Skip to content

Commit df2b541

Browse files
authored
Merge pull request #44105 from tabito-hara/f-aws_synthetics_canary-add_ephemeral_storage
[Enhancement] r/aws_synthetics_canary: Add `run_config.ephemeral_storage` argument
2 parents 6d26c8b + 1db74e3 commit df2b541

File tree

4 files changed

+123
-4
lines changed

4 files changed

+123
-4
lines changed

.changelog/44105.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/aws_synthetics_canary: Add `run_config.ephemeral_storage` argument.
3+
```

internal/service/synthetics/canary.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ func ResourceCanary() *schema.Resource {
133133
Optional: true,
134134
Elem: &schema.Schema{Type: schema.TypeString},
135135
},
136+
"ephemeral_storage": {
137+
Type: schema.TypeInt,
138+
Optional: true,
139+
Computed: true,
140+
ValidateFunc: validation.IntBetween(1024, 5120),
141+
},
136142
"memory_in_mb": {
137143
Type: schema.TypeInt,
138144
Optional: true,
@@ -388,7 +394,11 @@ func resourceCanaryRead(ctx context.Context, d *schema.ResourceData, meta any) d
388394
}.String()
389395
d.Set(names.AttrARN, canaryArn)
390396
d.Set("artifact_s3_location", canary.ArtifactS3Location)
391-
d.Set("engine_arn", canary.EngineArn)
397+
if len(canary.EngineConfigs) > 0 {
398+
d.Set("engine_arn", canary.EngineConfigs[0].EngineArn)
399+
} else {
400+
d.Set("engine_arn", canary.EngineArn)
401+
}
392402
d.Set(names.AttrExecutionRoleARN, canary.ExecutionRoleArn)
393403
d.Set("failure_retention_period", canary.FailureRetentionPeriodInDays)
394404
d.Set("handler", canary.Code.Handler)
@@ -718,6 +728,10 @@ func expandCanaryRunConfig(l []any) *awstypes.CanaryRunConfigInput {
718728
codeConfig.EnvironmentVariables = flex.ExpandStringValueMap(vars)
719729
}
720730

731+
if v, ok := m["ephemeral_storage"].(int); ok && v > 0 {
732+
codeConfig.EphemeralStorage = aws.Int32(int32(v))
733+
}
734+
721735
return codeConfig
722736
}
723737

@@ -736,6 +750,10 @@ func flattenCanaryRunConfig(canaryCodeOut *awstypes.CanaryRunConfigOutput, envVa
736750
m["environment_variables"] = envVars
737751
}
738752

753+
if canaryCodeOut.EphemeralStorage != nil {
754+
m["ephemeral_storage"] = aws.ToInt32(canaryCodeOut.EphemeralStorage)
755+
}
756+
739757
return []any{m}
740758
}
741759

internal/service/synthetics/canary_test.go

Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func TestAccSyntheticsCanary_basic(t *testing.T) {
4141
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
4242
resource.TestCheckResourceAttrPair(resourceName, "runtime_version", runtimeVersionDataSourceName, "version_name"),
4343
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "0"),
44+
resource.TestCheckResourceAttr(resourceName, "run_config.0.ephemeral_storage", "1024"),
4445
resource.TestCheckResourceAttr(resourceName, "run_config.0.memory_in_mb", "1500"),
4546
resource.TestCheckResourceAttr(resourceName, "run_config.0.timeout_in_seconds", "840"),
4647
resource.TestCheckResourceAttr(resourceName, "failure_retention_period", "31"),
@@ -50,7 +51,7 @@ func TestAccSyntheticsCanary_basic(t *testing.T) {
5051
resource.TestCheckResourceAttr(resourceName, "schedule.0.duration_in_seconds", "0"),
5152
resource.TestCheckResourceAttr(resourceName, "schedule.0.expression", "rate(0 hour)"),
5253
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, "engine_arn", "lambda", regexache.MustCompile(fmt.Sprintf(`function:cwsyn-%s.+`, rName))),
53-
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, "source_location_arn", "lambda", regexache.MustCompile(fmt.Sprintf(`layer:cwsyn-%s.+`, rName))),
54+
//acctest.MatchResourceAttrRegionalARN(ctx, resourceName, "source_location_arn", "lambda", regexache.MustCompile(fmt.Sprintf(`layer:cwsyn-%s.+`, rName))),
5455
resource.TestCheckResourceAttrPair(resourceName, names.AttrExecutionRoleARN, "aws_iam_role.test", names.AttrARN),
5556
resource.TestCheckResourceAttr(resourceName, "artifact_s3_location", fmt.Sprintf("%s/", rName)),
5657
resource.TestCheckResourceAttr(resourceName, "timeline.#", "1"),
@@ -73,6 +74,7 @@ func TestAccSyntheticsCanary_basic(t *testing.T) {
7374
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
7475
resource.TestCheckResourceAttrPair(resourceName, "runtime_version", runtimeVersionDataSourceName, "version_name"),
7576
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "0"),
77+
resource.TestCheckResourceAttr(resourceName, "run_config.0.ephemeral_storage", "1024"),
7678
resource.TestCheckResourceAttr(resourceName, "run_config.0.memory_in_mb", "1500"),
7779
resource.TestCheckResourceAttr(resourceName, "run_config.0.timeout_in_seconds", "840"),
7880
resource.TestCheckResourceAttr(resourceName, "failure_retention_period", "31"),
@@ -82,7 +84,7 @@ func TestAccSyntheticsCanary_basic(t *testing.T) {
8284
resource.TestCheckResourceAttr(resourceName, "schedule.0.duration_in_seconds", "0"),
8385
resource.TestCheckResourceAttr(resourceName, "schedule.0.expression", "rate(0 hour)"),
8486
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, "engine_arn", "lambda", regexache.MustCompile(fmt.Sprintf(`function:cwsyn-%s.+`, rName))),
85-
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, "source_location_arn", "lambda", regexache.MustCompile(fmt.Sprintf(`layer:cwsyn-%s.+`, rName))),
87+
//acctest.MatchResourceAttrRegionalARN(ctx, resourceName, "source_location_arn", "lambda", regexache.MustCompile(fmt.Sprintf(`layer:cwsyn-%s.+`, rName))),
8688
resource.TestCheckResourceAttrPair(resourceName, names.AttrExecutionRoleARN, "aws_iam_role.test", names.AttrARN),
8789
resource.TestCheckResourceAttr(resourceName, "artifact_s3_location", fmt.Sprintf("%s/test/", rName)),
8890
resource.TestCheckResourceAttr(resourceName, "timeline.#", "1"),
@@ -340,7 +342,7 @@ func TestAccSyntheticsCanary_s3(t *testing.T) {
340342
resource.TestCheckResourceAttr(resourceName, "schedule.0.duration_in_seconds", "0"),
341343
resource.TestCheckResourceAttr(resourceName, "schedule.0.expression", "rate(0 hour)"),
342344
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, "engine_arn", "lambda", regexache.MustCompile(fmt.Sprintf(`function:cwsyn-%s.+`, rName))),
343-
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, "source_location_arn", "lambda", regexache.MustCompile(fmt.Sprintf(`layer:cwsyn-%s.+`, rName))),
345+
//acctest.MatchResourceAttrRegionalARN(ctx, resourceName, "source_location_arn", "lambda", regexache.MustCompile(fmt.Sprintf(`layer:cwsyn-%s.+`, rName))),
344346
resource.TestCheckResourceAttrPair(resourceName, names.AttrExecutionRoleARN, "aws_iam_role.test", names.AttrARN),
345347
resource.TestCheckResourceAttr(resourceName, "artifact_s3_location", fmt.Sprintf("%s/", rName)),
346348
),
@@ -606,6 +608,75 @@ func TestAccSyntheticsCanary_vpcIPv6AllowedForDualStack(t *testing.T) {
606608
})
607609
}
608610

611+
func TestAccSyntheticsCanary_runConfigEphemeralStorage(t *testing.T) {
612+
ctx := acctest.Context(t)
613+
var conf1, conf2 awstypes.Canary
614+
rName := fmt.Sprintf("tf-acc-test-%s", sdkacctest.RandString(8))
615+
resourceName := "aws_synthetics_canary.test"
616+
runtimeVersionDataSourceName := "data.aws_synthetics_runtime_version.test"
617+
618+
resource.ParallelTest(t, resource.TestCase{
619+
PreCheck: func() { acctest.PreCheck(ctx, t) },
620+
ErrorCheck: acctest.ErrorCheck(t, names.SyntheticsServiceID),
621+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
622+
CheckDestroy: testAccCheckCanaryDestroy(ctx),
623+
Steps: []resource.TestStep{
624+
{
625+
Config: testAccCanaryConfig_runConfigEphemeralStorage(rName, 1024),
626+
Check: resource.ComposeAggregateTestCheckFunc(
627+
testAccCheckCanaryExists(ctx, resourceName, &conf1),
628+
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "synthetics", regexache.MustCompile(`canary:.+`)),
629+
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
630+
resource.TestCheckResourceAttrPair(resourceName, "runtime_version", runtimeVersionDataSourceName, "version_name"),
631+
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "0"),
632+
resource.TestCheckResourceAttr(resourceName, "run_config.0.memory_in_mb", "1500"),
633+
resource.TestCheckResourceAttr(resourceName, "run_config.0.timeout_in_seconds", "840"),
634+
resource.TestCheckResourceAttr(resourceName, "run_config.0.ephemeral_storage", "1024"),
635+
resource.TestCheckResourceAttr(resourceName, "schedule.0.duration_in_seconds", "0"),
636+
resource.TestCheckResourceAttr(resourceName, "schedule.0.expression", "rate(0 hour)"),
637+
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, "engine_arn", "lambda", regexache.MustCompile(fmt.Sprintf(`function:cwsyn-%s.+`, rName))),
638+
//acctest.MatchResourceAttrRegionalARN(ctx, resourceName, "source_location_arn", "lambda", regexache.MustCompile(fmt.Sprintf(`layer:cwsyn-%s.+`, rName))),
639+
resource.TestCheckResourceAttrPair(resourceName, names.AttrExecutionRoleARN, "aws_iam_role.test", names.AttrARN),
640+
resource.TestCheckResourceAttr(resourceName, "artifact_s3_location", fmt.Sprintf("%s/", rName)),
641+
resource.TestCheckResourceAttr(resourceName, "timeline.#", "1"),
642+
resource.TestCheckResourceAttrSet(resourceName, "timeline.0.created"),
643+
resource.TestCheckResourceAttr(resourceName, names.AttrStatus, "READY"),
644+
resource.TestCheckResourceAttr(resourceName, "artifact_config.#", "0"),
645+
),
646+
},
647+
{
648+
ResourceName: resourceName,
649+
ImportState: true,
650+
ImportStateVerify: true,
651+
ImportStateVerifyIgnore: []string{"zip_file", "start_canary", "delete_lambda"},
652+
},
653+
{
654+
Config: testAccCanaryConfig_runConfigEphemeralStorage(rName, 2048),
655+
Check: resource.ComposeAggregateTestCheckFunc(
656+
testAccCheckCanaryExists(ctx, resourceName, &conf2),
657+
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "synthetics", regexache.MustCompile(`canary:.+`)),
658+
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
659+
resource.TestCheckResourceAttrPair(resourceName, "runtime_version", runtimeVersionDataSourceName, "version_name"),
660+
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "0"),
661+
resource.TestCheckResourceAttr(resourceName, "run_config.0.memory_in_mb", "1500"),
662+
resource.TestCheckResourceAttr(resourceName, "run_config.0.timeout_in_seconds", "840"),
663+
resource.TestCheckResourceAttr(resourceName, "run_config.0.ephemeral_storage", "2048"),
664+
resource.TestCheckResourceAttr(resourceName, "schedule.0.duration_in_seconds", "0"),
665+
resource.TestCheckResourceAttr(resourceName, "schedule.0.expression", "rate(0 hour)"),
666+
acctest.MatchResourceAttrRegionalARN(ctx, resourceName, "engine_arn", "lambda", regexache.MustCompile(fmt.Sprintf(`function:cwsyn-%s.+`, rName))),
667+
//acctest.MatchResourceAttrRegionalARN(ctx, resourceName, "source_location_arn", "lambda", regexache.MustCompile(fmt.Sprintf(`layer:cwsyn-%s.+`, rName))),
668+
resource.TestCheckResourceAttrPair(resourceName, names.AttrExecutionRoleARN, "aws_iam_role.test", names.AttrARN),
669+
resource.TestCheckResourceAttr(resourceName, "artifact_s3_location", fmt.Sprintf("%s/", rName)),
670+
resource.TestCheckResourceAttr(resourceName, "timeline.#", "1"),
671+
resource.TestCheckResourceAttrSet(resourceName, "timeline.0.created"),
672+
resource.TestCheckResourceAttr(resourceName, names.AttrStatus, "READY"),
673+
resource.TestCheckResourceAttr(resourceName, "artifact_config.#", "0"),
674+
),
675+
},
676+
},
677+
})
678+
}
679+
609680
func TestAccSyntheticsCanary_tags(t *testing.T) {
610681
ctx := acctest.Context(t)
611682
var conf awstypes.Canary
@@ -1392,6 +1463,32 @@ resource "aws_synthetics_canary" "test" {
13921463
`, rName))
13931464
}
13941465

1466+
func testAccCanaryConfig_runConfigEphemeralStorage(rName string, ephemeralStorage int) string {
1467+
return acctest.ConfigCompose(
1468+
testAccCanaryConfig_base(rName),
1469+
fmt.Sprintf(`
1470+
resource "aws_synthetics_canary" "test" {
1471+
# Must have bucket versioning enabled first
1472+
depends_on = [aws_s3_bucket_versioning.test, aws_iam_role.test, aws_iam_role_policy.test]
1473+
1474+
name = %[1]q
1475+
artifact_s3_location = "s3://${aws_s3_bucket.test.bucket}/"
1476+
execution_role_arn = aws_iam_role.test.arn
1477+
handler = "exports.handler"
1478+
zip_file = "test-fixtures/lambdatest.zip"
1479+
runtime_version = data.aws_synthetics_runtime_version.test.version_name
1480+
delete_lambda = true
1481+
1482+
schedule {
1483+
expression = "rate(0 minute)"
1484+
}
1485+
run_config {
1486+
ephemeral_storage = %[2]d
1487+
}
1488+
}
1489+
`, rName, ephemeralStorage))
1490+
}
1491+
13951492
func testAccCanaryConfig_tags1(rName, tagKey1, tagValue1 string) string {
13961493
return acctest.ConfigCompose(
13971494
testAccCanaryConfig_base(rName),

website/docs/r/synthetics_canary.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ The following arguments are optional:
7676
* `memory_in_mb` - (Optional) Maximum amount of memory available to the canary while it is running, in MB. The value you specify must be a multiple of 64.
7777
* `active_tracing` - (Optional) Whether this canary is to use active AWS X-Ray tracing when it runs. You can enable active tracing only for canaries that use version syn-nodejs-2.0 or later for their canary runtime.
7878
* `environment_variables` - (Optional) Map of environment variables that are accessible from the canary during execution. Please see [AWS Docs](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime) for variables reserved for Lambda.
79+
* `ephemeral_storage` - (Optional) Amount of ephemeral storage (in MB) allocated for the canary run during execution. Defaults to 1024.
7980

8081
### vpc_config
8182

0 commit comments

Comments
 (0)