Compare commits

...

2 Commits

Author SHA1 Message Date
KF
5f11260c53
DEL: CfIps.json 2024-05-30 18:57:00 +08:00
KF
60be67bc64
UPD: replaced null_resource with http data source 2024-05-30 18:56:45 +08:00
3 changed files with 8 additions and 11 deletions

View File

@ -1 +0,0 @@
{"result":{"ipv4_cidrs":["173.245.48.0/20","103.21.244.0/22","103.22.200.0/22","103.31.4.0/22","141.101.64.0/18","108.162.192.0/18","190.93.240.0/20","188.114.96.0/20","197.234.240.0/22","198.41.128.0/17","162.158.0.0/15","104.16.0.0/13","104.24.0.0/14","172.64.0.0/13","131.0.72.0/22"],"ipv6_cidrs":["2400:cb00::/32","2606:4700::/32","2803:f800::/32","2405:b500::/32","2405:8100::/32","2a06:98c0::/29","2c0f:f248::/32"],"etag":"38f79d050aa027e3be3865e495dcc9bc"},"success":true,"errors":[],"messages":[]}

View File

@ -11,7 +11,7 @@
| Name | Version | | Name | Version |
|------|---------| |------|---------|
| aws | 5.51.1 | | aws | 5.51.1 |
| null | 3.2.2 | | http | 3.4.2 |
## Modules ## Modules
@ -26,10 +26,10 @@
| Name | Type | | Name | Type |
|------|------| |------|------|
| [aws_ec2_managed_prefix_list.pl1](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_managed_prefix_list) | resource | | [aws_ec2_managed_prefix_list.pl1](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_managed_prefix_list) | resource |
| [null_resource.CloudflareIps](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source | | [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
| [aws_iam_policy_document.dynamodb_endpoint_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | | [aws_iam_policy_document.dynamodb_endpoint_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.s3_endpoint_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | | [aws_iam_policy_document.s3_endpoint_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [http_http.CloudflareIps](https://registry.terraform.io/providers/hashicorp/http/latest/docs/data-sources/http) | data source |
## Inputs ## Inputs

View File

@ -89,14 +89,12 @@ data "aws_iam_policy_document" "dynamodb_endpoint_policy" {
} }
} }
resource "null_resource" "CloudflareIps" {
provisioner "local-exec" {
command = "wget -qO CfIps.json https://api.cloudflare.com/client/v4/ips"
}
}
locals { data "http" "CloudflareIps" {
CfIpJson = jsondecode(file("${path.module}/CfIps.json")) url = "https://api.cloudflare.com/client/v4/ips"
request_headers = {
Accept = "application/json"
}
} }
resource "aws_ec2_managed_prefix_list" "pl1" { resource "aws_ec2_managed_prefix_list" "pl1" {
@ -104,7 +102,7 @@ resource "aws_ec2_managed_prefix_list" "pl1" {
address_family = "IPv4" address_family = "IPv4"
max_entries = 20 max_entries = 20
dynamic "entry" { dynamic "entry" {
for_each = local.CfIpJson.result.ipv4_cidrs for_each = jsondecode(data.http.CloudflareIps.response_body)["result"]["ipv4_cidrs"]
content { content {
cidr = entry.value cidr = entry.value
description = "Cloudflare IP" description = "Cloudflare IP"