Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/43989.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_synthetics_canary: Add `vpc_config.ipv6_allowed_for_dual_stack` argument
```
12 changes: 12 additions & 0 deletions internal/service/synthetics/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ func ResourceCanary() *schema.Resource {
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ipv6_allowed_for_dual_stack": {
Type: schema.TypeBool,
Optional: true,
},
names.AttrSecurityGroupIDs: {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Expand Down Expand Up @@ -746,6 +750,10 @@ func flattenCanaryVPCConfig(canaryVpcOutput *awstypes.VpcConfigOutput) []any {
names.AttrVPCID: aws.ToString(canaryVpcOutput.VpcId),
}

if canaryVpcOutput.Ipv6AllowedForDualStack != nil {
m["ipv6_allowed_for_dual_stack"] = aws.ToBool(canaryVpcOutput.Ipv6AllowedForDualStack)
}

return []any{m}
}

Expand All @@ -761,6 +769,10 @@ func expandCanaryVPCConfig(l []any) *awstypes.VpcConfigInput {
SecurityGroupIds: flex.ExpandStringValueSet(m[names.AttrSecurityGroupIDs].(*schema.Set)),
}

if v, ok := m["ipv6_allowed_for_dual_stack"]; ok {
codeConfig.Ipv6AllowedForDualStack = aws.Bool(v.(bool))
}

return codeConfig
}

Expand Down
137 changes: 133 additions & 4 deletions internal/service/synthetics/canary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestAccSyntheticsCanary_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
resource.TestCheckResourceAttrPair(resourceName, "runtime_version", runtimeVersionDataSourceName, "version_name"),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "0"),
resource.TestCheckResourceAttr(resourceName, "run_config.0.memory_in_mb", "1000"),
resource.TestCheckResourceAttr(resourceName, "run_config.0.memory_in_mb", "1500"),
resource.TestCheckResourceAttr(resourceName, "run_config.0.timeout_in_seconds", "840"),
resource.TestCheckResourceAttr(resourceName, "failure_retention_period", "31"),
resource.TestCheckResourceAttr(resourceName, "success_retention_period", "31"),
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestAccSyntheticsCanary_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
resource.TestCheckResourceAttrPair(resourceName, "runtime_version", runtimeVersionDataSourceName, "version_name"),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "0"),
resource.TestCheckResourceAttr(resourceName, "run_config.0.memory_in_mb", "1000"),
resource.TestCheckResourceAttr(resourceName, "run_config.0.memory_in_mb", "1500"),
resource.TestCheckResourceAttr(resourceName, "run_config.0.timeout_in_seconds", "840"),
resource.TestCheckResourceAttr(resourceName, "failure_retention_period", "31"),
resource.TestCheckResourceAttr(resourceName, "success_retention_period", "31"),
Expand Down Expand Up @@ -330,7 +330,7 @@ func TestAccSyntheticsCanary_s3(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
resource.TestCheckResourceAttrPair(resourceName, "runtime_version", runtimeVersionDataSourceName, "version_name"),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "0"),
resource.TestCheckResourceAttr(resourceName, "run_config.0.memory_in_mb", "1000"),
resource.TestCheckResourceAttr(resourceName, "run_config.0.memory_in_mb", "1500"),
resource.TestCheckResourceAttr(resourceName, "run_config.0.timeout_in_seconds", "840"),
resource.TestCheckResourceAttr(resourceName, "run_config.0.active_tracing", acctest.CtFalse),
resource.TestCheckResourceAttr(resourceName, "failure_retention_period", "31"),
Expand Down Expand Up @@ -372,7 +372,7 @@ func TestAccSyntheticsCanary_run(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckCanaryExists(ctx, resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
resource.TestCheckResourceAttr(resourceName, "run_config.0.memory_in_mb", "1000"),
resource.TestCheckResourceAttr(resourceName, "run_config.0.memory_in_mb", "1500"),
resource.TestCheckResourceAttr(resourceName, "run_config.0.timeout_in_seconds", "60"),
),
},
Expand Down Expand Up @@ -506,6 +506,7 @@ func TestAccSyntheticsCanary_vpc(t *testing.T) {
testAccCheckCanaryExists(ctx, resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.subnet_ids.#", "1"),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.security_group_ids.#", "1"),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.ipv6_allowed_for_dual_stack", acctest.CtFalse),
resource.TestCheckResourceAttrPair(resourceName, "vpc_config.0.vpc_id", "aws_vpc.test", names.AttrID),
),
},
Expand All @@ -521,6 +522,7 @@ func TestAccSyntheticsCanary_vpc(t *testing.T) {
testAccCheckCanaryExists(ctx, resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.subnet_ids.#", "2"),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.security_group_ids.#", "2"),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.ipv6_allowed_for_dual_stack", acctest.CtFalse),
resource.TestCheckResourceAttrPair(resourceName, "vpc_config.0.vpc_id", "aws_vpc.test", names.AttrID),
),
},
Expand All @@ -530,13 +532,80 @@ func TestAccSyntheticsCanary_vpc(t *testing.T) {
testAccCheckCanaryExists(ctx, resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.subnet_ids.#", "1"),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.security_group_ids.#", "1"),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.ipv6_allowed_for_dual_stack", acctest.CtFalse),
resource.TestCheckResourceAttrPair(resourceName, "vpc_config.0.vpc_id", "aws_vpc.test", names.AttrID),
),
},
},
})
}

func TestAccSyntheticsCanary_vpcIPv6AllowedForDualStack(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var conf awstypes.Canary
rName := fmt.Sprintf("tf-acc-test-%s", sdkacctest.RandString(8))
resourceName := "aws_synthetics_canary.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.SyntheticsServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckCanaryDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccCanaryConfig_vpcIPv6AllowedForDualStack(rName, true),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckCanaryExists(ctx, resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.subnet_ids.#", "2"),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.security_group_ids.#", "2"),
resource.TestCheckResourceAttrPair(resourceName, "vpc_config.0.vpc_id", "aws_vpc.test", names.AttrID),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.ipv6_allowed_for_dual_stack", acctest.CtTrue),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"zip_file", "start_canary", "delete_lambda"},
},
{
Config: testAccCanaryConfig_vpcIPv6AllowedForDualStack(rName, false),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckCanaryExists(ctx, resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.subnet_ids.#", "2"),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.security_group_ids.#", "2"),
resource.TestCheckResourceAttrPair(resourceName, "vpc_config.0.vpc_id", "aws_vpc.test", names.AttrID),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.ipv6_allowed_for_dual_stack", acctest.CtFalse),
),
},
{
Config: testAccCanaryConfig_vpcIPv6AllowedForDualStack(rName, true),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckCanaryExists(ctx, resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.subnet_ids.#", "2"),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.security_group_ids.#", "2"),
resource.TestCheckResourceAttrPair(resourceName, "vpc_config.0.vpc_id", "aws_vpc.test", names.AttrID),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.ipv6_allowed_for_dual_stack", acctest.CtTrue),
),
},
{
Config: testAccCanaryConfig_vpcIPv6AllowedForDualStackUpdated(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckCanaryExists(ctx, resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.subnet_ids.#", "2"),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.security_group_ids.#", "2"),
resource.TestCheckResourceAttrPair(resourceName, "vpc_config.0.vpc_id", "aws_vpc.test", names.AttrID),
resource.TestCheckResourceAttr(resourceName, "vpc_config.0.ipv6_allowed_for_dual_stack", acctest.CtFalse),
),
},
},
})
}

func TestAccSyntheticsCanary_tags(t *testing.T) {
ctx := acctest.Context(t)
var conf awstypes.Canary
Expand Down Expand Up @@ -1263,6 +1332,66 @@ resource "aws_synthetics_canary" "test" {
`, rName))
}

func testAccCanaryConfig_vpcIPv6AllowedForDualStack(rName string, ipv6 bool) string {
return acctest.ConfigCompose(
testAccCanaryConfig_base(rName),
acctest.ConfigVPCWithSubnetsIPv6(rName, 2),
testAccCanarySecurityGroupBaseConfig(rName, 2),
fmt.Sprintf(`
resource "aws_synthetics_canary" "test" {
name = %[1]q
artifact_s3_location = "s3://${aws_s3_bucket.test.bucket}/"
execution_role_arn = aws_iam_role.test.arn
handler = "exports.handler"
zip_file = "test-fixtures/lambdatest.zip"
runtime_version = data.aws_synthetics_runtime_version.test.version_name
delete_lambda = true

schedule {
expression = "rate(0 minute)"
}

vpc_config {
subnet_ids = aws_subnet.test[*].id
security_group_ids = aws_security_group.test[*].id

ipv6_allowed_for_dual_stack = %[2]t
}

depends_on = [aws_iam_role_policy_attachment.test]
}
`, rName, ipv6))
}

func testAccCanaryConfig_vpcIPv6AllowedForDualStackUpdated(rName string) string {
return acctest.ConfigCompose(
testAccCanaryConfig_base(rName),
acctest.ConfigVPCWithSubnetsIPv6(rName, 2),
testAccCanarySecurityGroupBaseConfig(rName, 2),
fmt.Sprintf(`
resource "aws_synthetics_canary" "test" {
name = %[1]q
artifact_s3_location = "s3://${aws_s3_bucket.test.bucket}/"
execution_role_arn = aws_iam_role.test.arn
handler = "exports.handler"
zip_file = "test-fixtures/lambdatest.zip"
runtime_version = data.aws_synthetics_runtime_version.test.version_name
delete_lambda = true

schedule {
expression = "rate(0 minute)"
}

vpc_config {
subnet_ids = aws_subnet.test[*].id
security_group_ids = aws_security_group.test[*].id
}

depends_on = [aws_iam_role_policy_attachment.test]
}
`, rName))
}

func testAccCanaryConfig_tags1(rName, tagKey1, tagValue1 string) string {
return acctest.ConfigCompose(
testAccCanaryConfig_base(rName),
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/synthetics_canary.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ If this canary tests an endpoint in a VPC, this structure contains information a

* `subnet_ids` - (Required) IDs of the subnets where this canary is to run.
* `security_group_ids` - (Required) IDs of the security groups for this canary.
* `ipv6_allowed_for_dual_stack` - (Optional) If `true`, allow outbound IPv6 traffic on VPC canaries that are connected to dual-stack subnets. The default is `false`.

## Attribute Reference

Expand Down
Loading