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

r/aws_codebuild_fleet: Allow scaling_configuration to be removed on Update #40773

Merged
Show file tree
Hide file tree
Changes from 3 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
18 changes: 10 additions & 8 deletions internal/service/codebuild/fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,8 @@ func resourceFleetRead(ctx context.Context, d *schema.ResourceData, meta interfa
d.Set(names.AttrName, fleet.Name)
d.Set("overflow_behavior", fleet.OverflowBehavior)

if fleet.ScalingConfiguration != nil {
if err := d.Set("scaling_configuration", []interface{}{flattenScalingConfiguration(fleet.ScalingConfiguration)}); err != nil {
return create.AppendDiagError(diags, names.CodeBuild, create.ErrActionSetting, resNameFleet, d.Id(), err)
}
} else {
d.Set("scaling_configuration", nil)
if err := d.Set("scaling_configuration", flattenScalingConfiguration(fleet.ScalingConfiguration)); err != nil {
return create.AppendDiagError(diags, names.CodeBuild, create.ErrActionSetting, resNameFleet, d.Id(), err)
}

if fleet.Status != nil {
Expand Down Expand Up @@ -392,6 +388,8 @@ func resourceFleetUpdate(ctx context.Context, d *schema.ResourceData, meta inter
if d.HasChange("scaling_configuration") {
if v, ok := d.GetOk("scaling_configuration"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
input.ScalingConfiguration = expandScalingConfiguration(v.([]interface{})[0].(map[string]interface{}))
} else {
input.ScalingConfiguration = &types.ScalingConfigurationInput{}
}
}

Expand Down Expand Up @@ -689,7 +687,7 @@ func flattenComputeConfiguration(apiObject *types.ComputeConfiguration) map[stri
return tfMap
}

func flattenScalingConfiguration(apiObject *types.ScalingConfigurationOutput) map[string]interface{} {
func flattenScalingConfiguration(apiObject *types.ScalingConfigurationOutput) []interface{} {
if apiObject == nil {
return nil
}
Expand All @@ -712,7 +710,11 @@ func flattenScalingConfiguration(apiObject *types.ScalingConfigurationOutput) ma
tfMap["target_tracking_scaling_configs"] = flattenTargetTrackingScalingConfigs(v)
}

return tfMap
if len(tfMap) == 0 {
return nil
}

return []interface{}{tfMap}
ewbankkit marked this conversation as resolved.
Show resolved Hide resolved
}

func flattenTargetTrackingScalingConfigs(apiObjects []types.TargetTrackingScalingConfiguration) []interface{} {
Expand Down
24 changes: 24 additions & 0 deletions internal/service/codebuild/fleet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ func TestAccCodeBuildFleet_scalingConfiguration(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.0.target_tracking_scaling_configs.0.target_value", "97.5"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccFleetConfig_scalingConfiguration2(rName),
Check: resource.ComposeTestCheckFunc(
Expand All @@ -301,6 +306,13 @@ func TestAccCodeBuildFleet_scalingConfiguration(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.0.target_tracking_scaling_configs.0.target_value", "90.5"),
),
},
{
Config: testAccFleetConfig_scalingConfiguration3(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckFleetExists(ctx, resourceName),
resource.TestCheckResourceAttr(resourceName, "scaling_configuration.#", "0"),
),
},
},
})
}
Expand Down Expand Up @@ -509,6 +521,18 @@ resource "aws_codebuild_fleet" "test" {
`, rName)
}

func testAccFleetConfig_scalingConfiguration3(rName string) string {
return fmt.Sprintf(`
resource "aws_codebuild_fleet" "test" {
base_capacity = 1
compute_type = "BUILD_GENERAL1_SMALL"
environment_type = "ARM_CONTAINER"
name = %[1]q
overflow_behavior = "QUEUE"
}
`, rName)
}

func testAccFleetConfig_baseFleetServiceRole(rName string) string {
return fmt.Sprintf(`
resource "aws_iam_role" "test" {
Expand Down
Loading