From f9e8f1509ad43d5d2607d2ef9992614a18776119 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 23 Feb 2022 13:36:17 -0600 Subject: [PATCH 01/13] add enviornment variables to run config --- internal/service/synthetics/canary.go | 26 +++++++++++++++++----- internal/service/synthetics/canary_test.go | 6 ++++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/internal/service/synthetics/canary.go b/internal/service/synthetics/canary.go index da27e8b744b..c16aff570ce 100644 --- a/internal/service/synthetics/canary.go +++ b/internal/service/synthetics/canary.go @@ -114,6 +114,11 @@ func ResourceCanary() *schema.Resource { Type: schema.TypeBool, Optional: true, }, + "environment_variables": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, "memory_in_mb": { Type: schema.TypeInt, Optional: true, @@ -385,7 +390,13 @@ func resourceCanaryRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("error setting vpc config: %w", err) } - if err := d.Set("run_config", flattenCanaryRunConfig(canary.RunConfig)); err != nil { + // get environment variables since they are not available on describe + runConfig := &synthetics.CanaryRunConfigInput{} + if v, ok := d.GetOk("run_config"); ok { + runConfig = expandCanaryRunConfig(v.([]interface{})) + } + + if err := d.Set("run_config", flattenCanaryRunConfig(canary.RunConfig, runConfig.EnvironmentVariables)); err != nil { return fmt.Errorf("error setting run config: %w", err) } @@ -703,18 +714,23 @@ func expandCanaryRunConfig(l []interface{}) *synthetics.CanaryRunConfigInput { codeConfig.ActiveTracing = aws.Bool(v) } + if v, ok := m["enviroment_variables"].(map[string]string); ok { + codeConfig.EnvironmentVariables = aws.StringMap(v) + } + return codeConfig } -func flattenCanaryRunConfig(canaryCodeOut *synthetics.CanaryRunConfigOutput) []interface{} { +func flattenCanaryRunConfig(canaryCodeOut *synthetics.CanaryRunConfigOutput, envVars map[string]*string) []interface{} { if canaryCodeOut == nil { return []interface{}{} } m := map[string]interface{}{ - "timeout_in_seconds": aws.Int64Value(canaryCodeOut.TimeoutInSeconds), - "memory_in_mb": aws.Int64Value(canaryCodeOut.MemoryInMB), - "active_tracing": aws.BoolValue(canaryCodeOut.ActiveTracing), + "timeout_in_seconds": aws.Int64Value(canaryCodeOut.TimeoutInSeconds), + "memory_in_mb": aws.Int64Value(canaryCodeOut.MemoryInMB), + "active_tracing": aws.BoolValue(canaryCodeOut.ActiveTracing), + "environment_variables": aws.StringValueMap(envVars), } return []interface{}{m} diff --git a/internal/service/synthetics/canary_test.go b/internal/service/synthetics/canary_test.go index 6dcd0864259..ad57827bbed 100644 --- a/internal/service/synthetics/canary_test.go +++ b/internal/service/synthetics/canary_test.go @@ -319,6 +319,7 @@ func TestAccSyntheticsCanary_run(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "run_config.0.memory_in_mb", "1000"), resource.TestCheckResourceAttr(resourceName, "run_config.0.timeout_in_seconds", "60"), + resource.TestCheckResourceAttr(resourceName, "run_config.0.environment_variables.foo", "bar"), ), }, { @@ -761,7 +762,10 @@ resource "aws_synthetics_canary" "test" { } run_config { - timeout_in_seconds = 60 + timeout_in_seconds = 60 + environment_variables = { + foo = "bar" + } } depends_on = [aws_iam_role.test, aws_iam_role_policy.test] From 815b2b705d42c7e8bb24da2bf1f3327d850583cc Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 3 Mar 2022 11:58:12 -0600 Subject: [PATCH 02/13] r/aws_synthntics_canary: add environment variables to run_config --- internal/service/synthetics/canary.go | 28 +++++++++++++++------- internal/service/synthetics/canary_test.go | 11 ++++++--- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/internal/service/synthetics/canary.go b/internal/service/synthetics/canary.go index c16aff570ce..0dc251fd366 100644 --- a/internal/service/synthetics/canary.go +++ b/internal/service/synthetics/canary.go @@ -391,12 +391,15 @@ func resourceCanaryRead(d *schema.ResourceData, meta interface{}) error { } // get environment variables since they are not available on describe - runConfig := &synthetics.CanaryRunConfigInput{} + envVars := make(map[string]*string) if v, ok := d.GetOk("run_config"); ok { - runConfig = expandCanaryRunConfig(v.([]interface{})) + runConfig := expandCanaryRunConfig(v.([]interface{})) + for k, v := range runConfig.EnvironmentVariables { + envVars[k] = v + } } - if err := d.Set("run_config", flattenCanaryRunConfig(canary.RunConfig, runConfig.EnvironmentVariables)); err != nil { + if err := d.Set("run_config", flattenCanaryRunConfig(canary.RunConfig, envVars)); err != nil { return fmt.Errorf("error setting run config: %w", err) } @@ -714,8 +717,12 @@ func expandCanaryRunConfig(l []interface{}) *synthetics.CanaryRunConfigInput { codeConfig.ActiveTracing = aws.Bool(v) } - if v, ok := m["enviroment_variables"].(map[string]string); ok { - codeConfig.EnvironmentVariables = aws.StringMap(v) + if vars, ok := m["environment_variables"].(map[string]interface{}); ok { + ev := make(map[string]string) + for k, v := range vars { + ev[k] = v.(string) + } + codeConfig.EnvironmentVariables = aws.StringMap(ev) } return codeConfig @@ -727,10 +734,13 @@ func flattenCanaryRunConfig(canaryCodeOut *synthetics.CanaryRunConfigOutput, env } m := map[string]interface{}{ - "timeout_in_seconds": aws.Int64Value(canaryCodeOut.TimeoutInSeconds), - "memory_in_mb": aws.Int64Value(canaryCodeOut.MemoryInMB), - "active_tracing": aws.BoolValue(canaryCodeOut.ActiveTracing), - "environment_variables": aws.StringValueMap(envVars), + "timeout_in_seconds": aws.Int64Value(canaryCodeOut.TimeoutInSeconds), + "memory_in_mb": aws.Int64Value(canaryCodeOut.MemoryInMB), + "active_tracing": aws.BoolValue(canaryCodeOut.ActiveTracing), + } + + if v := envVars; v != nil { + m["environment_variables"] = aws.StringValueMap(envVars) } return []interface{}{m} diff --git a/internal/service/synthetics/canary_test.go b/internal/service/synthetics/canary_test.go index ad57827bbed..0d5c4e70c20 100644 --- a/internal/service/synthetics/canary_test.go +++ b/internal/service/synthetics/canary_test.go @@ -319,14 +319,14 @@ func TestAccSyntheticsCanary_run(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "run_config.0.memory_in_mb", "1000"), resource.TestCheckResourceAttr(resourceName, "run_config.0.timeout_in_seconds", "60"), - resource.TestCheckResourceAttr(resourceName, "run_config.0.environment_variables.foo", "bar"), + resource.TestCheckResourceAttr(resourceName, "run_config.0.environment_variables.test1", "result1"), ), }, { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"zip_file", "start_canary"}, + ImportStateVerifyIgnore: []string{"zip_file", "start_canary", "run_config.0.environment_variables"}, }, { Config: testAccCanaryRun2Config(rName), @@ -334,6 +334,7 @@ func TestAccSyntheticsCanary_run(t *testing.T) { testAccCheckCanaryExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "run_config.0.memory_in_mb", "960"), resource.TestCheckResourceAttr(resourceName, "run_config.0.timeout_in_seconds", "120"), + resource.TestCheckResourceAttr(resourceName, "run_config.0.environment_variables.test2", "result2"), ), }, { @@ -764,7 +765,7 @@ resource "aws_synthetics_canary" "test" { run_config { timeout_in_seconds = 60 environment_variables = { - foo = "bar" + test1 = "result1" } } @@ -790,6 +791,10 @@ resource "aws_synthetics_canary" "test" { run_config { timeout_in_seconds = 120 memory_in_mb = 960 + environment_variables = { + test1 = "result1" + test2 = "result2" + } } depends_on = [aws_iam_role.test, aws_iam_role_policy.test] From 04ffb8d9178a3d2c428af9c0ae2e58f3f16c0cf8 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Mon, 7 Mar 2022 11:02:46 -0500 Subject: [PATCH 03/13] docs: update canary docs --- website/docs/r/synthetics_canary.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/r/synthetics_canary.html.markdown b/website/docs/r/synthetics_canary.html.markdown index 983699ab4f1..557b35d7a86 100644 --- a/website/docs/r/synthetics_canary.html.markdown +++ b/website/docs/r/synthetics_canary.html.markdown @@ -73,6 +73,7 @@ The following arguments are optional: * `timeout_in_seconds` - (Optional) Number of seconds the canary is allowed to run before it must stop. If you omit this field, the frequency of the canary is used, up to a maximum of 840 (14 minutes). * `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. * `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. +* `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. ### vpc_config From c89fa150add964ce504ec8a4986a22e0ee270744 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Mon, 7 Mar 2022 16:26:27 -0500 Subject: [PATCH 04/13] r/aws_synthntics_canary: refactor fetching environment variables --- internal/service/synthetics/canary.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/internal/service/synthetics/canary.go b/internal/service/synthetics/canary.go index 0dc251fd366..fe3bc7c350d 100644 --- a/internal/service/synthetics/canary.go +++ b/internal/service/synthetics/canary.go @@ -390,16 +390,13 @@ func resourceCanaryRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("error setting vpc config: %w", err) } - // get environment variables since they are not available on describe - envVars := make(map[string]*string) + // get environment variables since they a + runConfig := &synthetics.CanaryRunConfigInput{} if v, ok := d.GetOk("run_config"); ok { - runConfig := expandCanaryRunConfig(v.([]interface{})) - for k, v := range runConfig.EnvironmentVariables { - envVars[k] = v - } + runConfig = expandCanaryRunConfig(v.([]interface{})) } - if err := d.Set("run_config", flattenCanaryRunConfig(canary.RunConfig, envVars)); err != nil { + if err := d.Set("run_config", flattenCanaryRunConfig(canary.RunConfig, runConfig.EnvironmentVariables)); err != nil { return fmt.Errorf("error setting run config: %w", err) } From 2b757a44693ca25f2b43d5c4f5446355f5da3e05 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Tue, 8 Mar 2022 11:32:05 -0500 Subject: [PATCH 05/13] r/aws_synthntics_canary: acctest fmt --- internal/service/synthetics/canary_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/service/synthetics/canary_test.go b/internal/service/synthetics/canary_test.go index 0d5c4e70c20..d841f4cf6a4 100644 --- a/internal/service/synthetics/canary_test.go +++ b/internal/service/synthetics/canary_test.go @@ -789,11 +789,11 @@ resource "aws_synthetics_canary" "test" { } run_config { - timeout_in_seconds = 120 - memory_in_mb = 960 + timeout_in_seconds = 120 + memory_in_mb = 960 environment_variables = { test1 = "result1" - test2 = "result2" + test2 = "result2" } } From fb6c4f526afa89f02023be6156b799d3d1252b64 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Tue, 8 Mar 2022 11:51:36 -0500 Subject: [PATCH 06/13] r/aws_synthntics_canary: acctest fmt --- internal/service/synthetics/canary_test.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/internal/service/synthetics/canary_test.go b/internal/service/synthetics/canary_test.go index d841f4cf6a4..1038a0a33db 100644 --- a/internal/service/synthetics/canary_test.go +++ b/internal/service/synthetics/canary_test.go @@ -763,10 +763,11 @@ resource "aws_synthetics_canary" "test" { } run_config { - timeout_in_seconds = 60 - environment_variables = { - test1 = "result1" - } + timeout_in_seconds = 60 + + environment_variables = { + test1 = "result1" + } } depends_on = [aws_iam_role.test, aws_iam_role_policy.test] @@ -789,12 +790,13 @@ resource "aws_synthetics_canary" "test" { } run_config { - timeout_in_seconds = 120 - memory_in_mb = 960 - environment_variables = { - test1 = "result1" - test2 = "result2" - } + timeout_in_seconds = 120 + memory_in_mb = 960 + + environment_variables = { + test1 = "result1" + test2 = "result2" + } } depends_on = [aws_iam_role.test, aws_iam_role_policy.test] From e73956e48988689c197703d235019128b4711892 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Tue, 8 Mar 2022 12:10:36 -0500 Subject: [PATCH 07/13] r/aws_synthntics_canary: acctest fmt --- internal/service/synthetics/canary_test.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/internal/service/synthetics/canary_test.go b/internal/service/synthetics/canary_test.go index 1038a0a33db..1873e836489 100644 --- a/internal/service/synthetics/canary_test.go +++ b/internal/service/synthetics/canary_test.go @@ -764,9 +764,8 @@ resource "aws_synthetics_canary" "test" { run_config { timeout_in_seconds = 60 - environment_variables = { - test1 = "result1" + test1 = "result1" } } @@ -792,10 +791,9 @@ resource "aws_synthetics_canary" "test" { run_config { timeout_in_seconds = 120 memory_in_mb = 960 - environment_variables = { - test1 = "result1" - test2 = "result2" + test1 = "result1" + test2 = "result2" } } From a03d5b1d083375a10755f53ac3a8ebd26061d7f6 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Tue, 8 Mar 2022 16:38:36 -0500 Subject: [PATCH 08/13] update CHANGELOG for #23574 --- .changelog/23574.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/23574.txt diff --git a/.changelog/23574.txt b/.changelog/23574.txt new file mode 100644 index 00000000000..32f6daf5be6 --- /dev/null +++ b/.changelog/23574.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_synthetics_canary: Add optional `environment variables` to `run_config`. +``` \ No newline at end of file From 79001f5f86f3bd19c6426f57ee7f89396365a470 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 9 Mar 2022 12:42:26 -0500 Subject: [PATCH 09/13] Update .changelog/23574.txt Co-authored-by: angie pinilla --- .changelog/23574.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/23574.txt b/.changelog/23574.txt index 32f6daf5be6..3dd23b946b6 100644 --- a/.changelog/23574.txt +++ b/.changelog/23574.txt @@ -1,3 +1,3 @@ ```release-note:enhancement -resource/aws_synthetics_canary: Add optional `environment variables` to `run_config`. +resource/aws_synthetics_canary: Add optional `environment_variables` to `run_config`. ``` \ No newline at end of file From 8a036263c2b111935be1b2ce6a9f94316114d542 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 9 Mar 2022 12:45:34 -0500 Subject: [PATCH 10/13] remove unused variable for envVars check Co-authored-by: angie pinilla --- internal/service/synthetics/canary.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/synthetics/canary.go b/internal/service/synthetics/canary.go index fe3bc7c350d..1341dafd00e 100644 --- a/internal/service/synthetics/canary.go +++ b/internal/service/synthetics/canary.go @@ -736,7 +736,7 @@ func flattenCanaryRunConfig(canaryCodeOut *synthetics.CanaryRunConfigOutput, env "active_tracing": aws.BoolValue(canaryCodeOut.ActiveTracing), } - if v := envVars; v != nil { + if envVars != nil { m["environment_variables"] = aws.StringValueMap(envVars) } From 8fbb2e1a404862a40a5d46e21fb33d71c4df374f Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 9 Mar 2022 12:47:15 -0500 Subject: [PATCH 11/13] Update `environment_variables` check to use `flex.ExpandStringMap` Co-authored-by: angie pinilla --- internal/service/synthetics/canary.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/internal/service/synthetics/canary.go b/internal/service/synthetics/canary.go index 1341dafd00e..0f9f994bb3c 100644 --- a/internal/service/synthetics/canary.go +++ b/internal/service/synthetics/canary.go @@ -714,12 +714,8 @@ func expandCanaryRunConfig(l []interface{}) *synthetics.CanaryRunConfigInput { codeConfig.ActiveTracing = aws.Bool(v) } - if vars, ok := m["environment_variables"].(map[string]interface{}); ok { - ev := make(map[string]string) - for k, v := range vars { - ev[k] = v.(string) - } - codeConfig.EnvironmentVariables = aws.StringMap(ev) + if vars, ok := m["environment_variables"].(map[string]interface{}); ok && len(vars) > 0 { + codeConfig.EnvironmentVariables = flex.ExpandStringMap(ev) } return codeConfig From 6f9c989cddf4c1b27052e6df902f9057476cc61e Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 9 Mar 2022 13:40:51 -0500 Subject: [PATCH 12/13] r/aws_synthntics_canary: add acceptance test for `environment_variables` --- internal/service/synthetics/canary.go | 3 +- internal/service/synthetics/canary_test.go | 120 +++++++++++++++++++-- 2 files changed, 114 insertions(+), 9 deletions(-) diff --git a/internal/service/synthetics/canary.go b/internal/service/synthetics/canary.go index 0f9f994bb3c..1b5ddd438e3 100644 --- a/internal/service/synthetics/canary.go +++ b/internal/service/synthetics/canary.go @@ -390,7 +390,6 @@ func resourceCanaryRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("error setting vpc config: %w", err) } - // get environment variables since they a runConfig := &synthetics.CanaryRunConfigInput{} if v, ok := d.GetOk("run_config"); ok { runConfig = expandCanaryRunConfig(v.([]interface{})) @@ -715,7 +714,7 @@ func expandCanaryRunConfig(l []interface{}) *synthetics.CanaryRunConfigInput { } if vars, ok := m["environment_variables"].(map[string]interface{}); ok && len(vars) > 0 { - codeConfig.EnvironmentVariables = flex.ExpandStringMap(ev) + codeConfig.EnvironmentVariables = flex.ExpandStringMap(vars) } return codeConfig diff --git a/internal/service/synthetics/canary_test.go b/internal/service/synthetics/canary_test.go index 1873e836489..d81f268b891 100644 --- a/internal/service/synthetics/canary_test.go +++ b/internal/service/synthetics/canary_test.go @@ -391,6 +391,49 @@ func TestAccSyntheticsCanary_runTracing(t *testing.T) { }) } +func TestAccSyntheticsCanary_runEnvironmentVariables(t *testing.T) { + var conf synthetics.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(t) }, + ErrorCheck: acctest.ErrorCheck(t, synthetics.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckCanaryDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCanaryRunEnvVariables1Config(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckCanaryExists(resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "run_config.0.environment_variables.test1", "result1"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"zip_file", "start_canary", "run_config.0.environment_variables"}, + }, + { + Config: testAccCanaryRunEnvVariables2Config(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckCanaryExists(resourceName, &conf), + resource.TestCheckResourceAttr(resourceName, "run_config.0.environment_variables.test1", "result1"), + resource.TestCheckResourceAttr(resourceName, "run_config.0.environment_variables.test2", "result2"), + ), + }, + { + Config: testAccCanaryRunEnvVariables3Config(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckCanaryExists(resourceName, &conf), + resource.TestCheckNoResourceAttr(resourceName, "run_config.0.environment_variables"), + ), + }, + }, + }) +} + func TestAccSyntheticsCanary_vpc(t *testing.T) { if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -764,9 +807,6 @@ resource "aws_synthetics_canary" "test" { run_config { timeout_in_seconds = 60 - environment_variables = { - test1 = "result1" - } } depends_on = [aws_iam_role.test, aws_iam_role_policy.test] @@ -791,10 +831,6 @@ resource "aws_synthetics_canary" "test" { run_config { timeout_in_seconds = 120 memory_in_mb = 960 - environment_variables = { - test1 = "result1" - test2 = "result2" - } } depends_on = [aws_iam_role.test, aws_iam_role_policy.test] @@ -826,6 +862,76 @@ resource "aws_synthetics_canary" "test" { `, rName, tracing)) } +func testAccCanaryRunEnvVariables1Config(rName string) string { + return acctest.ConfigCompose(testAccCanaryBaseConfig(rName), 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 = "syn-nodejs-puppeteer-3.2" + + schedule { + expression = "rate(0 minute)" + } + + run_config { + environment_variables = { + test1 = "result1" + } + } + + depends_on = [aws_iam_role.test, aws_iam_role_policy.test] +} +`, rName)) +} + +func testAccCanaryRunEnvVariables2Config(rName string) string { + return acctest.ConfigCompose(testAccCanaryBaseConfig(rName), 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 = "syn-nodejs-puppeteer-3.2" + + schedule { + expression = "rate(0 minute)" + } + + run_config { + environment_variables = { + test1 = "result1" + test2 = "result2" + } + } + + depends_on = [aws_iam_role.test, aws_iam_role_policy.test] +} +`, rName)) +} + +func testAccCanaryRunEnvVariables3Config(rName string) string { + return acctest.ConfigCompose(testAccCanaryBaseConfig(rName), 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 = "syn-nodejs-puppeteer-3.2" + + schedule { + expression = "rate(0 minute)" + } + + depends_on = [aws_iam_role.test, aws_iam_role_policy.test] +} +`, rName)) +} + func testAccCanaryBasicConfig(rName string) string { return acctest.ConfigCompose(testAccCanaryBaseConfig(rName), fmt.Sprintf(` resource "aws_synthetics_canary" "test" { From cc1e9db182728ad1dccf018bf2d5f62c67fa9db8 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 9 Mar 2022 13:46:23 -0500 Subject: [PATCH 13/13] r/aws_synthntics_canary: remove missing key check in acctest --- internal/service/synthetics/canary_test.go | 33 ++++------------------ 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/internal/service/synthetics/canary_test.go b/internal/service/synthetics/canary_test.go index d81f268b891..05146fe345e 100644 --- a/internal/service/synthetics/canary_test.go +++ b/internal/service/synthetics/canary_test.go @@ -319,14 +319,13 @@ func TestAccSyntheticsCanary_run(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "run_config.0.memory_in_mb", "1000"), resource.TestCheckResourceAttr(resourceName, "run_config.0.timeout_in_seconds", "60"), - resource.TestCheckResourceAttr(resourceName, "run_config.0.environment_variables.test1", "result1"), ), }, { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"zip_file", "start_canary", "run_config.0.environment_variables"}, + ImportStateVerifyIgnore: []string{"zip_file", "start_canary"}, }, { Config: testAccCanaryRun2Config(rName), @@ -334,7 +333,6 @@ func TestAccSyntheticsCanary_run(t *testing.T) { testAccCheckCanaryExists(resourceName, &conf), resource.TestCheckResourceAttr(resourceName, "run_config.0.memory_in_mb", "960"), resource.TestCheckResourceAttr(resourceName, "run_config.0.timeout_in_seconds", "120"), - resource.TestCheckResourceAttr(resourceName, "run_config.0.environment_variables.test2", "result2"), ), }, { @@ -424,7 +422,7 @@ func TestAccSyntheticsCanary_runEnvironmentVariables(t *testing.T) { ), }, { - Config: testAccCanaryRunEnvVariables3Config(rName), + Config: testAccCanaryBasicConfig(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckCanaryExists(resourceName, &conf), resource.TestCheckNoResourceAttr(resourceName, "run_config.0.environment_variables"), @@ -878,8 +876,8 @@ resource "aws_synthetics_canary" "test" { run_config { environment_variables = { - test1 = "result1" - } + test1 = "result1" + } } depends_on = [aws_iam_role.test, aws_iam_role_policy.test] @@ -903,28 +901,9 @@ resource "aws_synthetics_canary" "test" { run_config { environment_variables = { - test1 = "result1" + test1 = "result1" test2 = "result2" - } - } - - depends_on = [aws_iam_role.test, aws_iam_role_policy.test] -} -`, rName)) -} - -func testAccCanaryRunEnvVariables3Config(rName string) string { - return acctest.ConfigCompose(testAccCanaryBaseConfig(rName), 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 = "syn-nodejs-puppeteer-3.2" - - schedule { - expression = "rate(0 minute)" + } } depends_on = [aws_iam_role.test, aws_iam_role_policy.test]