Skip to content

Commit

Permalink
Merge pull request #28439 from Aminevsky/b-aws_lambda_function_url-co…
Browse files Browse the repository at this point in the history
…rs-remove

Fix Lambda function URL cors settings are not removed
  • Loading branch information
ewbankkit authored Dec 20, 2022
2 parents f666815 + d06d96d commit 5b6c641
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/28439.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_lambda_function_url: Fix removal of `cors` configuration block
```
2 changes: 2 additions & 0 deletions internal/service/lambda/function_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ func resourceFunctionURLUpdate(ctx context.Context, d *schema.ResourceData, meta
if d.HasChange("cors") {
if v, ok := d.GetOk("cors"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
input.Cors = expandCors(v.([]interface{})[0].(map[string]interface{}))
} else {
input.Cors = &lambda.Cors{}
}
}

Expand Down
12 changes: 10 additions & 2 deletions internal/service/lambda/function_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ func TestAccLambdaFunctionURL_Cors(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "cors.0.max_age", "72000"),
),
},
{
Config: testAccFunctionURLConfig_basic(funcName, policyName, roleName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckFunctionURLExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "authorization_type", lambda.FunctionUrlAuthTypeNone),
resource.TestCheckResourceAttr(resourceName, "cors.#", "0"),
),
},
},
})
}
Expand Down Expand Up @@ -271,7 +279,7 @@ func testAccFunctionURLConfig_base(policyName, roleName string) string {
data "aws_partition" "current" {}
resource "aws_iam_role_policy" "iam_policy_for_lambda" {
name = "%s"
name = %[1]q
role = aws_iam_role.iam_for_lambda.id
policy = <<EOF
Expand Down Expand Up @@ -322,7 +330,7 @@ EOF
}
resource "aws_iam_role" "iam_for_lambda" {
name = "%s"
name = %[2]q
assume_role_policy = <<EOF
{
Expand Down

0 comments on commit 5b6c641

Please sign in to comment.