Skip to content

Commit b877634

Browse files
committed
ECS Express: add changelog and fix linting errors
1 parent f35443c commit b877634

File tree

5 files changed

+87
-88
lines changed

5 files changed

+87
-88
lines changed

internal/service/ecs/express_gateway_service.go

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"
1919
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
2020
"github.com/hashicorp/terraform-plugin-framework/attr"
21-
"github.com/hashicorp/terraform-plugin-framework/path"
2221
"github.com/hashicorp/terraform-plugin-framework/resource"
2322
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
2423
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
@@ -28,7 +27,6 @@ import (
2827
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
2928
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
3029
"github.com/hashicorp/terraform-plugin-framework/types"
31-
3230
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
3331
"github.com/hashicorp/terraform-provider-aws/internal/enum"
3432
"github.com/hashicorp/terraform-provider-aws/internal/errs"
@@ -61,6 +59,7 @@ const (
6159
type resourceExpressGatewayService struct {
6260
framework.ResourceWithModel[resourceExpressGatewayServiceModel]
6361
framework.WithTimeouts
62+
framework.WithImportByID
6463
}
6564

6665
func (r *resourceExpressGatewayService) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
@@ -71,18 +70,18 @@ func (r *resourceExpressGatewayService) Schema(ctx context.Context, req resource
7170
Computed: true,
7271
ElementType: types.ObjectType{
7372
AttrTypes: map[string]attr.Type{
74-
"service_revision_arn": types.StringType,
75-
"execution_role_arn": types.StringType,
76-
"task_role_arn": types.StringType,
77-
"cpu": types.StringType,
78-
"memory": types.StringType,
79-
"health_check_path": types.StringType,
80-
"created_at": types.StringType,
81-
"network_configuration": types.ListType{
73+
"service_revision_arn": types.StringType,
74+
names.AttrExecutionRoleARN: types.StringType,
75+
"task_role_arn": types.StringType,
76+
"cpu": types.StringType,
77+
"memory": types.StringType,
78+
"health_check_path": types.StringType,
79+
names.AttrCreatedAt: types.StringType,
80+
names.AttrNetworkConfiguration: types.ListType{
8281
ElemType: types.ObjectType{
8382
AttrTypes: map[string]attr.Type{
84-
"security_groups": types.SetType{ElemType: types.StringType},
85-
"subnets": types.SetType{ElemType: types.StringType},
83+
names.AttrSecurityGroups: types.SetType{ElemType: types.StringType},
84+
names.AttrSubnets: types.SetType{ElemType: types.StringType},
8685
},
8786
},
8887
},
@@ -107,8 +106,8 @@ func (r *resourceExpressGatewayService) Schema(ctx context.Context, req resource
107106
"ingress_paths": types.ListType{
108107
ElemType: types.ObjectType{
109108
AttrTypes: map[string]attr.Type{
110-
"access_type": types.StringType,
111-
"endpoint": types.StringType,
109+
"access_type": types.StringType,
110+
names.AttrEndpoint: types.StringType,
112111
},
113112
},
114113
},
@@ -125,7 +124,7 @@ func (r *resourceExpressGatewayService) Schema(ctx context.Context, req resource
125124
"cpu": schema.StringAttribute{
126125
Optional: true,
127126
},
128-
"created_at": schema.StringAttribute{
127+
names.AttrCreatedAt: schema.StringAttribute{
129128
CustomType: timetypes.RFC3339Type{},
130129
Computed: true,
131130
PlanModifiers: []planmodifier.String{
@@ -139,7 +138,7 @@ func (r *resourceExpressGatewayService) Schema(ctx context.Context, req resource
139138
},
140139
},
141140

142-
"execution_role_arn": schema.StringAttribute{
141+
names.AttrExecutionRoleARN: schema.StringAttribute{
143142
Required: true,
144143
},
145144
"health_check_path": schema.StringAttribute{
@@ -155,7 +154,7 @@ func (r *resourceExpressGatewayService) Schema(ctx context.Context, req resource
155154
"memory": schema.StringAttribute{
156155
Optional: true,
157156
},
158-
names.AttrServiceARN: framework.ARNAttributeComputedOnly(),
157+
"service_arn": framework.ARNAttributeComputedOnly(),
159158
names.AttrServiceName: schema.StringAttribute{
160159
Optional: true,
161160
Computed: true,
@@ -164,16 +163,16 @@ func (r *resourceExpressGatewayService) Schema(ctx context.Context, req resource
164163
stringplanmodifier.RequiresReplace(),
165164
},
166165
},
167-
"status": schema.ListAttribute{
166+
names.AttrStatus: schema.ListAttribute{
168167
CustomType: fwtypes.NewListNestedObjectTypeOf[statusModel](ctx),
169168
Computed: true,
170169
PlanModifiers: []planmodifier.List{
171170
listplanmodifier.UseStateForUnknown(),
172171
},
173172
ElementType: types.ObjectType{
174173
AttrTypes: map[string]attr.Type{
175-
"status_code": types.StringType,
176-
"status_reason": types.StringType,
174+
names.AttrStatusCode: types.StringType,
175+
names.AttrStatusReason: types.StringType,
177176
},
178177
},
179178
},
@@ -196,7 +195,7 @@ func (r *resourceExpressGatewayService) Schema(ctx context.Context, req resource
196195
},
197196
},
198197
Blocks: map[string]schema.Block{
199-
"network_configuration": schema.ListNestedBlock{
198+
names.AttrNetworkConfiguration: schema.ListNestedBlock{
200199
CustomType: fwtypes.NewListNestedObjectTypeOf[networkConfigurationModel](ctx),
201200
Validators: []validator.List{
202201
listvalidator.SizeAtMost(1),
@@ -261,7 +260,7 @@ func (r *resourceExpressGatewayService) Schema(ctx context.Context, req resource
261260
},
262261
},
263262
},
264-
"environment": schema.ListNestedBlock{
263+
names.AttrEnvironment: schema.ListNestedBlock{
265264
CustomType: fwtypes.NewListNestedObjectTypeOf[environmentModel](ctx),
266265
NestedObject: schema.NestedBlockObject{
267266
Attributes: map[string]schema.Attribute{
@@ -344,7 +343,7 @@ func (r *resourceExpressGatewayService) Create(ctx context.Context, req resource
344343
conn := r.Meta().ECSClient(ctx)
345344

346345
var plan resourceExpressGatewayServiceModel
347-
smerr.EnrichAppend(ctx, &resp.Diagnostics, req.Plan.Get(ctx, &plan))
346+
smerr.AddEnrich(ctx, &resp.Diagnostics, req.Plan.Get(ctx, &plan))
348347
if resp.Diagnostics.HasError() {
349348
return
350349
}
@@ -355,7 +354,7 @@ func (r *resourceExpressGatewayService) Create(ctx context.Context, req resource
355354
}
356355

357356
var input ecs.CreateExpressGatewayServiceInput
358-
smerr.EnrichAppend(ctx, &resp.Diagnostics, flex.Expand(ctx, plan, &input))
357+
smerr.AddEnrich(ctx, &resp.Diagnostics, flex.Expand(ctx, plan, &input))
359358
if resp.Diagnostics.HasError() {
360359
return
361360
}
@@ -382,7 +381,7 @@ func (r *resourceExpressGatewayService) Create(ctx context.Context, req resource
382381
var waitOut *awstypes.ECSExpressGatewayService
383382

384383
if plan.WaitForSteadyState.ValueBool() {
385-
waitOut, err = waitExpressGatewayServiceStable(ctx, conn, *out.Service.ServiceArn, *out.Service.Cluster, operationTime, createTimeout)
384+
waitOut, err = waitExpressGatewayServiceStable(ctx, conn, *out.Service.ServiceArn, operationTime, createTimeout)
386385
} else {
387386
waitOut, err = waitExpressGatewayServiceActive(ctx, conn, plan.ServiceArn.ValueString(), createTimeout)
388387
}
@@ -391,7 +390,7 @@ func (r *resourceExpressGatewayService) Create(ctx context.Context, req resource
391390
return
392391
}
393392

394-
smerr.EnrichAppend(ctx, &resp.Diagnostics, flex.Flatten(ctx, waitOut.ActiveConfigurations, &plan.ActiveConfigurations))
393+
smerr.AddEnrich(ctx, &resp.Diagnostics, flex.Flatten(ctx, waitOut.ActiveConfigurations, &plan.ActiveConfigurations))
395394

396395
// Set Optional+Computed attributes from API response
397396
if waitOut.Cluster != nil {
@@ -424,17 +423,17 @@ func (r *resourceExpressGatewayService) Create(ctx context.Context, req resource
424423
}
425424

426425
if waitOut.Status != nil {
427-
smerr.EnrichAppend(ctx, &resp.Diagnostics, flex.Flatten(ctx, []awstypes.ExpressGatewayServiceStatus{*waitOut.Status}, &plan.Status))
426+
smerr.AddEnrich(ctx, &resp.Diagnostics, flex.Flatten(ctx, []awstypes.ExpressGatewayServiceStatus{*waitOut.Status}, &plan.Status))
428427
}
429428

430-
smerr.EnrichAppend(ctx, &resp.Diagnostics, resp.State.Set(ctx, plan))
429+
smerr.AddEnrich(ctx, &resp.Diagnostics, resp.State.Set(ctx, plan))
431430
}
432431

433432
func (r *resourceExpressGatewayService) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
434433
conn := r.Meta().ECSClient(ctx)
435434

436435
var state resourceExpressGatewayServiceModel
437-
smerr.EnrichAppend(ctx, &resp.Diagnostics, req.State.Get(ctx, &state))
436+
smerr.AddEnrich(ctx, &resp.Diagnostics, req.State.Get(ctx, &state))
438437
if resp.Diagnostics.HasError() {
439438
return
440439
}
@@ -463,7 +462,7 @@ func (r *resourceExpressGatewayService) Read(ctx context.Context, req resource.R
463462
state.ID = flex.StringToFramework(ctx, out.ServiceArn)
464463

465464
if len(out.ActiveConfigurations) > 0 {
466-
smerr.EnrichAppend(ctx, &resp.Diagnostics, flex.Flatten(ctx, out.ActiveConfigurations, &state.ActiveConfigurations))
465+
smerr.AddEnrich(ctx, &resp.Diagnostics, flex.Flatten(ctx, out.ActiveConfigurations, &state.ActiveConfigurations))
467466
}
468467

469468
if out.CreatedAt != nil {
@@ -508,28 +507,28 @@ func (r *resourceExpressGatewayService) Read(ctx context.Context, req resource.R
508507
}
509508

510509
if out.Status != nil {
511-
smerr.EnrichAppend(ctx, &resp.Diagnostics, flex.Flatten(ctx, []awstypes.ExpressGatewayServiceStatus{*out.Status}, &state.Status))
510+
smerr.AddEnrich(ctx, &resp.Diagnostics, flex.Flatten(ctx, []awstypes.ExpressGatewayServiceStatus{*out.Status}, &state.Status))
512511
}
513512

514513
setTagsOut(ctx, out.Tags)
515514

516-
smerr.EnrichAppend(ctx, &resp.Diagnostics, resp.State.Set(ctx, &state))
515+
smerr.AddEnrich(ctx, &resp.Diagnostics, resp.State.Set(ctx, &state))
517516
}
518517

519518
func (r *resourceExpressGatewayService) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
520519
conn := r.Meta().ECSClient(ctx)
521520

522521
var plan, state resourceExpressGatewayServiceModel
523-
smerr.EnrichAppend(ctx, &resp.Diagnostics, req.Plan.Get(ctx, &plan))
524-
smerr.EnrichAppend(ctx, &resp.Diagnostics, req.State.Get(ctx, &state))
522+
smerr.AddEnrich(ctx, &resp.Diagnostics, req.Plan.Get(ctx, &plan))
523+
smerr.AddEnrich(ctx, &resp.Diagnostics, req.State.Get(ctx, &state))
525524
if resp.Diagnostics.HasError() {
526525
return
527526
}
528527

529528
diff, d := flex.Diff(ctx, plan, state, flex.WithIgnoredField("active_configurations"), flex.WithIgnoredField("current_deployment"),
530529
flex.WithIgnoredField("scaling_target"), flex.WithIgnoredField(names.AttrTags), flex.WithIgnoredField(names.AttrTags),
531530
flex.WithIgnoredField(names.AttrTagsAll))
532-
smerr.EnrichAppend(ctx, &resp.Diagnostics, d)
531+
smerr.AddEnrich(ctx, &resp.Diagnostics, d)
533532
if resp.Diagnostics.HasError() {
534533
return
535534
}
@@ -543,7 +542,7 @@ func (r *resourceExpressGatewayService) Update(ctx context.Context, req resource
543542
// ServiceArn is required for the update operation
544543
input.ServiceArn = plan.ServiceArn.ValueStringPointer()
545544

546-
smerr.EnrichAppend(ctx, &resp.Diagnostics, flex.Expand(ctx, plan, &input))
545+
smerr.AddEnrich(ctx, &resp.Diagnostics, flex.Expand(ctx, plan, &input))
547546
if resp.Diagnostics.HasError() {
548547
return
549548
}
@@ -560,15 +559,15 @@ func (r *resourceExpressGatewayService) Update(ctx context.Context, req resource
560559
return
561560
}
562561

563-
smerr.EnrichAppend(ctx, &resp.Diagnostics, flex.Flatten(ctx, out, &plan))
562+
smerr.AddEnrich(ctx, &resp.Diagnostics, flex.Flatten(ctx, out, &plan))
564563
if resp.Diagnostics.HasError() {
565564
return
566565
}
567566

568567
updateTimeout := r.UpdateTimeout(ctx, plan.Timeouts)
569568

570569
if plan.WaitForSteadyState.ValueBool() {
571-
waitOut, err = waitExpressGatewayServiceStable(ctx, conn, plan.ServiceArn.ValueString(), plan.Cluster.ValueString(), operationTime, updateTimeout)
570+
waitOut, err = waitExpressGatewayServiceStable(ctx, conn, plan.ServiceArn.ValueString(), operationTime, updateTimeout)
572571
} else {
573572
waitOut, err = waitExpressGatewayServiceActive(ctx, conn, plan.ServiceArn.ValueString(), updateTimeout)
574573
}
@@ -587,7 +586,7 @@ func (r *resourceExpressGatewayService) Update(ctx context.Context, req resource
587586
}
588587

589588
// Set Computed attributes from updated service state
590-
smerr.EnrichAppend(ctx, &resp.Diagnostics, flex.Flatten(ctx, waitOut.ActiveConfigurations, &plan.ActiveConfigurations))
589+
smerr.AddEnrich(ctx, &resp.Diagnostics, flex.Flatten(ctx, waitOut.ActiveConfigurations, &plan.ActiveConfigurations))
591590
if waitOut.CreatedAt != nil {
592591
plan.CreatedAt = timetypes.NewRFC3339TimeValue(*waitOut.CreatedAt)
593592
}
@@ -617,17 +616,17 @@ func (r *resourceExpressGatewayService) Update(ctx context.Context, req resource
617616
}
618617

619618
if waitOut.Status != nil {
620-
smerr.EnrichAppend(ctx, &resp.Diagnostics, flex.Flatten(ctx, []awstypes.ExpressGatewayServiceStatus{*waitOut.Status}, &plan.Status))
619+
smerr.AddEnrich(ctx, &resp.Diagnostics, flex.Flatten(ctx, []awstypes.ExpressGatewayServiceStatus{*waitOut.Status}, &plan.Status))
621620
}
622621

623-
smerr.EnrichAppend(ctx, &resp.Diagnostics, resp.State.Set(ctx, &plan))
622+
smerr.AddEnrich(ctx, &resp.Diagnostics, resp.State.Set(ctx, &plan))
624623
}
625624

626625
func (r *resourceExpressGatewayService) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
627626
conn := r.Meta().ECSClient(ctx)
628627

629628
var state resourceExpressGatewayServiceModel
630-
smerr.EnrichAppend(ctx, &resp.Diagnostics, req.State.Get(ctx, &state))
629+
smerr.AddEnrich(ctx, &resp.Diagnostics, req.State.Get(ctx, &state))
631630
if resp.Diagnostics.HasError() {
632631
return
633632
}
@@ -666,10 +665,6 @@ func (r *resourceExpressGatewayService) Delete(ctx context.Context, req resource
666665
}
667666
}
668667

669-
func (r *resourceExpressGatewayService) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
670-
resource.ImportStatePassthroughID(ctx, path.Root(names.AttrID), req, resp)
671-
}
672-
673668
const (
674669
gatewayServiceStatusActive = string(awstypes.ExpressGatewayServiceStatusCodeActive)
675670
gatewayServiceStatusDraining = string(awstypes.ExpressGatewayServiceStatusCodeDraining)
@@ -696,11 +691,11 @@ func waitExpressGatewayServiceActive(ctx context.Context, conn *ecs.Client, ARN
696691
return nil, smarterr.NewError(err)
697692
}
698693

699-
func waitExpressGatewayServiceStable(ctx context.Context, conn *ecs.Client, gatewayServiceARN, clusterNameOrARN string, operationTime time.Time, timeout time.Duration) (*awstypes.ECSExpressGatewayService, error) { //nolint:unparam
694+
func waitExpressGatewayServiceStable(ctx context.Context, conn *ecs.Client, gatewayServiceARN string, operationTime time.Time, timeout time.Duration) (*awstypes.ECSExpressGatewayService, error) {
700695
stateConf := &retry.StateChangeConf{
701696
Pending: []string{gatewayServiceStatusInactive, gatewayServiceStatusDraining, gatewayServiceStatusPending},
702697
Target: []string{gatewayServiceStatusActive, gatewayServiceStatusStable},
703-
Refresh: statusExpressGatewayServiceWaitForStable(ctx, conn, gatewayServiceARN, clusterNameOrARN, operationTime),
698+
Refresh: statusExpressGatewayServiceWaitForStable(ctx, conn, gatewayServiceARN, operationTime),
704699
Timeout: timeout,
705700
}
706701

@@ -842,7 +837,7 @@ func checkExpressGatewayServiceExists(ctx context.Context, conn *ecs.Client, ser
842837
return err
843838
}
844839

845-
func statusExpressGatewayServiceWaitForStable(ctx context.Context, conn *ecs.Client, gatewayServiceARN, clusterNameOrARN string, operationTime time.Time) retry.StateRefreshFunc {
840+
func statusExpressGatewayServiceWaitForStable(ctx context.Context, conn *ecs.Client, gatewayServiceARN string, operationTime time.Time) retry.StateRefreshFunc {
846841
var deploymentArn *string
847842

848843
return func() (any, string, error) {

0 commit comments

Comments
 (0)