Skip to content

Commit

Permalink
Merge pull request #35177 from SebastianSlaby/canary-timeout
Browse files Browse the repository at this point in the history
Fix: aws_synthetics_canary generate correct timeout_in_seconds if not set in run_config
  • Loading branch information
jar-b authored Sep 5, 2024
2 parents 5ec77de + 807ecc2 commit 362643d
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .changelog/35177.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_synthetics_canary: Remove `run_config.timeout_in_seconds` default value to allow creation of resources with a frequency less than 14 minutes
```
8 changes: 5 additions & 3 deletions internal/service/synthetics/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,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 @@ -698,8 +698,10 @@ func expandCanaryRunConfig(l []interface{}) *awstypes.CanaryRunConfigInput {

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

codeConfig := &awstypes.CanaryRunConfigInput{
TimeoutInSeconds: aws.Int32(int32(m["timeout_in_seconds"].(int))),
codeConfig := &awstypes.CanaryRunConfigInput{}

if v, ok := m["timeout_in_seconds"].(int); ok && v > 0 {
codeConfig.TimeoutInSeconds = aws.Int32(int32(v))
}

if v, ok := m["memory_in_mb"].(int); ok && v > 0 {
Expand Down
119 changes: 95 additions & 24 deletions internal/service/synthetics/canary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestAccSyntheticsCanary_basic(t *testing.T) {
testAccCheckCanaryExists(ctx, resourceName, &conf1),
acctest.MatchResourceAttrRegionalARN(resourceName, names.AttrARN, "synthetics", regexache.MustCompile(`canary:.+`)),
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
resource.TestCheckResourceAttr(resourceName, "runtime_version", "syn-nodejs-puppeteer-6.1"),
resource.TestCheckResourceAttr(resourceName, "runtime_version", "syn-nodejs-puppeteer-9.0"),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct0),
resource.TestCheckResourceAttr(resourceName, "run_config.0.memory_in_mb", "1000"),
resource.TestCheckResourceAttr(resourceName, "run_config.0.timeout_in_seconds", "840"),
Expand Down Expand Up @@ -70,7 +70,7 @@ func TestAccSyntheticsCanary_basic(t *testing.T) {
testAccCheckCanaryExists(ctx, resourceName, &conf2),
acctest.MatchResourceAttrRegionalARN(resourceName, names.AttrARN, "synthetics", regexache.MustCompile(`canary:.+`)),
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
resource.TestCheckResourceAttr(resourceName, "runtime_version", "syn-nodejs-puppeteer-6.1"),
resource.TestCheckResourceAttr(resourceName, "runtime_version", "syn-nodejs-puppeteer-9.0"),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct0),
resource.TestCheckResourceAttr(resourceName, "run_config.0.memory_in_mb", "1000"),
resource.TestCheckResourceAttr(resourceName, "run_config.0.timeout_in_seconds", "840"),
Expand Down Expand Up @@ -149,10 +149,10 @@ func TestAccSyntheticsCanary_runtimeVersion(t *testing.T) {
CheckDestroy: testAccCheckCanaryDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccCanaryConfig_runtimeVersion(rName, "syn-nodejs-puppeteer-6.0"),
Config: testAccCanaryConfig_runtimeVersion(rName, "syn-nodejs-puppeteer-8.0"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckCanaryExists(ctx, resourceName, &conf1),
resource.TestCheckResourceAttr(resourceName, "runtime_version", "syn-nodejs-puppeteer-6.0"),
resource.TestCheckResourceAttr(resourceName, "runtime_version", "syn-nodejs-puppeteer-8.0"),
),
},
{
Expand All @@ -162,10 +162,55 @@ func TestAccSyntheticsCanary_runtimeVersion(t *testing.T) {
ImportStateVerifyIgnore: []string{"zip_file", "start_canary", "delete_lambda"},
},
{
Config: testAccCanaryConfig_runtimeVersion(rName, "syn-nodejs-puppeteer-6.1"),
Config: testAccCanaryConfig_runtimeVersion(rName, "syn-nodejs-puppeteer-9.0"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckCanaryExists(ctx, resourceName, &conf1),
resource.TestCheckResourceAttr(resourceName, "runtime_version", "syn-nodejs-puppeteer-6.1"),
resource.TestCheckResourceAttr(resourceName, "runtime_version", "syn-nodejs-puppeteer-9.0"),
),
},
},
})
}

func TestAccSyntheticsCanary_rate(t *testing.T) {
ctx := acctest.Context(t)
var conf1 awstypes.Canary
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_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)"),
),
},
},
Expand Down Expand Up @@ -281,7 +326,7 @@ func TestAccSyntheticsCanary_s3(t *testing.T) {
testAccCheckCanaryExists(ctx, resourceName, &conf),
acctest.MatchResourceAttrRegionalARN(resourceName, names.AttrARN, "synthetics", regexache.MustCompile(`canary:.+`)),
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
resource.TestCheckResourceAttr(resourceName, "runtime_version", "syn-nodejs-puppeteer-6.1"),
resource.TestCheckResourceAttr(resourceName, "runtime_version", "syn-nodejs-puppeteer-9.0"),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct0),
resource.TestCheckResourceAttr(resourceName, "run_config.0.memory_in_mb", "1000"),
resource.TestCheckResourceAttr(resourceName, "run_config.0.timeout_in_seconds", "840"),
Expand Down Expand Up @@ -748,7 +793,7 @@ resource "aws_synthetics_canary" "test" {
execution_role_arn = aws_iam_role.test.arn
handler = "exports.handler"
zip_file = "test-fixtures/lambdatest.zip"
runtime_version = "syn-nodejs-puppeteer-6.1"
runtime_version = "syn-nodejs-puppeteer-9.0"
delete_lambda = true
schedule {
Expand All @@ -772,7 +817,7 @@ resource "aws_synthetics_canary" "test" {
execution_role_arn = aws_iam_role.test.arn
handler = "exports.handler"
zip_file = "test-fixtures/lambdatest.zip"
runtime_version = "syn-nodejs-puppeteer-6.1"
runtime_version = "syn-nodejs-puppeteer-9.0"
delete_lambda = true
schedule {
Expand All @@ -797,7 +842,7 @@ resource "aws_synthetics_canary" "test" {
execution_role_arn = aws_iam_role.test.arn
handler = "exports.handler"
zip_file = "test-fixtures/lambdatest.zip"
runtime_version = "syn-nodejs-puppeteer-6.1"
runtime_version = "syn-nodejs-puppeteer-9.0"
delete_lambda = true
schedule {
Expand All @@ -822,7 +867,7 @@ resource "aws_synthetics_canary" "test" {
execution_role_arn = aws_iam_role.test.arn
handler = "exports.handler"
zip_file = "test-fixtures/lambdatest.zip"
runtime_version = "syn-nodejs-puppeteer-6.1"
runtime_version = "syn-nodejs-puppeteer-9.0"
delete_lambda = true
schedule {
Expand All @@ -848,7 +893,7 @@ resource "aws_synthetics_canary" "test" {
execution_role_arn = aws_iam_role.test.arn
handler = "exports.handler"
zip_file = "test-fixtures/lambdatest.zip"
runtime_version = "syn-nodejs-puppeteer-6.1"
runtime_version = "syn-nodejs-puppeteer-9.0"
delete_lambda = true
schedule {
Expand Down Expand Up @@ -878,7 +923,7 @@ resource "aws_synthetics_canary" "test" {
execution_role_arn = aws_iam_role.test.arn
handler = "exports.handler"
zip_file = "test-fixtures/lambdatest.zip"
runtime_version = "syn-nodejs-puppeteer-6.1"
runtime_version = "syn-nodejs-puppeteer-9.0"
delete_lambda = true
schedule {
Expand All @@ -888,6 +933,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-9.0"
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 All @@ -896,7 +967,7 @@ resource "aws_synthetics_canary" "test" {
execution_role_arn = aws_iam_role.test.arn
handler = "exports.handler"
zip_file = "test-fixtures/lambdatest.zip"
runtime_version = "syn-nodejs-puppeteer-6.1"
runtime_version = "syn-nodejs-puppeteer-9.0"
delete_lambda = true
artifact_config {
Expand Down Expand Up @@ -927,7 +998,7 @@ resource "aws_synthetics_canary" "test" {
execution_role_arn = aws_iam_role.test.arn
handler = "exports.handler"
zip_file = "test-fixtures/lambdatest.zip"
runtime_version = "syn-nodejs-puppeteer-6.1"
runtime_version = "syn-nodejs-puppeteer-9.0"
delete_lambda = true
artifact_config {
Expand Down Expand Up @@ -974,7 +1045,7 @@ resource "aws_synthetics_canary" "test" {
execution_role_arn = aws_iam_role.test.arn
handler = "exports.handler"
zip_file = "test-fixtures/lambdatest_modified.zip"
runtime_version = "syn-nodejs-puppeteer-6.1"
runtime_version = "syn-nodejs-puppeteer-9.0"
delete_lambda = true
schedule {
Expand All @@ -995,7 +1066,7 @@ resource "aws_synthetics_canary" "test" {
handler = "exports.handler"
zip_file = "test-fixtures/lambdatest.zip"
start_canary = %[2]t
runtime_version = "syn-nodejs-puppeteer-6.1"
runtime_version = "syn-nodejs-puppeteer-9.0"
delete_lambda = true
schedule {
Expand All @@ -1016,7 +1087,7 @@ resource "aws_synthetics_canary" "test" {
handler = "exports.handler"
zip_file = "test-fixtures/lambdatest_modified.zip"
start_canary = %[2]t
runtime_version = "syn-nodejs-puppeteer-6.1"
runtime_version = "syn-nodejs-puppeteer-9.0"
delete_lambda = true
schedule {
Expand All @@ -1038,7 +1109,7 @@ resource "aws_synthetics_canary" "test" {
s3_bucket = aws_s3_object.test.bucket
s3_key = aws_s3_object.test.key
s3_version = aws_s3_object.test.version_id
runtime_version = "syn-nodejs-puppeteer-6.1"
runtime_version = "syn-nodejs-puppeteer-9.0"
delete_lambda = true
schedule {
Expand Down Expand Up @@ -1091,7 +1162,7 @@ resource "aws_synthetics_canary" "test" {
execution_role_arn = aws_iam_role.test.arn
handler = "exports.handler"
zip_file = "test-fixtures/lambdatest.zip"
runtime_version = "syn-nodejs-puppeteer-6.1"
runtime_version = "syn-nodejs-puppeteer-9.0"
delete_lambda = true
schedule {
Expand Down Expand Up @@ -1120,7 +1191,7 @@ resource "aws_synthetics_canary" "test" {
execution_role_arn = aws_iam_role.test.arn
handler = "exports.handler"
zip_file = "test-fixtures/lambdatest.zip"
runtime_version = "syn-nodejs-puppeteer-6.1"
runtime_version = "syn-nodejs-puppeteer-9.0"
delete_lambda = true
schedule {
Expand Down Expand Up @@ -1149,7 +1220,7 @@ resource "aws_synthetics_canary" "test" {
execution_role_arn = aws_iam_role.test.arn
handler = "exports.handler"
zip_file = "test-fixtures/lambdatest.zip"
runtime_version = "syn-nodejs-puppeteer-6.1"
runtime_version = "syn-nodejs-puppeteer-9.0"
delete_lambda = true
schedule {
Expand All @@ -1174,7 +1245,7 @@ resource "aws_synthetics_canary" "test" {
execution_role_arn = aws_iam_role.test.arn
handler = "exports.handler"
zip_file = "test-fixtures/lambdatest.zip"
runtime_version = "syn-nodejs-puppeteer-6.1"
runtime_version = "syn-nodejs-puppeteer-9.0"
delete_lambda = true
schedule {
Expand All @@ -1196,7 +1267,7 @@ resource "aws_synthetics_canary" "test" {
execution_role_arn = aws_iam_role.test.arn
handler = "exports.handler"
zip_file = "test-fixtures/lambdatest.zip"
runtime_version = "syn-nodejs-puppeteer-6.1"
runtime_version = "syn-nodejs-puppeteer-9.0"
delete_lambda = true
schedule {
Expand Down

0 comments on commit 362643d

Please sign in to comment.