Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: aws_synthetics_canary generate correct timeout_in_seconds if not set in run_config #35177

Merged
merged 7 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 5 additions & 3 deletions internal/service/synthetics/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ func ResourceCanary() *schema.Resource {
},
"timeout_in_seconds": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
ValidateFunc: validation.IntBetween(3, 14*60),
Default: 840,
},
},
},
Expand Down Expand Up @@ -692,8 +692,10 @@ func expandCanaryRunConfig(l []interface{}) *synthetics.CanaryRunConfigInput {

m := l[0].(map[string]interface{})

codeConfig := &synthetics.CanaryRunConfigInput{
TimeoutInSeconds: aws.Int64(int64(m["timeout_in_seconds"].(int))),
codeConfig := &synthetics.CanaryRunConfigInput{}

if v, ok := m["timeout_in_seconds"].(int); ok && v > 3 {
codeConfig.TimeoutInSeconds = aws.Int64(int64(v))
}

if v, ok := m["memory_in_mb"].(int); ok && v > 0 {
Expand Down
71 changes: 71 additions & 0 deletions internal/service/synthetics/canary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,51 @@ func TestAccSyntheticsCanary_runtimeVersion(t *testing.T) {
})
}

func TestAccSyntheticsCanary_rate(t *testing.T) {
ctx := acctest.Context(t)
var conf1 synthetics.Canary
resourceName := "aws_synthetics_canary.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, synthetics.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckCanaryDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccCanaryConfig_rate(fmt.Sprintf("tf-acc-test-%s", sdkacctest.RandString(8)), "rate(1 minute)"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckCanaryExists(ctx, resourceName, &conf1),
resource.TestCheckResourceAttr(resourceName, "run_config.0.timeout_in_seconds", "60"),
resource.TestCheckResourceAttr(resourceName, "schedule.0.expression", "rate(1 minute)"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"zip_file", "start_canary", "delete_lambda", "run_config.0.environment_variables"},
},
{
Config: testAccCanaryConfig_rate(fmt.Sprintf("tf-acc-test-%s", sdkacctest.RandString(8)), "rate(2 minutes)"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckCanaryExists(ctx, resourceName, &conf1),
resource.TestCheckResourceAttr(resourceName, "run_config.0.timeout_in_seconds", "120"),
resource.TestCheckResourceAttr(resourceName, "schedule.0.expression", "rate(2 minutes)"),
),
},
{
Config: testAccCanaryConfig_rate(fmt.Sprintf("tf-acc-test-%s", sdkacctest.RandString(8)), "rate(1 hour)"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckCanaryExists(ctx, resourceName, &conf1),
resource.TestCheckResourceAttr(resourceName, "run_config.0.timeout_in_seconds", "840"),
resource.TestCheckResourceAttr(resourceName, "schedule.0.expression", "rate(1 hour)"),
),
},
},
})
}

func TestAccSyntheticsCanary_startCanary(t *testing.T) {
ctx := acctest.Context(t)
var conf1, conf2, conf3 synthetics.Canary
Expand Down Expand Up @@ -887,6 +932,32 @@ resource "aws_synthetics_canary" "test" {
`, rName))
}

func testAccCanaryConfig_rate(rName string, rate string) string {
return acctest.ConfigCompose(testAccCanaryConfig_base(rName), fmt.Sprintf(`
resource "aws_synthetics_canary" "test" {
# Must have bucket versioning enabled first
depends_on = [aws_s3_bucket_versioning.test, aws_iam_role.test, aws_iam_role_policy.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 = "syn-nodejs-puppeteer-3.9"
delete_lambda = true

run_config {
environment_variables = {
test1 = "value1"
}
}
schedule {
expression = %[2]q
}
}
`, rName, rate))
}

func testAccCanaryConfig_artifactEncryption(rName string) string {
return acctest.ConfigCompose(testAccCanaryConfig_base(rName), fmt.Sprintf(`
resource "aws_synthetics_canary" "test" {
Expand Down