Skip to content

Commit

Permalink
Cosmetics.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Oct 24, 2024
1 parent c52be90 commit c1c6c1d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 41 deletions.
67 changes: 28 additions & 39 deletions internal/service/deploy/deployment_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ func resourceDeploymentGroup() *schema.Resource {
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
"termination_hook_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"trigger_configuration": {
Type: schema.TypeSet,
Optional: true,
Expand All @@ -445,11 +450,6 @@ func resourceDeploymentGroup() *schema.Resource {
},
},
},
"termination_hook_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},

CustomizeDiff: verify.SetTagsDiff,
Expand Down Expand Up @@ -518,14 +518,14 @@ func resourceDeploymentGroupCreate(ctx context.Context, d *schema.ResourceData,
input.OutdatedInstancesStrategy = types.OutdatedInstancesStrategy(v.(string))
}

if v, ok := d.GetOk("trigger_configuration"); ok {
input.TriggerConfigurations = expandTriggerConfigs(v.(*schema.Set).List())
}

if v, ok := d.GetOk("termination_hook_enabled"); ok {
input.TerminationHookEnabled = aws.Bool(v.(bool))
}

if v, ok := d.GetOk("trigger_configuration"); ok {
input.TriggerConfigurations = expandTriggerConfigs(v.(*schema.Set).List())
}

outputRaw, err := tfresource.RetryWhen(ctx, 5*time.Minute,
func() (interface{}, error) {
return conn.CreateDeploymentGroup(ctx, input)
Expand Down Expand Up @@ -615,10 +615,10 @@ func resourceDeploymentGroupRead(ctx context.Context, d *schema.ResourceData, me
}
d.Set("outdated_instances_strategy", group.OutdatedInstancesStrategy)
d.Set(names.AttrServiceRoleARN, group.ServiceRoleArn)
d.Set("termination_hook_enabled", group.TerminationHookEnabled)
if err := d.Set("trigger_configuration", flattenTriggerConfigs(group.TriggerConfigurations)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting trigger_configuration: %s", err)
}
d.Set("termination_hook_enabled", group.TerminationHookEnabled)

return diags
}
Expand All @@ -628,13 +628,9 @@ func resourceDeploymentGroupUpdate(ctx context.Context, d *schema.ResourceData,
conn := meta.(*conns.AWSClient).DeployClient(ctx)

if d.HasChangesExcept(names.AttrTags, names.AttrTagsAll) {
// required fields
applicationName := d.Get("app_name").(string)
serviceRoleArn := d.Get(names.AttrServiceRoleARN).(string)

input := codedeploy.UpdateDeploymentGroupInput{
ApplicationName: aws.String(applicationName),
ServiceRoleArn: aws.String(serviceRoleArn),
input := &codedeploy.UpdateDeploymentGroupInput{
ApplicationName: aws.String(d.Get("app_name").(string)),
ServiceRoleArn: aws.String(d.Get(names.AttrServiceRoleARN).(string)),
}

if d.HasChange("deployment_group_name") {
Expand Down Expand Up @@ -724,32 +720,25 @@ func resourceDeploymentGroupUpdate(ctx context.Context, d *schema.ResourceData,
input.TerminationHookEnabled = aws.Bool(n.(bool))
}

log.Printf("[DEBUG] Updating CodeDeploy DeploymentGroup %s", d.Id())

var err error
err = retry.RetryContext(ctx, 5*time.Minute, func() *retry.RetryError {
_, err = conn.UpdateDeploymentGroup(ctx, &input)

if errs.IsA[*types.InvalidRoleException](err) {
return retry.RetryableError(err)
}

if errs.IsAErrorMessageContains[*types.InvalidTriggerConfigException](err, "Topic ARN") {
return retry.RetryableError(err)
}
_, err := tfresource.RetryWhen(ctx, 5*time.Minute,
func() (interface{}, error) {
return conn.UpdateDeploymentGroup(ctx, input)
},
func(err error) (bool, error) {
if errs.IsA[*types.InvalidRoleException](err) {
return true, err
}

if err != nil {
return retry.NonRetryableError(err)
}
if errs.IsAErrorMessageContains[*types.InvalidTriggerConfigException](err, "Topic ARN") {
return true, err
}

return nil
})
return false, err
},
)

if tfresource.TimedOut(err) {
_, err = conn.UpdateDeploymentGroup(ctx, &input)
}
if err != nil {
return sdkdiag.AppendErrorf(diags, "updating CodeDeploy deployment group (%s): %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "updating CodeDeploy Deployment Group (%s): %s", d.Id(), err)
}
}

Expand Down
5 changes: 3 additions & 2 deletions internal/service/deploy/deployment_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func TestAccDeployDeploymentGroup_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "compute_platform", "Server"),
resource.TestCheckResourceAttrSet(resourceName, "deployment_group_id"),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, acctest.Ct0),
resource.TestCheckResourceAttr(resourceName, "termination_hook_enabled", acctest.CtFalse),
),
},
{
Expand Down Expand Up @@ -1597,7 +1598,7 @@ func TestAccDeployDeploymentGroup_TermationHook_enabled(t *testing.T) {
Config: testAccDeploymentGroupConfig_terminationHookEnabled(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDeploymentGroupExists(ctx, resourceName, &group),
resource.TestCheckResourceAttr(resourceName, "termination_hook_enabled", "true"),
resource.TestCheckResourceAttr(resourceName, "termination_hook_enabled", acctest.CtTrue),
),
},
},
Expand All @@ -1620,7 +1621,7 @@ func TestAccDeployDeploymentGroup_TermationHook_disabled(t *testing.T) {
Config: testAccDeploymentGroupConfig_terminationHookDisabled(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDeploymentGroupExists(ctx, resourceName, &group),
resource.TestCheckResourceAttr(resourceName, "termination_hook_enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "termination_hook_enabled", acctest.CtFalse),
),
},
},
Expand Down

0 comments on commit c1c6c1d

Please sign in to comment.