Skip to content

Commit

Permalink
r/aws_amplify_app: ForceNew if 'build_spec' changes to "".
Browse files Browse the repository at this point in the history
Acceptance test output:

% make testacc TEST=./aws TESTARGS='-run=TestAccAWSAmplifyApp_BuildSpec'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSAmplifyApp_BuildSpec -timeout 180m
=== RUN   TestAccAWSAmplifyApp_BuildSpec
=== PAUSE TestAccAWSAmplifyApp_BuildSpec
=== CONT  TestAccAWSAmplifyApp_BuildSpec
--- PASS: TestAccAWSAmplifyApp_BuildSpec (33.73s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	37.005s
  • Loading branch information
ewbankkit committed May 19, 2021
1 parent 94a9d17 commit 407f9fe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
6 changes: 5 additions & 1 deletion aws/resource_aws_amplify_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ func resourceAwsAmplifyApp() *schema.Resource {

CustomizeDiff: customdiff.Sequence(
SetTagsDiff,
customdiff.ForceNewIfChange("build_spec", func(_ context.Context, old, new, meta interface{}) bool {
// Any existing value cannot be cleared.
return new.(string) == ""
}),
customdiff.ForceNewIfChange("description", func(_ context.Context, old, new, meta interface{}) bool {
// Any existing description cannot be cleared.
// Any existing value cannot be cleared.
return new.(string) == ""
}),
),
Expand Down
32 changes: 20 additions & 12 deletions aws/resource_aws_amplify_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,24 +265,22 @@ func TestAccAWSAmplifyApp_repository(t *testing.T) {
})
}

func TestAccAWSAmplifyApp_buildSpec(t *testing.T) {
func TestAccAWSAmplifyApp_BuildSpec(t *testing.T) {
var app1, app2, app3 amplify.App
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_amplify_app.test"

// once set, build_spec cannot be removed.
buildSpec1 := "version: 0.1"
buildSpec2 := "version: 0.2"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSAmplify(t) },
ErrorCheck: testAccErrorCheck(t, amplify.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAmplifyAppDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSAmplifyAppConfigBuildSpec(rName, buildSpec1),
Config: testAccAWSAmplifyAppConfigBuildSpec(rName, "version: 0.1"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "build_spec", buildSpec1),
testAccCheckAWSAmplifyAppExists(resourceName, &app1),
resource.TestCheckResourceAttr(resourceName, "build_spec", "version: 0.1"),
),
},
{
Expand All @@ -291,9 +289,19 @@ func TestAccAWSAmplifyApp_buildSpec(t *testing.T) {
ImportStateVerify: true,
},
{
Config: testAccAWSAmplifyAppConfigBuildSpec(rName, buildSpec2),
Config: testAccAWSAmplifyAppConfigBuildSpec(rName, "version: 0.2"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "build_spec", buildSpec2),
testAccCheckAWSAmplifyAppExists(resourceName, &app2),
testAccCheckAWSAmplifyAppNotRecreated(&app1, &app2),
resource.TestCheckResourceAttr(resourceName, "build_spec", "version: 0.2"),
),
},
{
Config: testAccAWSAmplifyAppConfigName(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAmplifyAppExists(resourceName, &app3),
testAccCheckAWSAmplifyAppRecreated(&app2, &app3),
resource.TestCheckResourceAttr(resourceName, "build_spec", ""),
),
},
},
Expand Down Expand Up @@ -623,12 +631,12 @@ resource "aws_amplify_app" "test" {
`, rName, repository, accessToken)
}

func testAccAWSAmplifyAppConfigBuildSpec(rName string, buildSpec string) string {
func testAccAWSAmplifyAppConfigBuildSpec(rName, buildSpec string) string {
return fmt.Sprintf(`
resource "aws_amplify_app" "test" {
name = "%s"
name = %[1]q
build_spec = "%s"
build_spec = %[2]q
}
`, rName, buildSpec)
}
Expand Down

0 comments on commit 407f9fe

Please sign in to comment.