diff --git a/go.mod b/go.mod index 3995096cec11..ca0db8e49806 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c github.com/YakDriver/regexache v0.23.0 github.com/aws/aws-sdk-go v1.47.0 - github.com/aws/aws-sdk-go-v2 v1.22.0 + github.com/aws/aws-sdk-go-v2 v1.23.2 github.com/aws/aws-sdk-go-v2/config v1.20.0 github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.0 github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.12.0 @@ -16,6 +16,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/appconfig v1.24.0 github.com/aws/aws-sdk-go-v2/service/athena v1.33.0 github.com/aws/aws-sdk-go-v2/service/auditmanager v1.28.0 + github.com/aws/aws-sdk-go-v2/service/batch v1.29.5 github.com/aws/aws-sdk-go-v2/service/cleanrooms v1.5.0 github.com/aws/aws-sdk-go-v2/service/cloudcontrol v1.13.0 github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.25.0 @@ -124,8 +125,8 @@ require ( github.com/armon/go-radix v1.0.0 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.0 // indirect github.com/aws/aws-sdk-go-v2/credentials v1.14.0 // indirect - github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.0 // indirect - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.0 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.5 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.5 // indirect github.com/aws/aws-sdk-go-v2/internal/ini v1.4.0 // indirect github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.0 // indirect github.com/aws/aws-sdk-go-v2/service/dynamodb v1.23.0 // indirect @@ -138,7 +139,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/sso v1.16.0 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.18.0 // indirect github.com/aws/aws-sdk-go-v2/service/sts v1.24.0 // indirect - github.com/aws/smithy-go v1.16.0 // indirect + github.com/aws/smithy-go v1.17.0 // indirect github.com/bgentry/speakeasy v0.1.0 // indirect github.com/boombuler/barcode v1.0.1 // indirect github.com/bufbuild/protocompile v0.6.0 // indirect diff --git a/go.sum b/go.sum index 2753300f7ed5..c0b7cf29f9f8 100644 --- a/go.sum +++ b/go.sum @@ -25,8 +25,8 @@ github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgI github.com/aws/aws-sdk-go v1.47.0 h1:/JUg9V1+xh+qBn8A6ec/l15ETPaMaBqxkjz+gg63dNk= github.com/aws/aws-sdk-go v1.47.0/go.mod h1:DlEaEbWKZmsITVbqlSVvekPARM1HzeV9PMYg15ymSDA= github.com/aws/aws-sdk-go-v2 v1.21.2/go.mod h1:ErQhvNuEMhJjweavOYhxVkn2RUx7kQXVATHrjKtxIpM= -github.com/aws/aws-sdk-go-v2 v1.22.0 h1:CpTS3XO3MWNel8ohoazkLZC6scvkYL2k+m0yzFJ17Hg= -github.com/aws/aws-sdk-go-v2 v1.22.0/go.mod h1:Kd0OJtkW3Q0M0lUWGszapWjEvrXDzRW+D21JNsroB+c= +github.com/aws/aws-sdk-go-v2 v1.23.2 h1:UoTll1Y5b88x8h53OlsJGgOHwpggdMr7UVnLjMb3XYg= +github.com/aws/aws-sdk-go-v2 v1.23.2/go.mod h1:i1XDttT4rnf6vxc9AuskLc6s7XBee8rlLilKlc03uAA= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.0 h1:hHgLiIrTRtddC0AKcJr5s7i/hLgcpTt+q/FKxf1Zayk= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.0/go.mod h1:w4I/v3NOWgD+qvs1NPEwhd++1h3XPHFaVxasfY6HlYQ= github.com/aws/aws-sdk-go-v2/config v1.20.0 h1:q2+/mqFhY0J9m3Tb5RGFE3R4sdaUkIe4k2EuDfE3c08= @@ -38,11 +38,11 @@ github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.0/go.mod h1:c28nJNzMVVb9TQpZ github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.12.0 h1:IJ1PN7TqW79Dmc0hSSd+clznCToXmN8gtWQO1hOxFbE= github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.12.0/go.mod h1:Y0Ksox8/7Bl2UTwxdxWQ0JfRQi4sMv48F8Iy4ueS/Dc= github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43/go.mod h1:auo+PiyLl0n1l8A0e8RIeR8tOzYPfZZH/JNlrJ8igTQ= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.0 h1:tN6dNNE4SzMuyMnVtQJXGVKX177/d5Zy4MuA1HA4KUc= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.0/go.mod h1:F6MXWETIeetAHwFHyoHEqrcB3NpijFv9nLP5h9CXtT0= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.5 h1:16Z1XuMUv63fcyW5bIUno6AFcX4drsrE0gof+xue6g4= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.5/go.mod h1:pRvFacV2qbRKy34ZFptHZW4wpauJA445bqFbvA6ikSo= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37/go.mod h1:Qe+2KtKml+FEsQF/DHmDV+xjtche/hwoF75EG4UlHW8= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.0 h1:bfdsbTARDjaC/dSYGMO+E0psxFU4hTvCLnqYAfZ3D38= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.0/go.mod h1:Jg8XVv5M2V2wiAMvBFx+O59jg6Yr8vhP0bgNF/IuquM= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.5 h1:RxpMuBgzP3Dj1n5CZY6droLFcsn5gc7QsrIcaGQoeCs= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.5/go.mod h1:dO8Js7ym4Jzg/wcjTgCRVln/jFn3nI82XNhsG2lWbDI= github.com/aws/aws-sdk-go-v2/internal/ini v1.4.0 h1:21tlTXq3ev10yLMAjXZzpkZbrl49h3ElSjmxD57tD/E= github.com/aws/aws-sdk-go-v2/internal/ini v1.4.0/go.mod h1:d9YrBHJhyzDCv5UsEVRizHlFV6Q0sLemFq6uxuqWfUw= github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.0 h1:NpsAO1LaZyc72xMoQB/qgcOwI9Ag1d5FvaEp+omzFqg= @@ -59,6 +59,8 @@ github.com/aws/aws-sdk-go-v2/service/athena v1.33.0 h1:xFUnzjoPtDGTKwKkIQTb155XN github.com/aws/aws-sdk-go-v2/service/athena v1.33.0/go.mod h1:oTGe2oUbm/Gj3uDRcSM3O14t0eDXByI/qQUztvqsOG4= github.com/aws/aws-sdk-go-v2/service/auditmanager v1.28.0 h1:MxGObspDXcw+1NJECK3ObQhSWT4AM+F9cqfJzoHHOZg= github.com/aws/aws-sdk-go-v2/service/auditmanager v1.28.0/go.mod h1:liyqvkb5u86yzBey9YeUatKQB7kN4ks3QH/K+YqMDgM= +github.com/aws/aws-sdk-go-v2/service/batch v1.29.5 h1:Ip5rljKGnSjEu5ThcWtUUWXFrLrLUavsPFUaCVZ+r3A= +github.com/aws/aws-sdk-go-v2/service/batch v1.29.5/go.mod h1:irQFkjkvKCzJxdz8XGJ5QSdfisjUHwkcq5m4zNl76cA= github.com/aws/aws-sdk-go-v2/service/cleanrooms v1.5.0 h1:6gHJBaPeZcAEbprX+1sGaBd4qXJ2QK5RedRkF4u8uNA= github.com/aws/aws-sdk-go-v2/service/cleanrooms v1.5.0/go.mod h1:GZUDl13Gh1RxQ3Id7zGZRbaruI+d5s29hVS4g2XqPl8= github.com/aws/aws-sdk-go-v2/service/cloudcontrol v1.13.0 h1:/GppYyDIhFwWIBNBe/eDnj5TUTvWrYuhFoPeRp2rMdc= @@ -202,8 +204,8 @@ github.com/aws/aws-sdk-go-v2/service/workspaces v1.32.0/go.mod h1:94kY9vDWsnNND6 github.com/aws/aws-sdk-go-v2/service/xray v1.21.0 h1:jtO3lzCaQ0kTGA+1C+EkJy5095xhUUjt5AX8FDnCIrY= github.com/aws/aws-sdk-go-v2/service/xray v1.21.0/go.mod h1:KXFGYPgDR+QY7GjzjP02lU+bmeELByZYgkRmC1RSxF4= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= -github.com/aws/smithy-go v1.16.0 h1:gJZEH/Fqh+RsvlJ1Zt4tVAtV6bKkp3cC+R6FCZMNzik= -github.com/aws/smithy-go v1.16.0/go.mod h1:NukqUGpCZIILqqiV0NIjeFh24kd/FAa4beRb6nbIUPE= +github.com/aws/smithy-go v1.17.0 h1:wWJD7LX6PBV6etBUwO0zElG0nWN9rUhp0WdYeHSHAaI= +github.com/aws/smithy-go v1.17.0/go.mod h1:NukqUGpCZIILqqiV0NIjeFh24kd/FAa4beRb6nbIUPE= github.com/beevik/etree v1.2.0 h1:l7WETslUG/T+xOPs47dtd6jov2Ii/8/OjCldk5fYfQw= github.com/beevik/etree v1.2.0/go.mod h1:aiPf89g/1k3AShMVAzriilpcE4R/Vuor90y83zVZWFc= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= diff --git a/internal/service/batch/job_queue.go b/internal/service/batch/job_queue.go index 504a6f5ac3d2..23efaf93749b 100644 --- a/internal/service/batch/job_queue.go +++ b/internal/service/batch/job_queue.go @@ -13,7 +13,9 @@ import ( "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go/service/batch" + "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" + "github.com/hashicorp/terraform-plugin-framework-validators/resourcevalidator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" @@ -55,6 +57,16 @@ type resourceJobQueue struct { framework.WithTimeouts } +func (r *resourceJobQueue) ConfigValidators(_ context.Context) []resource.ConfigValidator { + return []resource.ConfigValidator{ + // ExactlyOneOf is better? + resourcevalidator.Conflicting( + path.MatchRoot("compute_environments"), + path.MatchRoot("compute_environment_order"), + ), + } +} + func (r *resourceJobQueue) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) { response.TypeName = "aws_batch_job_queue" } @@ -65,8 +77,9 @@ func (r *resourceJobQueue) Schema(ctx context.Context, request resource.SchemaRe Attributes: map[string]schema.Attribute{ "arn": framework.ARNAttributeComputedOnly(), "compute_environments": schema.ListAttribute{ - ElementType: fwtypes.ARNType, - Required: true, + ElementType: fwtypes.ARNType, + Optional: true, + DeprecationMessage: "This parameter will be replaced by `compute_environments_order`.", }, "id": framework.IDAttribute(), "name": schema.StringAttribute{ @@ -106,6 +119,20 @@ func (r *resourceJobQueue) Schema(ctx context.Context, request resource.SchemaRe Update: true, Delete: true, }), + "compute_environment_order": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[computeEnvironmentOrder](ctx), + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "order": schema.Int64Attribute{ + Required: true, + }, + "compute_environment": schema.StringAttribute{ + // CustomType: fwtypes.ARNType, + Required: true, + }, + }, + }, + }, } response.Schema = s @@ -121,16 +148,27 @@ func (r *resourceJobQueue) Create(ctx context.Context, request resource.CreateRe return } - ceo := flex.ExpandFrameworkStringValueList(ctx, data.ComputeEnvironments) - input := batch.CreateJobQueueInput{ - ComputeEnvironmentOrder: expandComputeEnvironmentOrder(ceo), - JobQueueName: flex.StringFromFramework(ctx, data.Name), - Priority: flex.Int64FromFramework(ctx, data.Priority), - State: flex.StringFromFramework(ctx, data.State), - Tags: getTagsIn(ctx), + // ComputeEnvironmentOrder: expandComputeEnvironments(ceo), + JobQueueName: flex.StringFromFramework(ctx, data.JobQueueName), + Priority: flex.Int64FromFramework(ctx, data.Priority), + State: flex.StringFromFramework(ctx, data.State), + Tags: getTagsIn(ctx), + } + + if !data.ComputeEnvironmentOrder.IsNull() { + // c := flex.ExpandFrameworkListNestedBlockPtr(ctx, data.ComputeEnvironmentOrder, r.expandComputeEnvironmentOrder) + // input.ComputeEnvironmentOrder = nil + flex.Expand(ctx, data.ComputeEnvironmentOrder, func(i int, v interface{}) { + ceo := v.(computeEnvironmentOrder) + input.ComputeEnvironmentOrder = append(input.ComputeEnvironmentOrder, &batch.ComputeEnvironmentOrder{ + Order: flex.Int64FromFramework(ctx, ceo.Order), + ComputeEnvironment: flex.StringFromFramework(ctx, ceo.ComputeEnvironment), + }) + }, nil) + } else { + input.ComputeEnvironmentOrder = expandComputeEnvironments(flex.ExpandFrameworkStringValueList(ctx, data.ComputeEnvironments)) } - if !data.SchedulingPolicyARN.IsNull() { input.SchedulingPolicyArn = flex.StringFromFramework(ctx, data.SchedulingPolicyARN) } @@ -139,7 +177,7 @@ func (r *resourceJobQueue) Create(ctx context.Context, request resource.CreateRe if err != nil { response.Diagnostics.AddError( - create.ProblemStandardMessage(names.Batch, create.ErrActionCreating, ResNameJobQueue, data.Name.ValueString(), nil), + create.ProblemStandardMessage(names.Batch, create.ErrActionCreating, ResNameJobQueue, data.JobQueueName.ValueString(), nil), err.Error(), ) return @@ -149,16 +187,21 @@ func (r *resourceJobQueue) Create(ctx context.Context, request resource.CreateRe state.ID = flex.StringToFramework(ctx, output.JobQueueArn) createTimeout := r.CreateTimeout(ctx, data.Timeouts) - out, err := waitJobQueueCreated(ctx, conn, data.Name.ValueString(), createTimeout) + out, err := waitJobQueueCreated(ctx, conn, data.JobQueueName.ValueString(), createTimeout) if err != nil { response.Diagnostics.AddError( - create.ProblemStandardMessage(names.Batch, create.ErrActionWaitingForCreation, ResNameJobQueue, data.Name.ValueString(), nil), + create.ProblemStandardMessage(names.Batch, create.ErrActionWaitingForCreation, ResNameJobQueue, data.JobQueueName.ValueString(), nil), err.Error(), ) return } + if !data.ComputeEnvironmentOrder.IsNull() { + flex.Flatten(ctx, out.ComputeEnvironmentOrder, &data.ComputeEnvironmentOrder) + } else { + state.ComputeEnvironments = flex.FlattenFrameworkStringValueListLegacy(ctx, flattenComputeEnvironmentOrder(out.ComputeEnvironmentOrder)) + } response.Diagnostics.Append(state.refreshFromOutput(ctx, out)...) response.Diagnostics.Append(response.State.Set(ctx, &state)...) } @@ -177,7 +220,7 @@ func (r *resourceJobQueue) Read(ctx context.Context, request resource.ReadReques if err != nil { response.Diagnostics.AddError( - create.ProblemStandardMessage(names.Batch, create.ErrActionUpdating, ResNameJobQueue, data.Name.ValueString(), err), + create.ProblemStandardMessage(names.Batch, create.ErrActionUpdating, ResNameJobQueue, data.JobQueueName.ValueString(), err), err.Error(), ) return @@ -189,6 +232,11 @@ func (r *resourceJobQueue) Read(ctx context.Context, request resource.ReadReques return } + if !data.ComputeEnvironmentOrder.IsNull() { + flex.Flatten(ctx, out.ComputeEnvironmentOrder, &data.ComputeEnvironmentOrder) + } else { + data.ComputeEnvironments = flex.FlattenFrameworkStringValueListLegacy(ctx, flattenComputeEnvironmentOrder(out.ComputeEnvironmentOrder)) + } response.Diagnostics.Append(data.refreshFromOutput(ctx, out)...) response.Diagnostics.Append(response.State.Set(ctx, &data)...) } @@ -206,12 +254,12 @@ func (r *resourceJobQueue) Update(ctx context.Context, request resource.UpdateRe var update bool input := &batch.UpdateJobQueueInput{ - JobQueue: flex.StringFromFramework(ctx, plan.Name), + JobQueue: flex.StringFromFramework(ctx, plan.JobQueueName), } if !plan.ComputeEnvironments.Equal(state.ComputeEnvironments) { ceo := flex.ExpandFrameworkStringValueList(ctx, plan.ComputeEnvironments) - input.ComputeEnvironmentOrder = expandComputeEnvironmentOrder(ceo) + input.ComputeEnvironmentOrder = expandComputeEnvironments(ceo) update = true } @@ -252,7 +300,7 @@ func (r *resourceJobQueue) Update(ctx context.Context, request resource.UpdateRe if err != nil { response.Diagnostics.AddError( - create.ProblemStandardMessage(names.Batch, create.ErrActionUpdating, ResNameJobQueue, plan.Name.ValueString(), nil), + create.ProblemStandardMessage(names.Batch, create.ErrActionUpdating, ResNameJobQueue, plan.JobQueueName.ValueString(), nil), err.Error(), ) return @@ -263,7 +311,7 @@ func (r *resourceJobQueue) Update(ctx context.Context, request resource.UpdateRe if err != nil { response.Diagnostics.AddError( - create.ProblemStandardMessage(names.Batch, create.ErrActionWaitingForCreation, ResNameJobQueue, plan.Name.ValueString(), nil), + create.ProblemStandardMessage(names.Batch, create.ErrActionWaitingForCreation, ResNameJobQueue, plan.JobQueueName.ValueString(), nil), err.Error(), ) return @@ -290,7 +338,7 @@ func (r *resourceJobQueue) Delete(ctx context.Context, request resource.DeleteRe if err != nil { response.Diagnostics.AddError( - create.ProblemStandardMessage(names.Batch, create.ErrActionDeleting, ResNameJobQueue, data.Name.ValueString(), nil), + create.ProblemStandardMessage(names.Batch, create.ErrActionDeleting, ResNameJobQueue, data.JobQueueName.ValueString(), nil), err.Error(), ) return @@ -302,7 +350,7 @@ func (r *resourceJobQueue) Delete(ctx context.Context, request resource.DeleteRe if err != nil { response.Diagnostics.AddError( - create.ProblemStandardMessage(names.Batch, create.ErrActionDeleting, ResNameJobQueue, data.Name.ValueString(), nil), + create.ProblemStandardMessage(names.Batch, create.ErrActionDeleting, ResNameJobQueue, data.JobQueueName.ValueString(), nil), err.Error(), ) return @@ -312,7 +360,7 @@ func (r *resourceJobQueue) Delete(ctx context.Context, request resource.DeleteRe if err != nil { response.Diagnostics.AddError( - create.ProblemStandardMessage(names.Batch, create.ErrActionWaitingForDeletion, ResNameJobQueue, data.Name.ValueString(), nil), + create.ProblemStandardMessage(names.Batch, create.ErrActionWaitingForDeletion, ResNameJobQueue, data.JobQueueName.ValueString(), nil), err.Error(), ) return @@ -339,24 +387,29 @@ func (r *resourceJobQueue) UpgradeState(ctx context.Context) map[int64]resource. } type resourceJobQueueData struct { - ARN types.String `tfsdk:"arn"` - ComputeEnvironments types.List `tfsdk:"compute_environments"` - ID types.String `tfsdk:"id"` - Name types.String `tfsdk:"name"` - Priority types.Int64 `tfsdk:"priority"` - SchedulingPolicyARN fwtypes.ARN `tfsdk:"scheduling_policy_arn"` - State types.String `tfsdk:"state"` - Tags types.Map `tfsdk:"tags"` - TagsAll types.Map `tfsdk:"tags_all"` - Timeouts timeouts.Value `tfsdk:"timeouts"` + ARN types.String `tfsdk:"arn"` + ComputeEnvironments types.List `tfsdk:"compute_environments"` + ComputeEnvironmentOrder fwtypes.ListNestedObjectValueOf[computeEnvironmentOrder] `tfsdk:"compute_environment_order"` + ID types.String `tfsdk:"id"` + JobQueueName types.String `tfsdk:"name"` + Priority types.Int64 `tfsdk:"priority"` + SchedulingPolicyARN fwtypes.ARN `tfsdk:"scheduling_policy_arn"` + State types.String `tfsdk:"state"` + Tags types.Map `tfsdk:"tags"` + TagsAll types.Map `tfsdk:"tags_all"` + Timeouts timeouts.Value `tfsdk:"timeouts"` +} + +type computeEnvironmentOrder struct { + ComputeEnvironment types.String `tfsdk:"compute_environment"` + Order types.Int64 `tfsdk:"order"` } func (r *resourceJobQueueData) refreshFromOutput(ctx context.Context, out *batch.JobQueueDetail) diag.Diagnostics { //nolint:unparam var diags diag.Diagnostics r.ARN = flex.StringToFrameworkLegacy(ctx, out.JobQueueArn) - r.Name = flex.StringToFramework(ctx, out.JobQueueName) - r.ComputeEnvironments = flex.FlattenFrameworkStringValueListLegacy(ctx, flattenComputeEnvironmentOrder(out.ComputeEnvironmentOrder)) + r.JobQueueName = flex.StringToFramework(ctx, out.JobQueueName) r.Priority = flex.Int64ToFrameworkLegacy(ctx, out.Priority) r.SchedulingPolicyARN = flex.StringToFrameworkARN(ctx, out.SchedulingPolicyArn) r.State = flex.StringToFrameworkLegacy(ctx, out.State) @@ -366,7 +419,17 @@ func (r *resourceJobQueueData) refreshFromOutput(ctx context.Context, out *batch return diags } -func expandComputeEnvironmentOrder(order []string) (envs []*batch.ComputeEnvironmentOrder) { +// func (r *resourceJobQueue) expandComputeEnvironmentOrder(ctx context.Context, ceos computeEnvironmentOrder) awstypes.ComputeEnvironmentOrder { +// for _, v := range data.ComputeEnvironmentOrder { + +// } +// return awstypes.ComputeEnvironmentOrder{ +// Order: flex.Int32FromFramework(ctx, data.Order), +// ComputeEnvironment: flex.StringFromFramework(ctx, data.ComputeEnvironment), +// } +// } + +func expandComputeEnvironments(order []string) (envs []*batch.ComputeEnvironmentOrder) { for i, env := range order { envs = append(envs, &batch.ComputeEnvironmentOrder{ Order: aws.Int64(int64(i)), diff --git a/internal/service/batch/job_queue_schema.go b/internal/service/batch/job_queue_schema.go index bd19814922cd..829c756b84f3 100644 --- a/internal/service/batch/job_queue_schema.go +++ b/internal/service/batch/job_queue_schema.go @@ -94,7 +94,7 @@ func upgradeJobQueueResourceStateV0toV1(ctx context.Context, req resource.Upgrad jobQueueDataV2 := resourceJobQueueData{ ComputeEnvironments: jobQueueDataV0.ComputeEnvironments, ID: jobQueueDataV0.ID, - Name: jobQueueDataV0.Name, + JobQueueName: jobQueueDataV0.Name, Priority: jobQueueDataV0.Priority, State: jobQueueDataV0.State, Tags: jobQueueDataV0.Tags, diff --git a/internal/service/batch/job_queue_test.go b/internal/service/batch/job_queue_test.go index 53c98bd19187..1dc58162ca63 100644 --- a/internal/service/batch/job_queue_test.go +++ b/internal/service/batch/job_queue_test.go @@ -55,6 +55,40 @@ func TestAccBatchJobQueue_basic(t *testing.T) { }) } +func TestAccBatchJobQueue_basicCEO(t *testing.T) { + ctx := acctest.Context(t) + var jobQueue1 batch.JobQueueDetail + resourceName := "aws_batch_job_queue.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, batch.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckJobQueueDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccJobQueueConfig_stateCEO(rName, batch.JQStateEnabled), + Check: resource.ComposeTestCheckFunc( + testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), + acctest.CheckResourceAttrRegionalARN(resourceName, "arn", "batch", fmt.Sprintf("job-queue/%s", rName)), + resource.TestCheckResourceAttr(resourceName, "compute_environment_order.#", "1"), + resource.TestCheckResourceAttrPair(resourceName, "compute_environment_order.0.compute_environment", "aws_batch_compute_environment.test", "arn"), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "priority", "1"), + resource.TestCheckResourceAttr(resourceName, "state", batch.JQStateEnabled), + resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccBatchJobQueue_disappears(t *testing.T) { ctx := acctest.Context(t) var jobQueue1 batch.JobQueueDetail @@ -589,7 +623,25 @@ func testAccJobQueueConfig_state(rName string, state string) string { testAccJobQueueConfigBase(rName), fmt.Sprintf(` resource "aws_batch_job_queue" "test" { - compute_environments = [aws_batch_compute_environment.test.arn] + compute_environments = [aws_batch_compute_environment.test.arn] + + name = %[1]q + priority = 1 + state = %[2]q +} +`, rName, state)) +} + +func testAccJobQueueConfig_stateCEO(rName string, state string) string { + return acctest.ConfigCompose( + testAccJobQueueConfigBase(rName), + fmt.Sprintf(` +resource "aws_batch_job_queue" "test" { + compute_environment_order { + compute_environment = aws_batch_compute_environment.test.arn + order = 1 + } + name = %[1]q priority = 1 state = %[2]q