Skip to content

Commit 4c4a333

Browse files
authored
Merge pull request #1502 from snyk/fix/aws_route_with_prefix_broken
fix: crash in deep mode on aws_route
2 parents 898b618 + 2ea9f83 commit 4c4a333

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed

pkg/resource/aws/aws_route.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ func initAwsRouteMetaData(resourceSchemaRepository resource.SchemaRepositoryInte
2020
if ipv6 := res.Attributes().GetString("destination_ipv6_cidr_block"); ipv6 != nil && *ipv6 != "" {
2121
attributes["destination_ipv6_cidr_block"] = *ipv6
2222
}
23+
if prefixes := res.Attributes().GetString("destination_prefix_list_id"); prefixes != nil && *prefixes != "" {
24+
attributes["destination_prefix_list_id"] = *prefixes
25+
}
2326
return attributes
2427
})
2528
resourceSchemaRepository.SetNormalizeFunc(AwsRouteResourceType, func(res *resource.Resource) {
@@ -30,6 +33,7 @@ func initAwsRouteMetaData(resourceSchemaRepository resource.SchemaRepositoryInte
3033
val.DeleteIfDefault("local_gateway_id")
3134
val.DeleteIfDefault("destination_cidr_block")
3235
val.DeleteIfDefault("destination_ipv6_cidr_block")
36+
val.DeleteIfDefault("destination_prefix_list_id")
3337
val.DeleteIfDefault("egress_only_gateway_id")
3438
val.DeleteIfDefault("nat_gateway_id")
3539
val.DeleteIfDefault("instance_id")

pkg/resource/aws/aws_route_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,31 @@ func TestAcc_Aws_Route(t *testing.T) {
3434
},
3535
})
3636
}
37+
38+
// Splitted that case because it required a lot of unrelated resources
39+
func TestAcc_Aws_Route_With_PrefixListId(t *testing.T) {
40+
acceptance.Run(t, acceptance.AccTestCase{
41+
TerraformVersion: "0.15.5",
42+
Paths: []string{"./testdata/acc/aws_route_with_prefix_list_id"},
43+
Args: []string{"scan", "--deep"},
44+
RetryDestroy: acceptance.RetryConfig{
45+
Attempts: 3,
46+
Delay: 5 * time.Second,
47+
},
48+
Checks: []acceptance.AccCheck{
49+
{
50+
Env: map[string]string{
51+
"AWS_REGION": "us-east-1",
52+
},
53+
ShouldRetry: acceptance.LinearBackoff(10 * time.Minute),
54+
Check: func(result *test.ScanResult, stdout string, err error) {
55+
if err != nil {
56+
t.Fatal(err)
57+
}
58+
result.AssertInfrastructureIsInSync()
59+
result.AssertManagedCount(1)
60+
},
61+
},
62+
},
63+
})
64+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*
2+
!aws_route
3+

pkg/resource/aws/testdata/acc/aws_route_with_prefix_list_id/.terraform.lock.hcl

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
provider "aws" {
2+
region = "us-east-1"
3+
}
4+
5+
terraform {
6+
required_providers {
7+
aws = "3.75.1"
8+
}
9+
}
10+
11+
resource "aws_vpc" "example" {
12+
cidr_block = "10.1.0.0/16"
13+
}
14+
15+
resource "aws_ec2_managed_prefix_list" "example" {
16+
name = "example"
17+
address_family = "IPv4"
18+
max_entries = 5
19+
}
20+
21+
resource "aws_route_table" "example" {
22+
vpc_id = aws_vpc.example.id
23+
}
24+
25+
resource "aws_subnet" "example" {
26+
vpc_id = aws_vpc.example.id
27+
cidr_block = "10.1.1.0/24"
28+
}
29+
30+
resource "aws_nat_gateway" "example" {
31+
connectivity_type = "private"
32+
subnet_id = aws_subnet.example.id
33+
}
34+
35+
resource "aws_route" "r" {
36+
route_table_id = aws_route_table.example.id
37+
nat_gateway_id = aws_nat_gateway.example.id
38+
destination_prefix_list_id = aws_ec2_managed_prefix_list.example.id
39+
}

0 commit comments

Comments
 (0)