From d48fccc6196733a4d186d626ec7a0be550799382 Mon Sep 17 00:00:00 2001 From: Rho <13165182+rhoboat@users.noreply.github.com> Date: Tue, 10 May 2022 08:08:57 -0700 Subject: [PATCH] Data source: use aws_subnets over aws_subnet_ids (#1113) For compatibility with AWS provider v4, switch to using the new resource. --- examples/terraform-asg-scp-example/main.tf | 9 ++++++--- examples/terraform-aws-ecs-example/main.tf | 9 ++++++--- examples/terraform-aws-rds-example/main.tf | 9 ++++++--- examples/terraform-redeploy-example/main.tf | 11 +++++++---- modules/aws/lambda_test.go | 3 ++- modules/terraform/apply_test.go | 2 +- 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/examples/terraform-asg-scp-example/main.tf b/examples/terraform-asg-scp-example/main.tf index b66799d33..20c74d9e8 100644 --- a/examples/terraform-asg-scp-example/main.tf +++ b/examples/terraform-asg-scp-example/main.tf @@ -32,7 +32,7 @@ resource "aws_launch_template" "sample_launch_template" { } resource "aws_autoscaling_group" "sample_asg" { - vpc_zone_identifier = data.aws_subnet_ids.default_subnets.ids + vpc_zone_identifier = data.aws_subnets.default_subnets.ids desired_capacity = 1 max_size = 1 @@ -102,7 +102,10 @@ data "aws_vpc" "default" { default = true } -data "aws_subnet_ids" "default_subnets" { - vpc_id = data.aws_vpc.default.id +data "aws_subnets" "default_subnets" { + filter { + name = "vpc-id" + values = [data.aws_vpc.default.id] + } } diff --git a/examples/terraform-aws-ecs-example/main.tf b/examples/terraform-aws-ecs-example/main.tf index 7efa821e8..61b09cc99 100644 --- a/examples/terraform-aws-ecs-example/main.tf +++ b/examples/terraform-aws-ecs-example/main.tf @@ -23,8 +23,11 @@ data "aws_vpc" "default" { default = true } -data "aws_subnet_ids" "all" { - vpc_id = data.aws_vpc.default.id +data "aws_subnets" "all" { + filter { + name = "vpc-id" + values = [data.aws_vpc.default.id] + } } # --------------------------------------------------------------------------------------------------------------------- @@ -47,7 +50,7 @@ resource "aws_ecs_service" "example" { launch_type = "FARGATE" network_configuration { - subnets = data.aws_subnet_ids.all.ids + subnets = data.aws_subnets.all.ids } } diff --git a/examples/terraform-aws-rds-example/main.tf b/examples/terraform-aws-rds-example/main.tf index 85696b2d0..7fab49131 100644 --- a/examples/terraform-aws-rds-example/main.tf +++ b/examples/terraform-aws-rds-example/main.tf @@ -25,8 +25,11 @@ data "aws_vpc" "default" { default = true } -data "aws_subnet_ids" "all" { - vpc_id = data.aws_vpc.default.id +data "aws_subnets" "all" { + filter { + name = "vpc-id" + values = [data.aws_vpc.default.id] + } } # --------------------------------------------------------------------------------------------------------------------- @@ -35,7 +38,7 @@ data "aws_subnet_ids" "all" { resource "aws_db_subnet_group" "example" { name = var.name - subnet_ids = data.aws_subnet_ids.all.ids + subnet_ids = data.aws_subnets.all.ids tags = { Name = var.name diff --git a/examples/terraform-redeploy-example/main.tf b/examples/terraform-redeploy-example/main.tf index 45f16b083..75c928568 100644 --- a/examples/terraform-redeploy-example/main.tf +++ b/examples/terraform-redeploy-example/main.tf @@ -35,7 +35,7 @@ resource "aws_autoscaling_group" "web_servers" { min_elb_capacity = 3 # Deploy into all the subnets (and therefore AZs) available - vpc_zone_identifier = data.aws_subnet_ids.default.ids + vpc_zone_identifier = data.aws_subnets.default.ids # Automatically register this ASG's Instances in the ALB and use the ALB's health check to determine when an Instance # needs to be replaced @@ -173,7 +173,7 @@ resource "aws_security_group_rule" "web_server_allow_all_outbound" { resource "aws_alb" "web_servers" { name = var.instance_name security_groups = [aws_security_group.alb.id] - subnets = data.aws_subnet_ids.default.ids + subnets = data.aws_subnets.default.ids # This is here because aws_alb_listener.http depends on this resource and sets create_before_destroy to true lifecycle { @@ -294,7 +294,10 @@ data "aws_vpc" "default" { default = true } -data "aws_subnet_ids" "default" { - vpc_id = data.aws_vpc.default.id +data "aws_subnets" "default" { + filter { + name = "vpc-id" + values = [data.aws_vpc.default.id] + } } diff --git a/modules/aws/lambda_test.go b/modules/aws/lambda_test.go index 053f2bda4..1f0e33038 100644 --- a/modules/aws/lambda_test.go +++ b/modules/aws/lambda_test.go @@ -1,8 +1,9 @@ package aws import ( - "github.com/stretchr/testify/require" "testing" + + "github.com/stretchr/testify/require" ) func TestFunctionError(t *testing.T) { diff --git a/modules/terraform/apply_test.go b/modules/terraform/apply_test.go index ce7f2f0ac..86e446c4e 100644 --- a/modules/terraform/apply_test.go +++ b/modules/terraform/apply_test.go @@ -182,7 +182,7 @@ func TestParallelism(t *testing.T) { Apply(t, options) end = time.Now() duration := end.Sub(start) - require.Greater(t, int64(duration.Seconds()), int64(25)) + require.GreaterOrEqual(t, int64(duration.Seconds()), int64(25)) } func TestTgApplyUseLockNoError(t *testing.T) { t.Parallel()