Skip to content

Commit

Permalink
fix name check on read
Browse files Browse the repository at this point in the history
  • Loading branch information
DrFaust92 committed Apr 14, 2021
1 parent 16bf681 commit 72d4a8a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
27 changes: 20 additions & 7 deletions aws/resource_aws_codedeploy_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func resourceAwsCodeDeployApp() *schema.Resource {
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 100),
},

Expand Down Expand Up @@ -120,8 +119,9 @@ func resourceAwsCodeDeployAppRead(d *schema.ResourceData, meta interface{}) erro
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig

application := resourceAwsCodeDeployAppParseId(d.Id())
if application != d.Get("name").(string) {
application = d.Get("name").(string)
name := d.Get("name").(string)
if name != "" && application != name {
application = name
}
log.Printf("[DEBUG] Reading CodeDeploy application %s", application)
resp, err := conn.GetApplication(&codedeploy.GetApplicationInput{
Expand All @@ -141,10 +141,10 @@ func resourceAwsCodeDeployAppRead(d *schema.ResourceData, meta interface{}) erro
app := resp.Application
appName := aws.StringValue(app.ApplicationName)

if !strings.Contains(d.Id(), appName) {
d.SetId(fmt.Sprintf("%s:%s", aws.StringValue(app.ApplicationId), appName))
}
if !strings.Contains(d.Id(), appName) {
d.SetId(fmt.Sprintf("%s:%s", aws.StringValue(app.ApplicationId), appName))
}

appArn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Service: "codedeploy",
Expand Down Expand Up @@ -176,6 +176,19 @@ func resourceAwsCodeDeployAppRead(d *schema.ResourceData, meta interface{}) erro
func resourceAwsCodeDeployUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).codedeployconn

if d.HasChange("name") {
o, n := d.GetChange("name")

_, err := conn.UpdateApplication(&codedeploy.UpdateApplicationInput{
ApplicationName: aws.String(o.(string)),
NewApplicationName: aws.String(n.(string)),
})

if err != nil {
return fmt.Errorf("error updating CodeDeploy Application (%s) name: %w", d.Id(), err)
}
}

if d.HasChange("tags") {
o, n := d.GetChange("tags")

Expand Down
1 change: 0 additions & 1 deletion aws/resource_aws_codedeploy_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ func TestAccAWSCodeDeployApp_name(t *testing.T) {
Config: testAccAWSCodeDeployAppConfigName(rName2),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSCodeDeployAppExists(resourceName, &application2),
testAccCheckAWSCodeDeployAppRecreated(&application1, &application2),
resource.TestCheckResourceAttr(resourceName, "name", rName2),
),
},
Expand Down

0 comments on commit 72d4a8a

Please sign in to comment.