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

ForceNew on Lambda alias name change #4106

Merged
merged 2 commits into from
Apr 9, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions aws/resource_aws_lambda_alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func resourceAwsLambdaAlias() *schema.Resource {
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"arn": &schema.Schema{
Type: schema.TypeString,
Expand Down
38 changes: 38 additions & 0 deletions aws/resource_aws_lambda_alias_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,44 @@ func TestAccAWSLambdaAlias_basic(t *testing.T) {
})
}

func TestAccAWSLambdaAlias_nameupdate(t *testing.T) {
var conf lambda.AliasConfiguration

rString := acctest.RandString(8)
roleName := fmt.Sprintf("tf_acc_role_lambda_alias_basic_%s", rString)
policyName := fmt.Sprintf("tf_acc_policy_lambda_alias_basic_%s", rString)
attachmentName := fmt.Sprintf("tf_acc_attachment_%s", rString)
funcName := fmt.Sprintf("tf_acc_lambda_func_alias_basic_%s", rString)
aliasName := fmt.Sprintf("tf_acc_lambda_alias_basic_%s", rString)
aliasNameUpdate := fmt.Sprintf("tf_acc_lambda_alias_basic_%s", acctest.RandString(8))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsLambdaAliasDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAwsLambdaAliasConfig(roleName, policyName, attachmentName, funcName, aliasName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaAliasExists("aws_lambda_alias.lambda_alias_test", &conf),
testAccCheckAwsLambdaAttributes(&conf),
resource.TestMatchResourceAttr("aws_lambda_alias.lambda_alias_test", "arn",
regexp.MustCompile(`^arn:aws:lambda:[a-z]+-[a-z]+-[0-9]+:\d{12}:function:`+funcName+`:`+aliasName+`$`)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future note: When we start testing outside the aws partition (e.g. US Government) these will break. We can go with something like ^arn:[^:]+:lambda:..., create a partition regex constant, or create our own test check wrapper function for AWS ARNs.

),
},
resource.TestStep{
Config: testAccAwsLambdaAliasConfig(roleName, policyName, attachmentName, funcName, aliasNameUpdate),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsLambdaAliasExists("aws_lambda_alias.lambda_alias_test", &conf),
testAccCheckAwsLambdaAttributes(&conf),
resource.TestMatchResourceAttr("aws_lambda_alias.lambda_alias_test", "arn",
regexp.MustCompile(`^arn:aws:lambda:[a-z]+-[a-z]+-[0-9]+:\d{12}:function:`+funcName+`:`+aliasNameUpdate+`$`)),
),
},
},
})
}

func testAccCheckAwsLambdaAliasDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).lambdaconn

Expand Down