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

New Resource: aws_amplify_branch #11937

Merged
merged 19 commits into from
Jun 2, 2021
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
7 changes: 7 additions & 0 deletions .changelog/11937.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:new-resource
aws_amplify_branch
```

```release-note:bug
resource/aws_amplify_app: Mark the `enable_performance_mode` argumnet in the `auto_branch_creation_config` configuration block as `ForceNew`
```
29 changes: 29 additions & 0 deletions aws/internal/service/amplify/finder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,32 @@ func BackendEnvironmentByAppIDAndEnvironmentName(conn *amplify.Amplify, appID, e

return output.BackendEnvironment, nil
}

func BranchByAppIDAndBranchName(conn *amplify.Amplify, appID, branchName string) (*amplify.Branch, error) {
input := &amplify.GetBranchInput{
AppId: aws.String(appID),
BranchName: aws.String(branchName),
}

output, err := conn.GetBranch(input)

if tfawserr.ErrCodeEquals(err, amplify.ErrCodeNotFoundException) {
return nil, &resource.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if output == nil || output.Branch == nil {
return nil, &resource.NotFoundError{
Message: "Empty result",
LastRequest: input,
}
}

return output.Branch, nil
}
19 changes: 19 additions & 0 deletions aws/internal/service/amplify/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,22 @@ func BackendEnvironmentParseResourceID(id string) (string, string, error) {

return "", "", fmt.Errorf("unexpected format for ID (%[1]s), expected APPID%[2]sENVIRONMENTNAME", id, backendEnvironmentResourceIDSeparator)
}

const branchResourceIDSeparator = "/"

func BranchCreateResourceID(appID, branchName string) string {
parts := []string{appID, branchName}
id := strings.Join(parts, branchResourceIDSeparator)

return id
}

func BranchParseResourceID(id string) (string, string, error) {
parts := strings.Split(id, branchResourceIDSeparator)

if len(parts) == 2 && parts[0] != "" && parts[1] != "" {
return parts[0], parts[1], nil
}

return "", "", fmt.Errorf("unexpected format for ID (%[1]s), expected APPID%[2]sBRANCHNAME", id, branchResourceIDSeparator)
}
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ func Provider() *schema.Provider {
"aws_ami_launch_permission": resourceAwsAmiLaunchPermission(),
"aws_amplify_app": resourceAwsAmplifyApp(),
"aws_amplify_backend_environment": resourceAwsAmplifyBackendEnvironment(),
"aws_amplify_branch": resourceAwsAmplifyBranch(),
"aws_api_gateway_account": resourceAwsApiGatewayAccount(),
"aws_api_gateway_api_key": resourceAwsApiGatewayApiKey(),
"aws_api_gateway_authorizer": resourceAwsApiGatewayAuthorizer(),
Expand Down
1 change: 1 addition & 0 deletions aws/resource_aws_amplify_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func resourceAwsAmplifyApp() *schema.Resource {
"enable_performance_mode": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},

"enable_pull_request_preview": {
Expand Down
4 changes: 1 addition & 3 deletions aws/resource_aws_amplify_backend_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ func testAccAWSAmplifyBackendEnvironment_DeploymentArtifacts_StackName(t *testin
})
}

// testAccAWSAmplifyBackendEnvironmentConfigDeploymentArtifactsAndStackName(rname, environmentName)

func testAccCheckAWSAmplifyBackendEnvironmentExists(resourceName string, v *amplify.BackendEnvironment) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
Expand Down Expand Up @@ -160,7 +158,7 @@ func testAccCheckAWSAmplifyBackendEnvironmentDestroy(s *terraform.State) error {
return err
}

return fmt.Errorf("Amplify BackendEnvironment %s still exists", rs.Primary.ID)
return fmt.Errorf("Amplify Backend Environment %s still exists", rs.Primary.ID)
}

return nil
Expand Down
Loading