From 2ea9f83443fe7803089791515072525be6930b37 Mon Sep 17 00:00:00 2001 From: Elie Date: Wed, 25 May 2022 10:53:30 +0200 Subject: [PATCH] fix: crash in deep mode on aws_route We were missing to inject `destination_prefix_list_id` to the terraform provider when reading details of `aws_route` in deep mode. That cause an error on the provider side and abort the execution --- pkg/resource/aws/aws_route.go | 4 ++ pkg/resource/aws/aws_route_test.go | 28 +++++++++++++ .../.driftignore | 3 ++ .../.terraform.lock.hcl | 21 ++++++++++ .../terraform.tf | 39 +++++++++++++++++++ 5 files changed, 95 insertions(+) create mode 100644 pkg/resource/aws/testdata/acc/aws_route_with_prefix_list_id/.driftignore create mode 100644 pkg/resource/aws/testdata/acc/aws_route_with_prefix_list_id/.terraform.lock.hcl create mode 100644 pkg/resource/aws/testdata/acc/aws_route_with_prefix_list_id/terraform.tf diff --git a/pkg/resource/aws/aws_route.go b/pkg/resource/aws/aws_route.go index bf3a7279..2fa9210f 100644 --- a/pkg/resource/aws/aws_route.go +++ b/pkg/resource/aws/aws_route.go @@ -20,6 +20,9 @@ func initAwsRouteMetaData(resourceSchemaRepository resource.SchemaRepositoryInte if ipv6 := res.Attributes().GetString("destination_ipv6_cidr_block"); ipv6 != nil && *ipv6 != "" { attributes["destination_ipv6_cidr_block"] = *ipv6 } + if prefixes := res.Attributes().GetString("destination_prefix_list_id"); prefixes != nil && *prefixes != "" { + attributes["destination_prefix_list_id"] = *prefixes + } return attributes }) resourceSchemaRepository.SetNormalizeFunc(AwsRouteResourceType, func(res *resource.Resource) { @@ -30,6 +33,7 @@ func initAwsRouteMetaData(resourceSchemaRepository resource.SchemaRepositoryInte val.DeleteIfDefault("local_gateway_id") val.DeleteIfDefault("destination_cidr_block") val.DeleteIfDefault("destination_ipv6_cidr_block") + val.DeleteIfDefault("destination_prefix_list_id") val.DeleteIfDefault("egress_only_gateway_id") val.DeleteIfDefault("nat_gateway_id") val.DeleteIfDefault("instance_id") diff --git a/pkg/resource/aws/aws_route_test.go b/pkg/resource/aws/aws_route_test.go index 2661937d..1784a2ce 100644 --- a/pkg/resource/aws/aws_route_test.go +++ b/pkg/resource/aws/aws_route_test.go @@ -34,3 +34,31 @@ func TestAcc_Aws_Route(t *testing.T) { }, }) } + +// Splitted that case because it required a lot of unrelated resources +func TestAcc_Aws_Route_With_PrefixListId(t *testing.T) { + acceptance.Run(t, acceptance.AccTestCase{ + TerraformVersion: "0.15.5", + Paths: []string{"./testdata/acc/aws_route_with_prefix_list_id"}, + Args: []string{"scan", "--deep"}, + RetryDestroy: acceptance.RetryConfig{ + Attempts: 3, + Delay: 5 * time.Second, + }, + Checks: []acceptance.AccCheck{ + { + Env: map[string]string{ + "AWS_REGION": "us-east-1", + }, + ShouldRetry: acceptance.LinearBackoff(10 * time.Minute), + Check: func(result *test.ScanResult, stdout string, err error) { + if err != nil { + t.Fatal(err) + } + result.AssertInfrastructureIsInSync() + result.AssertManagedCount(1) + }, + }, + }, + }) +} diff --git a/pkg/resource/aws/testdata/acc/aws_route_with_prefix_list_id/.driftignore b/pkg/resource/aws/testdata/acc/aws_route_with_prefix_list_id/.driftignore new file mode 100644 index 00000000..faf680a9 --- /dev/null +++ b/pkg/resource/aws/testdata/acc/aws_route_with_prefix_list_id/.driftignore @@ -0,0 +1,3 @@ +* +!aws_route + diff --git a/pkg/resource/aws/testdata/acc/aws_route_with_prefix_list_id/.terraform.lock.hcl b/pkg/resource/aws/testdata/acc/aws_route_with_prefix_list_id/.terraform.lock.hcl new file mode 100644 index 00000000..1a5ac31c --- /dev/null +++ b/pkg/resource/aws/testdata/acc/aws_route_with_prefix_list_id/.terraform.lock.hcl @@ -0,0 +1,21 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "3.75.1" + constraints = "3.75.1" + hashes = [ + "h1:++H0a4igODgreQL3SJuRz71JZkC69rl41R8xLYM894o=", + "zh:11c2ee541ca1da923356c9225575ba294523d7b6af82d6171c912470ef0f90cd", + "zh:19fe975993664252b4a2ff1079546f2b186b01d1a025a94a4f15c37e023806c5", + "zh:442e7fc145b2debebe9279b283d07f5f736dc1776c2e5b1702728a6eb03789d0", + "zh:7a77991b204ae2c16ac29a32226135d5fdbda40c8dafa77c5adf5439a346be77", + "zh:89a257933181c15293c15a858fbfe7252129cc57cc2ec05b6c0b595d1bfe9d38", + "zh:b1813ea5b6b0fd88ea85b1b21b8e4119566d1bc34feca297b4fb39d0536893cb", + "zh:c519f3292ae431bd2381f88a95bd37c52f7a56d91feef88511e929344c180549", + "zh:d3dbe88b661c073c174f04f73adc2720372143bdfa12f4fe8f411332e64662cf", + "zh:e92a27e3c7295b031b5d62dd9428966c96e3157fc768b3d848a9ac60d1661c8e", + "zh:ecd664c0d664fcf2d8a89a01462cb00bcae37da200305aef2de1b8fe185c9cd8", + "zh:ed6ce1f9fa96aa28dd65842f852abed25f919d20b5cf53d26cec5b3f4d845725", + ] +} diff --git a/pkg/resource/aws/testdata/acc/aws_route_with_prefix_list_id/terraform.tf b/pkg/resource/aws/testdata/acc/aws_route_with_prefix_list_id/terraform.tf new file mode 100644 index 00000000..d80f5841 --- /dev/null +++ b/pkg/resource/aws/testdata/acc/aws_route_with_prefix_list_id/terraform.tf @@ -0,0 +1,39 @@ +provider "aws" { + region = "us-east-1" +} + +terraform { + required_providers { + aws = "3.75.1" + } +} + +resource "aws_vpc" "example" { + cidr_block = "10.1.0.0/16" +} + +resource "aws_ec2_managed_prefix_list" "example" { + name = "example" + address_family = "IPv4" + max_entries = 5 +} + +resource "aws_route_table" "example" { + vpc_id = aws_vpc.example.id +} + +resource "aws_subnet" "example" { + vpc_id = aws_vpc.example.id + cidr_block = "10.1.1.0/24" +} + +resource "aws_nat_gateway" "example" { + connectivity_type = "private" + subnet_id = aws_subnet.example.id +} + +resource "aws_route" "r" { + route_table_id = aws_route_table.example.id + nat_gateway_id = aws_nat_gateway.example.id + destination_prefix_list_id = aws_ec2_managed_prefix_list.example.id +}