forked from hashicorp/python-tfe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathip_ranges.py
More file actions
59 lines (45 loc) · 1.56 KB
/
Copy pathip_ranges.py
File metadata and controls
59 lines (45 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Copyright IBM Corp. 2025, 2026
# SPDX-License-Identifier: MPL-2.0
from __future__ import annotations
import argparse
import os
from datetime import datetime
from pytfe import TFEClient, TFEConfig
def _print_header(title: str):
print("\n" + "=" * 80)
print(title)
print("=" * 80)
def main():
parser = argparse.ArgumentParser(description="IP ranges demo for python-tfe SDK")
parser.add_argument(
"--address", default=os.getenv("TFE_ADDRESS", "https://app.terraform.io")
)
parser.add_argument("--token", default=os.getenv("TFE_TOKEN", ""))
parser.add_argument(
"--modified-since",
help="ISO-8601 timestamp; only fetch ranges changed since then "
"(e.g. 2020-05-26T15:10:05).",
)
args = parser.parse_args()
# The IP ranges endpoint does not require authentication.
cfg = TFEConfig(address=args.address, token=args.token)
client = TFEClient(cfg)
modified_since = (
datetime.fromisoformat(args.modified_since) if args.modified_since else None
)
_print_header("Reading HCP Terraform / TFE IP ranges")
ranges = client.ip_ranges.read(modified_since=modified_since)
if ranges is None:
print("Not modified since the supplied date.")
return
for name, cidrs in (
("API", ranges.api),
("Notifications", ranges.notifications),
("Sentinel", ranges.sentinel),
("VCS", ranges.vcs),
):
print(f"\n{name} ({len(cidrs)} ranges):")
for cidr in cidrs:
print(f" - {cidr}")
if __name__ == "__main__":
main()