Skip to content

Commit

Permalink
env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
DrFaust92 authored and YakDriver committed Feb 12, 2021
1 parent a48ad23 commit 1b43d1b
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
9 changes: 9 additions & 0 deletions aws/resource_aws_synthetics_canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ func resourceAwsSyntheticsCanary() *schema.Resource {
validation.IntAtLeast(960),
),
},
"environment_variables": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"timeout_in_seconds": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -540,6 +545,10 @@ func expandAwsSyntheticsCanaryRunConfig(l []interface{}) *synthetics.CanaryRunCo
codeConfig.MemoryInMB = aws.Int64(int64(v))
}

if v, ok := m["environment_variables"].(map[string]interface{}); ok && len(v) > 0 {
codeConfig.EnvironmentVariables = stringMapToPointers(v)
}

if v, ok := m["active_tracing"].(bool); ok {
codeConfig.ActiveTracing = aws.Bool(v)
}
Expand Down
98 changes: 98 additions & 0 deletions aws/resource_aws_synthetics_canary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,53 @@ func TestAccAWSSyntheticsCanary_runConfigTracing(t *testing.T) {
})
}

func TestAccAWSSyntheticsCanary_runConfigEnvVars(t *testing.T) {
var conf synthetics.Canary
rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(8))
resourceName := "aws_synthetics_canary.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsSyntheticsCanaryDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSyntheticsCanaryRunConfigEnvVarConfig1(rName, "key1", "value1"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAwsSyntheticsCanaryExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "run_config.0.environment_variables.%", "1"),
resource.TestCheckResourceAttr(resourceName, "run_config.0.environment_variables.key1", "value1"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"zip_file", "start_canary", "run_config.0.environment_variables"},
},
{
Config: testAccAWSSyntheticsCanaryRunConfigEnvVarConfig2(rName, "key1", "value1updated", "key2", "value2"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAwsSyntheticsCanaryExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "run_config.0.environment_variables.%", "2"),
resource.TestCheckResourceAttr(resourceName, "run_config.0.environment_variables.key1", "value1updated"),
resource.TestCheckResourceAttr(resourceName, "run_config.0.environment_variables.key2", "value2"),
),
},
{
Config: testAccAWSSyntheticsCanaryRunConfigEnvVarConfig1(rName, "key2", "value2"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckAwsSyntheticsCanaryExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "run_config.0.environment_variables.%", "1"),
resource.TestCheckResourceAttr(resourceName, "run_config.0.environment_variables.key2", "value2"),
),
},
},
})
}

func TestAccAWSSyntheticsCanary_vpc(t *testing.T) {
var conf synthetics.Canary
rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(8))
Expand Down Expand Up @@ -764,6 +811,57 @@ resource "aws_synthetics_canary" "test" {
`, rName, tracing)
}

func testAccAWSSyntheticsCanaryRunConfigEnvVarConfig1(rName, key1, value1 string) string {
return testAccAWSSyntheticsCanaryConfigBase(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-2.0"
schedule {
expression = "rate(0 minute)"
}
run_config {
timeout_in_seconds = 60
environment_variables = {
%[2]q = %[3]q
}
}
}
`, rName, key1, value1)
}

func testAccAWSSyntheticsCanaryRunConfigEnvVarConfig2(rName, key1, value1, key2, value2 string) string {
return testAccAWSSyntheticsCanaryConfigBase(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-2.0"
schedule {
expression = "rate(0 minute)"
}
run_config {
timeout_in_seconds = 60
environment_variables = {
%[2]q = %[3]q
%[4]q = %[5]q
}
}
}
`, rName, key1, value1, key2, value2)
}

func testAccAWSSyntheticsCanaryBasicConfig(rName string) string {
return testAccAWSSyntheticsCanaryConfigBase(rName) + fmt.Sprintf(`
resource "aws_synthetics_canary" "test" {
Expand Down

0 comments on commit 1b43d1b

Please sign in to comment.