From 60be67bc6496fc11069be765d63894d437614849 Mon Sep 17 00:00:00 2001 From: KF Date: Thu, 30 May 2024 18:56:45 +0800 Subject: [PATCH] UPD: replaced null_resource with http data source --- NetworkContentDelivery/Exercise3/README.md | 4 ++-- NetworkContentDelivery/Exercise3/main.tf | 14 ++++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/NetworkContentDelivery/Exercise3/README.md b/NetworkContentDelivery/Exercise3/README.md index 6a29baa..d577a9d 100644 --- a/NetworkContentDelivery/Exercise3/README.md +++ b/NetworkContentDelivery/Exercise3/README.md @@ -11,7 +11,7 @@ | Name | Version | |------|---------| | aws | 5.51.1 | -| null | 3.2.2 | +| http | 3.4.2 | ## Modules @@ -26,10 +26,10 @@ | Name | Type | |------|------| | [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_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 | +| [http_http.CloudflareIps](https://registry.terraform.io/providers/hashicorp/http/latest/docs/data-sources/http) | data source | ## Inputs diff --git a/NetworkContentDelivery/Exercise3/main.tf b/NetworkContentDelivery/Exercise3/main.tf index c6ecaa8..4921d48 100644 --- a/NetworkContentDelivery/Exercise3/main.tf +++ b/NetworkContentDelivery/Exercise3/main.tf @@ -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 { - CfIpJson = jsondecode(file("${path.module}/CfIps.json")) +data "http" "CloudflareIps" { + url = "https://api.cloudflare.com/client/v4/ips" + request_headers = { + Accept = "application/json" + } } resource "aws_ec2_managed_prefix_list" "pl1" { @@ -104,7 +102,7 @@ resource "aws_ec2_managed_prefix_list" "pl1" { address_family = "IPv4" max_entries = 20 dynamic "entry" { - for_each = local.CfIpJson.result.ipv4_cidrs + for_each = jsondecode(data.http.CloudflareIps.response_body)["result"]["ipv4_cidrs"] content { cidr = entry.value description = "Cloudflare IP"