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_ecs_service: Fix removal of service_registries attribute #30852

Merged
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
3 changes: 3 additions & 0 deletions .changelog/30852.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_ecs_service: Fix removal of `service_registries` configuration block
```
4 changes: 3 additions & 1 deletion internal/service/ecs/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ func FindServiceByID(ctx context.Context, conn *ecs.ECS, id, cluster string) (*e

func FindServiceNoTagsByID(ctx context.Context, conn *ecs.ECS, id, cluster string) (*ecs.Service, error) {
input := &ecs.DescribeServicesInput{
Cluster: aws.String(cluster),
Services: aws.StringSlice([]string{id}),
}
if cluster != "" {
input.Cluster = aws.String(cluster)
}

return FindService(ctx, conn, input)
}
Expand Down
4 changes: 0 additions & 4 deletions internal/service/ecs/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,6 @@ func flattenTaskSetLoadBalancers(list []*ecs.LoadBalancer) []map[string]interfac
// Expand for an array of service registries and
// returns ecs.ServiceRegistry compatible objects for an ECS TaskSet
func expandServiceRegistries(l []interface{}) []*ecs.ServiceRegistry {
if len(l) == 0 || l[0] == nil {
return nil
}

result := make([]*ecs.ServiceRegistry, 0, len(l))

for _, v := range l {
Expand Down
70 changes: 34 additions & 36 deletions internal/service/ecs/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ func resourceServiceCreate(ctx context.Context, d *schema.ResourceData, meta int

deploymentController := expandDeploymentController(d.Get("deployment_controller").([]interface{}))
deploymentMinimumHealthyPercent := d.Get("deployment_minimum_healthy_percent").(int)
name := d.Get("name").(string)
schedulingStrategy := d.Get("scheduling_strategy").(string)
input := ecs.CreateServiceInput{
CapacityProviderStrategy: expandCapacityProviderStrategy(d.Get("capacity_provider_strategy").(*schema.Set)),
Expand All @@ -489,7 +490,7 @@ func resourceServiceCreate(ctx context.Context, d *schema.ResourceData, meta int
EnableExecuteCommand: aws.Bool(d.Get("enable_execute_command").(bool)),
NetworkConfiguration: expandNetworkConfiguration(d.Get("network_configuration").([]interface{})),
SchedulingStrategy: aws.String(schedulingStrategy),
ServiceName: aws.String(d.Get("name").(string)),
ServiceName: aws.String(name),
Tags: GetTagsIn(ctx),
}

Expand Down Expand Up @@ -541,7 +542,7 @@ func resourceServiceCreate(ctx context.Context, d *schema.ResourceData, meta int
ps, err := expandPlacementStrategy(v.([]interface{}))

if err != nil {
return sdkdiag.AppendErrorf(diags, "creating ECS Service (%s): %s", d.Get("name").(string), err)
return sdkdiag.AppendFromErr(diags, err)
}

input.PlacementStrategy = ps
Expand All @@ -551,7 +552,7 @@ func resourceServiceCreate(ctx context.Context, d *schema.ResourceData, meta int
pc, err := expandPlacementConstraints(v.List())

if err != nil {
return sdkdiag.AppendErrorf(diags, "creating ECS Service (%s): %s", d.Get("name").(string), err)
return sdkdiag.AppendFromErr(diags, err)
}

input.PlacementConstraints = pc
Expand Down Expand Up @@ -600,28 +601,24 @@ func resourceServiceCreate(ctx context.Context, d *schema.ResourceData, meta int

// Some partitions (i.e., ISO) may not support tag-on-create
if input.Tags != nil && verify.ErrorISOUnsupported(conn.PartitionID, err) {
log.Printf("[WARN] failed creating ECS Service (%s) with tags: %s. Trying create without tags.", d.Get("name").(string), err)
log.Printf("[WARN] failed creating ECS Service (%s) with tags: %s. Trying create without tags.", name, err)
input.Tags = nil

output, err = serviceCreateWithRetry(ctx, conn, input)
}

if err != nil {
return sdkdiag.AppendErrorf(diags, "creating ECS Service (%s): %s", d.Get("name").(string), err)
return sdkdiag.AppendErrorf(diags, "creating ECS Service (%s): %s", name, err)
}

d.SetId(aws.StringValue(output.Service.ServiceArn))

cluster := d.Get("cluster").(string)

fn := waitServiceActive
if d.Get("wait_for_steady_state").(bool) {
if _, err := waitServiceStable(ctx, conn, d.Id(), cluster, d.Timeout(schema.TimeoutCreate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for ECS service (%s) to reach steady state after creation: %s", d.Id(), err)
}
} else {
if _, err := waitServiceActive(ctx, conn, d.Id(), cluster, d.Timeout(schema.TimeoutCreate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for ECS service (%s) to become active after creation: %s", d.Id(), err)
}
fn = waitServiceStable
}
if _, err := fn(ctx, conn, d.Id(), d.Get("cluster").(string), d.Timeout(schema.TimeoutCreate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for ECS Service (%s) create: %s", d.Id(), err)
}

// Some partitions (i.e., ISO) may not support tag-on-create, attempt tag after create
Expand Down Expand Up @@ -732,19 +729,21 @@ func resourceServiceRead(ctx context.Context, d *schema.ResourceData, meta inter

if service.DeploymentConfiguration.DeploymentCircuitBreaker != nil {
if err := d.Set("deployment_circuit_breaker", []interface{}{flattenDeploymentCircuitBreaker(service.DeploymentConfiguration.DeploymentCircuitBreaker)}); err != nil {
return sdkdiag.AppendErrorf(diags, "setting deployment_circuit_break: %s", err)
return sdkdiag.AppendErrorf(diags, "setting deployment_circuit_breaker: %s", err)
}
} else {
d.Set("deployment_circuit_breaker", nil)
}
}

if err := d.Set("deployment_controller", flattenDeploymentController(service.DeploymentController)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting deployment_controller for (%s): %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "setting deployment_controller: %s", err)
}

if service.LoadBalancers != nil {
d.Set("load_balancer", flattenLoadBalancers(service.LoadBalancers))
if err := d.Set("load_balancer", flattenLoadBalancers(service.LoadBalancers)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting load_balancer: %s", err)
}
}

if err := d.Set("capacity_provider_strategy", flattenCapacityProviderStrategy(service.CapacityProviderStrategy)); err != nil {
Expand All @@ -756,19 +755,19 @@ func resourceServiceRead(ctx context.Context, d *schema.ResourceData, meta inter
}

if err := d.Set("placement_constraints", flattenServicePlacementConstraints(service.PlacementConstraints)); err != nil {
log.Printf("[ERR] Error setting placement_constraints for (%s): %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "setting placement_constraints: %s", err)
}

if err := d.Set("network_configuration", flattenNetworkConfiguration(service.NetworkConfiguration)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting network_configuration for (%s): %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "setting network_configuration: %s", err)
}

// if err := d.Set("service_connect_configuration", flattenServiceConnectConfiguration(service.ServiceConnectConfiguration)); err != nil {
// return fmt.Errorf("error setting service_connect_configuration for (%s): %w", d.Id(), err)
// }

if err := d.Set("service_registries", flattenServiceRegistries(service.ServiceRegistries)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting service_registries for (%s): %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "setting service_registries: %s", err)
}

SetTagsOut(ctx, service.Tags)
Expand Down Expand Up @@ -831,7 +830,7 @@ func resourceServiceUpdate(ctx context.Context, d *schema.ResourceData, meta int
ps, err := expandPlacementStrategy(v.([]interface{}))

if err != nil {
return sdkdiag.AppendErrorf(diags, "updating ECS Service (%s): %s", d.Get("name").(string), err)
return sdkdiag.AppendFromErr(diags, err)
}

input.PlacementStrategy = ps
Expand All @@ -847,7 +846,7 @@ func resourceServiceUpdate(ctx context.Context, d *schema.ResourceData, meta int
pc, err := expandPlacementConstraints(v.List())

if err != nil {
return sdkdiag.AppendErrorf(diags, "updating ECS Service (%s): %s", d.Get("name").(string), err)
return sdkdiag.AppendFromErr(diags, err)
}

input.PlacementConstraints = pc
Expand Down Expand Up @@ -932,15 +931,12 @@ func resourceServiceUpdate(ctx context.Context, d *schema.ResourceData, meta int
return sdkdiag.AppendErrorf(diags, "updating ECS Service (%s): %s", d.Id(), err)
}

cluster := d.Get("cluster").(string)
fn := waitServiceActive
if d.Get("wait_for_steady_state").(bool) {
if _, err := waitServiceStable(ctx, conn, d.Id(), cluster, d.Timeout(schema.TimeoutUpdate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for ECS service (%s) to reach steady state after update: %s", d.Id(), err)
}
} else {
if _, err := waitServiceActive(ctx, conn, d.Id(), cluster, d.Timeout(schema.TimeoutUpdate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for ECS service (%s) to become active after update: %s", d.Id(), err)
}
fn = waitServiceStable
}
if _, err := fn(ctx, conn, d.Id(), d.Get("cluster").(string), d.Timeout(schema.TimeoutUpdate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for ECS Service (%s) update: %s", d.Id(), err)
}
}

Expand All @@ -952,11 +948,13 @@ func resourceServiceDelete(ctx context.Context, d *schema.ResourceData, meta int
conn := meta.(*conns.AWSClient).ECSConn()

service, err := FindServiceNoTagsByID(ctx, conn, d.Id(), d.Get("cluster").(string))

if tfresource.NotFound(err) {
return diags
}

if err != nil {
return sdkdiag.AppendErrorf(diags, "retrieving ECS Service (%s) for deletion: %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "reading ECS Service (%s): %s", d.Id(), err)
}

if aws.StringValue(service.Status) == serviceStatusInactive {
Expand All @@ -965,22 +963,22 @@ func resourceServiceDelete(ctx context.Context, d *schema.ResourceData, meta int

// Drain the ECS service
if aws.StringValue(service.Status) != serviceStatusDraining && aws.StringValue(service.SchedulingStrategy) != ecs.SchedulingStrategyDaemon {
log.Printf("[DEBUG] Draining ECS Service (%s)", d.Id())
_, err = conn.UpdateServiceWithContext(ctx, &ecs.UpdateServiceInput{
_, err := conn.UpdateServiceWithContext(ctx, &ecs.UpdateServiceInput{
Service: aws.String(d.Id()),
Cluster: aws.String(d.Get("cluster").(string)),
DesiredCount: aws.Int64(0),
})

if err != nil {
return sdkdiag.AppendErrorf(diags, "deleting ECS Service (%s): draining service: %s", d.Get("name").(string), err)
return sdkdiag.AppendErrorf(diags, "draining ECS Service (%s): %s", d.Id(), err)
}
}

input := ecs.DeleteServiceInput{
Service: aws.String(d.Id()),
Cluster: aws.String(d.Get("cluster").(string)),
}
// Wait until the ECS service is drained
log.Printf("[DEBUG] Deleting ECS Service: %s", d.Id())
err = retry.RetryContext(ctx, d.Timeout(schema.TimeoutDelete), func() *retry.RetryError {
_, err := conn.DeleteServiceWithContext(ctx, &input)

Expand Down Expand Up @@ -1008,7 +1006,7 @@ func resourceServiceDelete(ctx context.Context, d *schema.ResourceData, meta int
}

if err := waitServiceInactive(ctx, conn, d.Id(), d.Get("cluster").(string), d.Timeout(schema.TimeoutDelete)); err != nil {
return sdkdiag.AppendErrorf(diags, "deleting ECS Service (%s): waiting for completion: %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "waiting for ECS Service (%s) delete: %s", d.Id(), err)
}

return diags
Expand Down
Loading