From ff480f78795fa3f40a4601bb7f9dbbbe5f762d83 Mon Sep 17 00:00:00 2001 From: chan Date: Fri, 9 Aug 2024 01:25:57 -0400 Subject: [PATCH 1/9] copy over the changes --- internal/service/batch/job_queue.go | 52 +++++++++++ .../service/batch/job_queue_data_source.go | 38 ++++++++ .../batch/job_queue_data_source_test.go | 8 ++ internal/service/batch/job_queue_schema.go | 2 + internal/service/batch/job_queue_test.go | 93 +++++++++++++++++++ 5 files changed, 193 insertions(+) diff --git a/internal/service/batch/job_queue.go b/internal/service/batch/job_queue.go index 9e41a479d965..50dab545bffe 100644 --- a/internal/service/batch/job_queue.go +++ b/internal/service/batch/job_queue.go @@ -15,6 +15,7 @@ import ( "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/int64validator" "github.com/hashicorp/terraform-plugin-framework-validators/resourcevalidator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/diag" @@ -133,6 +134,34 @@ func (r *resourceJobQueue) Schema(ctx context.Context, request resource.SchemaRe }, }, }, + "job_state_time_limit_action": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[jobStateTimeLimitAction](ctx), + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "action": schema.StringAttribute{ + Required: true, + Validators: []validator.String{ + stringvalidator.OneOf(batch.JobStateTimeLimitActionsAction_Values()...), + }, + }, + "max_time_seconds": schema.Int64Attribute{ + Required: true, + Validators: []validator.Int64{ + int64validator.Between(600, 86400), + }, + }, + "reason": schema.StringAttribute{ + Required: true, + }, + "state": schema.StringAttribute{ + Required: true, + Validators: []validator.String{ + stringvalidator.OneOf(batch.JobStateTimeLimitActionsState_Values()...), + }, + }, + }, + }, + }, } response.Schema = s @@ -193,6 +222,11 @@ func (r *resourceJobQueue) Create(ctx context.Context, request resource.CreateRe } else { state.ComputeEnvironments = flex.FlattenFrameworkStringValueListLegacy(ctx, flattenComputeEnvironments(out.ComputeEnvironmentOrder)) } + + if !data.JobStateTimeLimitAction.IsNull() { + flex.Flatten(ctx, out.JobStateTimeLimitActions, &data.JobStateTimeLimitAction) + } + response.Diagnostics.Append(state.refreshFromOutput(ctx, out)...) response.Diagnostics.Append(response.State.Set(ctx, &state)...) } @@ -228,6 +262,11 @@ func (r *resourceJobQueue) Read(ctx context.Context, request resource.ReadReques } else { data.ComputeEnvironments = flex.FlattenFrameworkStringValueListLegacy(ctx, flattenComputeEnvironments(out.ComputeEnvironmentOrder)) } + + if !data.JobStateTimeLimitAction.IsNull() { + flex.Flatten(ctx, out.JobStateTimeLimitActions, &data.JobStateTimeLimitAction) + } + response.Diagnostics.Append(data.refreshFromOutput(ctx, out)...) response.Diagnostics.Append(response.State.Set(ctx, &data)...) } @@ -259,6 +298,11 @@ func (r *resourceJobQueue) Update(ctx context.Context, request resource.UpdateRe } } + if !plan.JobStateTimeLimitAction.IsNull() && !plan.JobStateTimeLimitAction.Equal(state.JobStateTimeLimitAction) { + flex.Expand(ctx, plan.JobStateTimeLimitAction, &input.JobStateTimeLimitActions) + update = true + } + if !plan.Priority.Equal(state.Priority) { input.Priority = flex.Int64FromFramework(ctx, plan.Priority) @@ -393,6 +437,7 @@ type resourceJobQueueData struct { JobQueueName types.String `tfsdk:"name"` Priority types.Int64 `tfsdk:"priority"` SchedulingPolicyARN fwtypes.ARN `tfsdk:"scheduling_policy_arn"` + JobStateTimeLimitAction fwtypes.ListNestedObjectValueOf[jobStateTimeLimitAction] `tfsdk:"job_state_time_limit_action"` State types.String `tfsdk:"state"` Tags types.Map `tfsdk:"tags"` TagsAll types.Map `tfsdk:"tags_all"` @@ -404,6 +449,13 @@ type computeEnvironmentOrder struct { Order types.Int64 `tfsdk:"order"` } +type jobStateTimeLimitAction struct { + Action types.String `tfsdk:"action"` + MaxTimeSeconds types.Int64 `tfsdk:"max_time_seconds"` + Reason types.String `tfsdk:"reason"` + State types.String `tfsdk:"state"` +} + func (r *resourceJobQueueData) refreshFromOutput(ctx context.Context, out *batch.JobQueueDetail) diag.Diagnostics { //nolint:unparam var diags diag.Diagnostics diff --git a/internal/service/batch/job_queue_data_source.go b/internal/service/batch/job_queue_data_source.go index a0453d79908e..9e3c0a8cc926 100644 --- a/internal/service/batch/job_queue_data_source.go +++ b/internal/service/batch/job_queue_data_source.go @@ -77,6 +77,31 @@ func DataSourceJobQueue() *schema.Resource { }, }, }, + + "job_state_time_limit_action": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "action": { + Type: schema.TypeString, + Computed: true, + }, + "max_time_seconds": { + Type: schema.TypeInt, + Computed: true, + }, + "reason": { + Type: schema.TypeString, + Computed: true, + }, + "state": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, }, } } @@ -122,6 +147,19 @@ func dataSourceJobQueueRead(ctx context.Context, d *schema.ResourceData, meta in return sdkdiag.AppendErrorf(diags, "setting compute_environment_order: %s", err) } + jobStateTimeLimitActions := make([]map[string]interface{}, 0) + for _, v := range jobQueue.JobStateTimeLimitActions { + jobStateTimeLimitAction := map[string]interface{}{} + jobStateTimeLimitAction["action"] = aws.StringValue(v.Action) + jobStateTimeLimitAction["max_time_seconds"] = aws.Int64Value(v.MaxTimeSeconds) + jobStateTimeLimitAction["reason"] = aws.StringValue(v.Reason) + jobStateTimeLimitAction["state"] = aws.StringValue(v.State) + jobStateTimeLimitActions = append(jobStateTimeLimitActions, jobStateTimeLimitAction) + } + if err := d.Set("job_state_time_limit_action", jobStateTimeLimitActions); err != nil { + return sdkdiag.AppendErrorf(diags, "setting job_state_time_limit_action: %s", err) + } + setTagsOut(ctx, jobQueue.Tags) return diags diff --git a/internal/service/batch/job_queue_data_source_test.go b/internal/service/batch/job_queue_data_source_test.go index dd9467c94bba..ac272926ce7a 100644 --- a/internal/service/batch/job_queue_data_source_test.go +++ b/internal/service/batch/job_queue_data_source_test.go @@ -63,6 +63,7 @@ func TestAccBatchJobQueueDataSource_schedulingPolicy(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrPair(dataSourceName, names.AttrARN, resourceName, names.AttrARN), resource.TestCheckResourceAttrPair(dataSourceName, "compute_environment_order.#", resourceName, "compute_environments.#"), + resource.TestCheckResourceAttrPair(datasourceName, "job_state_time_limit_action.#", resourceName, "job_state_time_limit_action.#"), resource.TestCheckResourceAttrPair(dataSourceName, names.AttrName, resourceName, names.AttrName), resource.TestCheckResourceAttrPair(dataSourceName, names.AttrPriority, resourceName, names.AttrPriority), resource.TestCheckResourceAttrPair(dataSourceName, "scheduling_policy_arn", resourceName, "scheduling_policy_arn"), @@ -225,6 +226,13 @@ resource "aws_batch_job_queue" "test" { state = "ENABLED" priority = 1 compute_environments = [aws_batch_compute_environment.sample.arn] + + job_state_time_limit_action { + action = "CANCEL" + max_time_seconds = 123 + reason = "foobar" + state = "RUNNABLE" + } } data "aws_batch_job_queue" "test" { diff --git a/internal/service/batch/job_queue_schema.go b/internal/service/batch/job_queue_schema.go index e8e1a272eb9f..9e254583da1e 100644 --- a/internal/service/batch/job_queue_schema.go +++ b/internal/service/batch/job_queue_schema.go @@ -91,6 +91,7 @@ func upgradeJobQueueResourceStateV0toV1(ctx context.Context, req resource.Upgrad return } ceo := fwtypes.NewListNestedObjectValueOfNull[computeEnvironmentOrder](ctx) + jobStateTimeLimitActions := fwtypes.NewListNestedObjectValueOfNull[jobStateTimeLimitAction](ctx) jobQueueDataV2 := resourceJobQueueData{ ComputeEnvironments: jobQueueDataV0.ComputeEnvironments, @@ -99,6 +100,7 @@ func upgradeJobQueueResourceStateV0toV1(ctx context.Context, req resource.Upgrad JobQueueName: jobQueueDataV0.Name, Priority: jobQueueDataV0.Priority, State: jobQueueDataV0.State, + JobStateTimeLimitAction: jobStateTimeLimitActions, Tags: jobQueueDataV0.Tags, TagsAll: jobQueueDataV0.TagsAll, Timeouts: jobQueueDataV0.Timeouts, diff --git a/internal/service/batch/job_queue_test.go b/internal/service/batch/job_queue_test.go index 397a6010035c..32762d2d0fcb 100644 --- a/internal/service/batch/job_queue_test.go +++ b/internal/service/batch/job_queue_test.go @@ -434,6 +434,99 @@ func testAccCheckJobQueueExists(ctx context.Context, n string, jq *batch.JobQueu } } +func TestAccBatchJobQueue_JobStateTimeLimitActionsMultiple(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, names.BatchServiceID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckJobQueueDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: acctest.ConfigCompose( + testAccJobQueueConfig_Base(rName), + fmt.Sprintf(` +resource "aws_batch_job_queue" "test" { + compute_environments = [aws_batch_compute_environment.test.arn] + name = %[1]q + priority = 1 + state = "DISABLED" + job_state_time_limit_action { + action = "CANCEL" + max_time_seconds = 600 + reason = "MISCONFIGURATION:JOB_RESOURCE_REQUIREMENT" + state = "RUNNABLE" + } + job_state_time_limit_action { + action = "CANCEL" + max_time_seconds = 605 + reason = "CAPACITY:INSUFFICIENT_INSTANCE_CAPACITY" + state = "RUNNABLE" + } +} +`, rName)), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), + resource.TestCheckResourceAttr(resourceName, "job_state_time_limit_action.#", "2"), + resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.0", "job_state_time_limit_action.action", "CANCEL"), + resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.0", "job_state_time_limit_action.max_time_seconds", "600"), + resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.0", "job_state_time_limit_action.reason", "MISCONFIGURATION:JOB_RESOURCE_REQUIREMENT"), + resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.0", "job_state_time_limit_action.state", "RUNNABLE"), + resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.1", "job_state_time_limit_action.action", "CANCEL"), + resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.1", "job_state_time_limit_action.max_time_seconds", "605"), + resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.1", "job_state_time_limit_action.reason", "CAPACITY:INSUFFICIENT_INSTANCE_CAPACITY"), + resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.1", "job_state_time_limit_action.state", "RUNNABLE"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: acctest.ConfigCompose( + testAccJobQueueConfig_Base(rName), + fmt.Sprintf(` +resource "aws_batch_job_queue" "test" { + compute_environments = [aws_batch_compute_environment.test.arn] + name = %[1]q + priority = 1 + state = "DISABLED" + job_state_time_limit_action { + action = "CANCEL" + max_time_seconds = 610 + reason = "MISCONFIGURATION:JOB_RESOURCE_REQUIREMENT" + state = "RUNNABLE" + } + job_state_time_limit_action { + action = "CANCEL" + max_time_seconds = 605 + reason = "MISCONFIGURATION:COMPUTE_ENVIRONMENT_MAX_RESOURCE" + state = "RUNNABLE" + } +} +`, rName)), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), + resource.TestCheckResourceAttr(resourceName, "job_state_time_limit_action.#", "2"), + resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.0", "job_state_time_limit_action.action", "CANCEL"), + resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.0", "job_state_time_limit_action.max_time_seconds", "610"), + resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.0", "job_state_time_limit_action.reason", "MISCONFIGURATION:JOB_RESOURCE_REQUIREMENT"), + resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.0", "job_state_time_limit_action.state", "RUNNABLE"), + resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.1", "job_state_time_limit_action.action", "CANCEL"), + resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.1", "job_state_time_limit_action.max_time_seconds", "605"), + resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.1", "job_state_time_limit_action.reason", "MISCONFIGURATION:COMPUTE_ENVIRONMENT_MAX_RESOURCE"), + resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.1", "job_state_time_limit_action.state", "RUNNABLE"), + ), + }, + }, + }) +} + func testAccCheckJobQueueDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { for _, rs := range s.RootModule().Resources { From 3997978de46085ec4f332c91ffcba33b8127b7a3 Mon Sep 17 00:00:00 2001 From: chan Date: Fri, 9 Aug 2024 01:30:28 -0400 Subject: [PATCH 2/9] copy over the remaining --- .changelog/36658.txt | 7 +++++++ website/docs/d/batch_job_queue.html.markdown | 5 +++++ website/docs/r/batch_job_queue.html.markdown | 8 ++++++++ 3 files changed, 20 insertions(+) create mode 100644 .changelog/36658.txt diff --git a/.changelog/36658.txt b/.changelog/36658.txt new file mode 100644 index 000000000000..c631fda6f1a6 --- /dev/null +++ b/.changelog/36658.txt @@ -0,0 +1,7 @@ +```release-note:enhancement +resource/aws_batch_job_queue: Add `job_state_time_limit_action` argument +``` + +```release-note:enhancement +data-source/aws_batch_job_queue: Add `job_state_time_limit_action` attribute +``` diff --git a/website/docs/d/batch_job_queue.html.markdown b/website/docs/d/batch_job_queue.html.markdown index 7b122cae84d1..538cd9fb917e 100644 --- a/website/docs/d/batch_job_queue.html.markdown +++ b/website/docs/d/batch_job_queue.html.markdown @@ -42,3 +42,8 @@ This data source exports the following attributes in addition to the arguments a which job placement is preferred. Compute environments are selected for job placement in ascending order. * `compute_environment_order.#.order` - The order of the compute environment. * `compute_environment_order.#.compute_environment` - The ARN of the compute environment. +* `job_state_time_limit_action` - Specifies an action that AWS Batch will take after the job has remained at the head of the queue in the specified state for longer than the specified time. + * `job_state_time_limit_action.#.action` - The action to take when a job is at the head of the job queue in the specified state for the specified period of time. + * `job_state_time_limit_action.#.max_time_seconds` - The approximate amount of time, in seconds, that must pass with the job in the specified state before the action is taken. + * `job_state_time_limit_action.#.reason` - The reason to log for the action being taken. + * `job_state_time_limit_action.#.state` - The state of the job needed to trigger the action. diff --git a/website/docs/r/batch_job_queue.html.markdown b/website/docs/r/batch_job_queue.html.markdown index 3de5f66914a8..5351072c0246 100644 --- a/website/docs/r/batch_job_queue.html.markdown +++ b/website/docs/r/batch_job_queue.html.markdown @@ -75,6 +75,7 @@ This resource supports the following arguments: * `name` - (Required) Specifies the name of the job queue. * `compute_environments` - (Deprecated) (Optional) This parameter is deprecated, please use `compute_environment_order` instead. List of compute environment ARNs mapped to a job queue. The position of the compute environments in the list will dictate the order. When importing a AWS Batch Job Queue, the parameter `compute_environments` will always be used over `compute_environment_order`. Please adjust your HCL accordingly. * `compute_environment_order` - (Optional) The set of compute environments mapped to a job queue and their order relative to each other. The job scheduler uses this parameter to determine which compute environment runs a specific job. Compute environments must be in the VALID state before you can associate them with a job queue. You can associate up to three compute environments with a job queue. +* `job_state_time_limit_action` - (Optional) The set of job state time limit actions mapped to a job queue. Specifies an action that AWS Batch will take after the job has remained at the head of the queue in the specified state for longer than the specified time. * `priority` - (Required) The priority of the job queue. Job queues with a higher priority are evaluated first when associated with the same compute environment. * `scheduling_policy_arn` - (Optional) The ARN of the fair share scheduling policy. If this parameter is specified, the job queue uses a fair share scheduling policy. If this parameter isn't specified, the job queue uses a first in, first out (FIFO) scheduling policy. After a job queue is created, you can replace but can't remove the fair share scheduling policy. @@ -86,6 +87,13 @@ This resource supports the following arguments: * `compute_environment` - (Required) The Amazon Resource Name (ARN) of the compute environment. * `order` - (Required) The order of the compute environment. Compute environments are tried in ascending order. For example, if two compute environments are associated with a job queue, the compute environment with a lower order integer value is tried for job placement first. +### job_state_time_limit_action + +* `action` - (Required) The action to take when a job is at the head of the job queue in the specified state for the specified period of time. Valid values include `"CANCEL"` + * `job_state_time_limit_action.#.max_time_seconds` - The approximate amount of time, in seconds, that must pass with the job in the specified state before the action is taken. Valid values include integers between `600` & `86400` +* `reason` - (Required) The reason to log for the action being taken. +* `state` - (Required) The state of the job needed to trigger the action. Valid values include `"RUNNABLE"`. + ## Attribute Reference This resource exports the following attributes in addition to the arguments above: From f9f4e875376a83d51eddfe702bc9aa48ba925797 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 16 Aug 2024 14:44:15 -0400 Subject: [PATCH 3/9] r/aws_batch_job_queue: Fix compilation errors. --- internal/service/batch/job_queue.go | 170 +++++++------------- internal/service/batch/job_queue_migrate.go | 3 - internal/service/batch/job_queue_test.go | 165 +++++++++---------- 3 files changed, 135 insertions(+), 203 deletions(-) diff --git a/internal/service/batch/job_queue.go b/internal/service/batch/job_queue.go index 1200d4862b3e..ac40d4c44bc0 100644 --- a/internal/service/batch/job_queue.go +++ b/internal/service/batch/job_queue.go @@ -25,13 +25,11 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag" "github.com/hashicorp/terraform-provider-aws/internal/framework" - "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" @@ -120,30 +118,26 @@ func (r *jobQueueResource) Schema(ctx context.Context, request resource.SchemaRe }, }, }, - }, - "job_state_time_limit_action": schema.ListNestedBlock{ - CustomType: fwtypes.NewListNestedObjectTypeOf[jobStateTimeLimitAction](ctx), - NestedObject: schema.NestedBlockObject{ - Attributes: map[string]schema.Attribute{ - "action": schema.StringAttribute{ - Required: true, - Validators: []validator.String{ - stringvalidator.OneOf(batch.JobStateTimeLimitActionsAction_Values()...), + "job_state_time_limit_action": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[jobStateTimeLimitActionModel](ctx), + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "action": schema.StringAttribute{ + CustomType: fwtypes.StringEnumType[awstypes.JobStateTimeLimitActionsAction](), + Required: true, }, - }, - "max_time_seconds": schema.Int64Attribute{ - Required: true, - Validators: []validator.Int64{ - int64validator.Between(600, 86400), + "max_time_seconds": schema.Int64Attribute{ + Required: true, + Validators: []validator.Int64{ + int64validator.Between(600, 86400), + }, }, - }, - "reason": schema.StringAttribute{ - Required: true, - }, - "state": schema.StringAttribute{ - Required: true, - Validators: []validator.String{ - stringvalidator.OneOf(batch.JobStateTimeLimitActionsState_Values()...), + "reason": schema.StringAttribute{ + Required: true, + }, + "state": schema.StringAttribute{ + CustomType: fwtypes.StringEnumType[awstypes.JobStateTimeLimitActionsState](), + Required: true, }, }, }, @@ -177,6 +171,10 @@ func (r *jobQueueResource) Create(ctx context.Context, request resource.CreateRe } else { input.ComputeEnvironmentOrder = expandComputeEnvironments(ctx, data.ComputeEnvironments) } + response.Diagnostics.Append(fwflex.Expand(ctx, data.JobStateTimeLimitActions, &input.JobStateTimeLimitActions)...) + if response.Diagnostics.HasError() { + return + } if !data.SchedulingPolicyARN.IsNull() { input.SchedulingPolicyArn = fwflex.StringFromFramework(ctx, data.SchedulingPolicyARN) } @@ -200,17 +198,6 @@ func (r *jobQueueResource) Create(ctx context.Context, request resource.CreateRe return } - if !data.ComputeEnvironmentOrder.IsNull() { - flex.Flatten(ctx, out.ComputeEnvironmentOrder, &data.ComputeEnvironmentOrder) - } else { - data.ComputeEnvironments = flex.FlattenFrameworkStringValueListLegacy(ctx, flattenComputeEnvironments(out.ComputeEnvironmentOrder)) - } - - if !data.JobStateTimeLimitAction.IsNull() { - flex.Flatten(ctx, out.JobStateTimeLimitActions, &data.JobStateTimeLimitAction) - } - - response.Diagnostics.Append(state.refreshFromOutput(ctx, out)...) response.Diagnostics.Append(response.State.Set(ctx, data)...) } @@ -254,17 +241,18 @@ func (r *jobQueueResource) Read(ctx context.Context, request resource.ReadReques data.ComputeEnvironments = flattenComputeEnvironments(ctx, jobQueue.ComputeEnvironmentOrder) } - if !data.JobStateTimeLimitAction.IsNull() { - flex.Flatten(ctx, out.JobStateTimeLimitActions, &data.JobStateTimeLimitAction) - } - data.JobQueueARN = fwflex.StringToFrameworkLegacy(ctx, jobQueue.JobQueueArn) data.JobQueueName = fwflex.StringToFramework(ctx, jobQueue.JobQueueName) + response.Diagnostics.Append(fwflex.Flatten(ctx, jobQueue.JobStateTimeLimitActions, &data.JobStateTimeLimitActions)...) + if response.Diagnostics.HasError() { + return + } data.Priority = fwflex.Int32ToFrameworkLegacy(ctx, jobQueue.Priority) data.SchedulingPolicyARN = fwflex.StringToFrameworkARN(ctx, jobQueue.SchedulingPolicyArn) data.State = fwflex.StringValueToFramework(ctx, jobQueue.State) setTagsOut(ctx, jobQueue.Tags) + response.Diagnostics.Append(response.State.Set(ctx, &data)...) } @@ -299,13 +287,15 @@ func (r *jobQueueResource) Update(ctx context.Context, request resource.UpdateRe } } - if !plan.JobStateTimeLimitAction.IsNull() && !plan.JobStateTimeLimitAction.Equal(state.JobStateTimeLimitAction) { - flex.Expand(ctx, plan.JobStateTimeLimitAction, &input.JobStateTimeLimitActions) + if !new.JobStateTimeLimitActions.Equal(old.JobStateTimeLimitActions) { + response.Diagnostics.Append(fwflex.Expand(ctx, new.JobStateTimeLimitActions, &input.JobStateTimeLimitActions)...) + if response.Diagnostics.HasError() { + return + } update = true } - - if !plan.Priority.Equal(state.Priority) { - input.Priority = flex.Int64FromFramework(ctx, plan.Priority) + if !new.Priority.Equal(old.Priority) { + input.Priority = fwflex.Int32FromFramework(ctx, new.Priority) update = true } if !new.State.Equal(old.State) { @@ -421,65 +411,9 @@ func (r *jobQueueResource) UpgradeState(ctx context.Context) map[int64]resource. } } -type resourceJobQueueData struct { - 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"` - JobStateTimeLimitAction fwtypes.ListNestedObjectValueOf[jobStateTimeLimitAction] `tfsdk:"job_state_time_limit_action"` - 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 fwtypes.ARN `tfsdk:"compute_environment"` - Order types.Int64 `tfsdk:"order"` -} - -type jobStateTimeLimitAction struct { - Action types.String `tfsdk:"action"` - MaxTimeSeconds types.Int64 `tfsdk:"max_time_seconds"` - Reason types.String `tfsdk:"reason"` - State types.String `tfsdk:"state"` -} - -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.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) - - setTagsOut(ctx, out.Tags) - - return diags -} - -func expandComputeEnvironments(order []string) (envs []*batch.ComputeEnvironmentOrder) { - for i, env := range order { - envs = append(envs, &batch.ComputeEnvironmentOrder{ - Order: aws.Int64(int64(i)), - ComputeEnvironment: aws.String(env), - }) - } - return -} - -func flattenComputeEnvironments(apiObject []*batch.ComputeEnvironmentOrder) []string { - sort.Slice(apiObject, func(i, j int) bool { - return aws.ToInt64(apiObject[i].Order) < aws.ToInt64(apiObject[j].Order) - }) - - computeEnvironments := make([]string, 0, len(apiObject)) - for _, v := range apiObject { - computeEnvironments = append(computeEnvironments, aws.ToString(v.ComputeEnvironment)) +func findJobQueueByID(ctx context.Context, conn *batch.Client, id string) (*awstypes.JobQueueDetail, error) { + input := &batch.DescribeJobQueuesInput{ + JobQueues: []string{id}, } output, err := findJobQueue(ctx, conn, input) @@ -605,17 +539,18 @@ func waitJobQueueDeleted(ctx context.Context, conn *batch.Client, id string, tim } type jobQueueResourceModel struct { - ComputeEnvironments types.List `tfsdk:"compute_environments"` - ComputeEnvironmentOrder fwtypes.ListNestedObjectValueOf[computeEnvironmentOrderModel] `tfsdk:"compute_environment_order"` - ID types.String `tfsdk:"id"` - JobQueueARN types.String `tfsdk:"arn"` - 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"` + ComputeEnvironments types.List `tfsdk:"compute_environments"` + ComputeEnvironmentOrder fwtypes.ListNestedObjectValueOf[computeEnvironmentOrderModel] `tfsdk:"compute_environment_order"` + ID types.String `tfsdk:"id"` + JobQueueARN types.String `tfsdk:"arn"` + JobQueueName types.String `tfsdk:"name"` + JobStateTimeLimitActions fwtypes.ListNestedObjectValueOf[jobStateTimeLimitActionModel] `tfsdk:"job_state_time_limit_action"` + 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"` } func (model *jobQueueResourceModel) InitFromID() error { @@ -633,6 +568,13 @@ type computeEnvironmentOrderModel struct { Order types.Int64 `tfsdk:"order"` } +type jobStateTimeLimitActionModel struct { + Action fwtypes.StringEnum[awstypes.JobStateTimeLimitActionsAction] `tfsdk:"action"` + MaxTimeSeconds types.Int64 `tfsdk:"max_time_seconds"` + Reason types.String `tfsdk:"reason"` + State fwtypes.StringEnum[awstypes.JobStateTimeLimitActionsState] `tfsdk:"state"` +} + func expandComputeEnvironments(ctx context.Context, tfList types.List) []awstypes.ComputeEnvironmentOrder { var apiObjects []awstypes.ComputeEnvironmentOrder diff --git a/internal/service/batch/job_queue_migrate.go b/internal/service/batch/job_queue_migrate.go index 0360a00c7f5b..4c20570739c8 100644 --- a/internal/service/batch/job_queue_migrate.go +++ b/internal/service/batch/job_queue_migrate.go @@ -70,8 +70,6 @@ func upgradeJobQueueResourceStateV0toV1(ctx context.Context, request resource.Up if response.Diagnostics.HasError() { return } - ceo := fwtypes.NewListNestedObjectValueOfNull[computeEnvironmentOrder](ctx) - jobStateTimeLimitActions := fwtypes.NewListNestedObjectValueOfNull[jobStateTimeLimitAction](ctx) jobQueueDataV1 := jobQueueResourceModel{ ComputeEnvironments: jobQueueDataV0.ComputeEnvironments, @@ -81,7 +79,6 @@ func upgradeJobQueueResourceStateV0toV1(ctx context.Context, request resource.Up JobQueueName: jobQueueDataV0.JobQueueName, Priority: jobQueueDataV0.Priority, State: jobQueueDataV0.State, - JobStateTimeLimitAction: jobStateTimeLimitActions, Tags: jobQueueDataV0.Tags, TagsAll: jobQueueDataV0.TagsAll, Timeouts: jobQueueDataV0.Timeouts, diff --git a/internal/service/batch/job_queue_test.go b/internal/service/batch/job_queue_test.go index 69ab3d8a1df5..e0a5fb083e1e 100644 --- a/internal/service/batch/job_queue_test.go +++ b/internal/service/batch/job_queue_test.go @@ -47,11 +47,12 @@ func TestAccBatchJobQueue_basic(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccJobQueueConfig_state(rName, string(awstypes.JQStateEnabled)), - Check: resource.ComposeTestCheckFunc( + Check: resource.ComposeAggregateTestCheckFunc( testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), acctest.CheckResourceAttrRegionalARN(resourceName, names.AttrARN, "batch", fmt.Sprintf("job-queue/%s", rName)), resource.TestCheckResourceAttr(resourceName, "compute_environments.#", acctest.Ct1), resource.TestCheckResourceAttrPair(resourceName, "compute_environments.0", "aws_batch_compute_environment.test", names.AttrARN), + resource.TestCheckResourceAttr(resourceName, "job_state_time_limit_action.#", acctest.Ct0), resource.TestCheckResourceAttr(resourceName, names.AttrName, rName), resource.TestCheckResourceAttr(resourceName, names.AttrPriority, acctest.Ct1), resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.JQStateEnabled)), @@ -408,30 +409,9 @@ func TestAccBatchJobQueue_state(t *testing.T) { }) } -func testAccCheckJobQueueExists(ctx context.Context, n string, v *awstypes.JobQueueDetail) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - conn := acctest.Provider.Meta().(*conns.AWSClient).BatchClient(ctx) - - output, err := tfbatch.FindJobQueueByID(ctx, conn, rs.Primary.ID) - - if err != nil { - return err - } - - *v = *output - - return nil - } -} - -func TestAccBatchJobQueue_JobStateTimeLimitActionsMultiple(t *testing.T) { +func TestAccBatchJobQueue_jobStateTimeLimitActionsMultiple(t *testing.T) { ctx := acctest.Context(t) - var jobQueue1 batch.JobQueueDetail + var jobQueue1 awstypes.JobQueueDetail resourceName := "aws_batch_job_queue.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -442,39 +422,10 @@ func TestAccBatchJobQueue_JobStateTimeLimitActionsMultiple(t *testing.T) { CheckDestroy: testAccCheckJobQueueDestroy(ctx), Steps: []resource.TestStep{ { - Config: acctest.ConfigCompose( - testAccJobQueueConfig_Base(rName), - fmt.Sprintf(` -resource "aws_batch_job_queue" "test" { - compute_environments = [aws_batch_compute_environment.test.arn] - name = %[1]q - priority = 1 - state = "DISABLED" - job_state_time_limit_action { - action = "CANCEL" - max_time_seconds = 600 - reason = "MISCONFIGURATION:JOB_RESOURCE_REQUIREMENT" - state = "RUNNABLE" - } - job_state_time_limit_action { - action = "CANCEL" - max_time_seconds = 605 - reason = "CAPACITY:INSUFFICIENT_INSTANCE_CAPACITY" - state = "RUNNABLE" - } -} -`, rName)), - Check: resource.ComposeAggregateTestCheckFunc( + Config: testAccJobQueueConfig_jobStateTimeLimitAction(rName), + Check: resource.ComposeTestCheckFunc( testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), resource.TestCheckResourceAttr(resourceName, "job_state_time_limit_action.#", "2"), - resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.0", "job_state_time_limit_action.action", "CANCEL"), - resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.0", "job_state_time_limit_action.max_time_seconds", "600"), - resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.0", "job_state_time_limit_action.reason", "MISCONFIGURATION:JOB_RESOURCE_REQUIREMENT"), - resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.0", "job_state_time_limit_action.state", "RUNNABLE"), - resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.1", "job_state_time_limit_action.action", "CANCEL"), - resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.1", "job_state_time_limit_action.max_time_seconds", "605"), - resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.1", "job_state_time_limit_action.reason", "CAPACITY:INSUFFICIENT_INSTANCE_CAPACITY"), - resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.1", "job_state_time_limit_action.state", "RUNNABLE"), ), }, { @@ -483,45 +434,37 @@ resource "aws_batch_job_queue" "test" { ImportStateVerify: true, }, { - Config: acctest.ConfigCompose( - testAccJobQueueConfig_Base(rName), - fmt.Sprintf(` -resource "aws_batch_job_queue" "test" { - compute_environments = [aws_batch_compute_environment.test.arn] - name = %[1]q - priority = 1 - state = "DISABLED" - job_state_time_limit_action { - action = "CANCEL" - max_time_seconds = 610 - reason = "MISCONFIGURATION:JOB_RESOURCE_REQUIREMENT" - state = "RUNNABLE" - } - job_state_time_limit_action { - action = "CANCEL" - max_time_seconds = 605 - reason = "MISCONFIGURATION:COMPUTE_ENVIRONMENT_MAX_RESOURCE" - state = "RUNNABLE" - } -} -`, rName)), - Check: resource.ComposeAggregateTestCheckFunc( + Config: testAccJobQueueConfig_jobStateTimeLimitActionUpdated(rName), + Check: resource.ComposeTestCheckFunc( testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), resource.TestCheckResourceAttr(resourceName, "job_state_time_limit_action.#", "2"), - resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.0", "job_state_time_limit_action.action", "CANCEL"), - resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.0", "job_state_time_limit_action.max_time_seconds", "610"), - resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.0", "job_state_time_limit_action.reason", "MISCONFIGURATION:JOB_RESOURCE_REQUIREMENT"), - resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.0", "job_state_time_limit_action.state", "RUNNABLE"), - resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.1", "job_state_time_limit_action.action", "CANCEL"), - resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.1", "job_state_time_limit_action.max_time_seconds", "605"), - resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.1", "job_state_time_limit_action.reason", "MISCONFIGURATION:COMPUTE_ENVIRONMENT_MAX_RESOURCE"), - resource.TestCheckResourceAttrPair(resourceName, "job_state_time_limit_action.1", "job_state_time_limit_action.state", "RUNNABLE"), ), }, }, }) } +func testAccCheckJobQueueExists(ctx context.Context, n string, v *awstypes.JobQueueDetail) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + conn := acctest.Provider.Meta().(*conns.AWSClient).BatchClient(ctx) + + output, err := tfbatch.FindJobQueueByID(ctx, conn, rs.Primary.ID) + + if err != nil { + return err + } + + *v = *output + + return nil + } +} + func testAccCheckJobQueueDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { for _, rs := range s.RootModule().Resources { @@ -898,3 +841,53 @@ resource "aws_batch_compute_environment" "more" { } `, rName, state)) } + +func testAccJobQueueConfig_jobStateTimeLimitAction(rName string) string { + return acctest.ConfigCompose( + testAccJobQueueConfig_base(rName), + fmt.Sprintf(` +resource "aws_batch_job_queue" "test" { + compute_environments = [aws_batch_compute_environment.test.arn] + name = %[1]q + priority = 1 + state = "DISABLED" + job_state_time_limit_action { + action = "CANCEL" + max_time_seconds = 600 + reason = "MISCONFIGURATION:JOB_RESOURCE_REQUIREMENT" + state = "RUNNABLE" + } + job_state_time_limit_action { + action = "CANCEL" + max_time_seconds = 605 + reason = "CAPACITY:INSUFFICIENT_INSTANCE_CAPACITY" + state = "RUNNABLE" + } +} +`, rName)) +} + +func testAccJobQueueConfig_jobStateTimeLimitActionUpdated(rName string) string { + return acctest.ConfigCompose( + testAccJobQueueConfig_base(rName), + fmt.Sprintf(` +resource "aws_batch_job_queue" "test" { + compute_environments = [aws_batch_compute_environment.test.arn] + name = %[1]q + priority = 1 + state = "DISABLED" + job_state_time_limit_action { + action = "CANCEL" + max_time_seconds = 610 + reason = "MISCONFIGURATION:JOB_RESOURCE_REQUIREMENT" + state = "RUNNABLE" + } + job_state_time_limit_action { + action = "CANCEL" + max_time_seconds = 605 + reason = "MISCONFIGURATION:COMPUTE_ENVIRONMENT_MAX_RESOURCE" + state = "RUNNABLE" + } +} +`, rName)) +} From d602c5d0f83a895c4c796ec88d13d4bb8b38a659 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 16 Aug 2024 14:44:37 -0400 Subject: [PATCH 4/9] Correct CHANGELOG entry file name. --- .changelog/{36658.txt => 38784.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/{36658.txt => 38784.txt} (100%) diff --git a/.changelog/36658.txt b/.changelog/38784.txt similarity index 100% rename from .changelog/36658.txt rename to .changelog/38784.txt From c23d1cceceae397187b915314cd3a544d1840155 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 16 Aug 2024 14:50:54 -0400 Subject: [PATCH 5/9] d/aws_batch_job_queue: Fix compilation errors. --- .../service/batch/job_queue_data_source.go | 18 +-- .../batch/job_queue_data_source_test.go | 113 +----------------- 2 files changed, 15 insertions(+), 116 deletions(-) diff --git a/internal/service/batch/job_queue_data_source.go b/internal/service/batch/job_queue_data_source.go index 90513436eced..43fc7bc1d488 100644 --- a/internal/service/batch/job_queue_data_source.go +++ b/internal/service/batch/job_queue_data_source.go @@ -127,16 +127,16 @@ func dataSourceJobQueueRead(ctx context.Context, d *schema.ResourceData, meta in return sdkdiag.AppendErrorf(diags, "setting compute_environment_order: %s", err) } - jobStateTimeLimitActions := make([]map[string]interface{}, 0) - for _, v := range jobQueue.JobStateTimeLimitActions { - jobStateTimeLimitAction := map[string]interface{}{} - jobStateTimeLimitAction["action"] = aws.StringValue(v.Action) - jobStateTimeLimitAction["max_time_seconds"] = aws.Int64Value(v.MaxTimeSeconds) - jobStateTimeLimitAction["reason"] = aws.StringValue(v.Reason) - jobStateTimeLimitAction["state"] = aws.StringValue(v.State) - jobStateTimeLimitActions = append(jobStateTimeLimitActions, jobStateTimeLimitAction) + tfList = make([]interface{}, 0) + for _, apiObject := range jobQueue.JobStateTimeLimitActions { + tfMap := map[string]interface{}{} + tfMap["action"] = apiObject.Action + tfMap["max_time_seconds"] = aws.ToInt32(apiObject.MaxTimeSeconds) + tfMap["reason"] = aws.ToString(apiObject.Reason) + tfMap["state"] = apiObject.State + tfList = append(tfList, tfMap) } - if err := d.Set("job_state_time_limit_action", jobStateTimeLimitActions); err != nil { + if err := d.Set("job_state_time_limit_action", tfList); err != nil { return sdkdiag.AppendErrorf(diags, "setting job_state_time_limit_action: %s", err) } diff --git a/internal/service/batch/job_queue_data_source_test.go b/internal/service/batch/job_queue_data_source_test.go index ac272926ce7a..85c6c6f9ceb0 100644 --- a/internal/service/batch/job_queue_data_source_test.go +++ b/internal/service/batch/job_queue_data_source_test.go @@ -63,7 +63,7 @@ func TestAccBatchJobQueueDataSource_schedulingPolicy(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrPair(dataSourceName, names.AttrARN, resourceName, names.AttrARN), resource.TestCheckResourceAttrPair(dataSourceName, "compute_environment_order.#", resourceName, "compute_environments.#"), - resource.TestCheckResourceAttrPair(datasourceName, "job_state_time_limit_action.#", resourceName, "job_state_time_limit_action.#"), + resource.TestCheckResourceAttrPair(dataSourceName, "job_state_time_limit_action.#", resourceName, "job_state_time_limit_action.#"), resource.TestCheckResourceAttrPair(dataSourceName, names.AttrName, resourceName, names.AttrName), resource.TestCheckResourceAttrPair(dataSourceName, names.AttrPriority, resourceName, names.AttrPriority), resource.TestCheckResourceAttrPair(dataSourceName, "scheduling_policy_arn", resourceName, "scheduling_policy_arn"), @@ -77,123 +77,22 @@ func TestAccBatchJobQueueDataSource_schedulingPolicy(t *testing.T) { }) } -func testAccJobQueueDataSourceConfigBase(rName string) string { - return fmt.Sprintf(` -data "aws_partition" "current" {} - -resource "aws_iam_role" "ecs_instance_role" { - name = "ecs_%[1]s" - - assume_role_policy = < Date: Fri, 16 Aug 2024 14:53:09 -0400 Subject: [PATCH 6/9] Run 'make fix-constants PKG=batch'. --- internal/service/batch/job_queue.go | 4 ++-- internal/service/batch/job_queue_data_source.go | 8 ++++---- internal/service/batch/job_queue_test.go | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/service/batch/job_queue.go b/internal/service/batch/job_queue.go index ac40d4c44bc0..1e958241e430 100644 --- a/internal/service/batch/job_queue.go +++ b/internal/service/batch/job_queue.go @@ -122,7 +122,7 @@ func (r *jobQueueResource) Schema(ctx context.Context, request resource.SchemaRe CustomType: fwtypes.NewListNestedObjectTypeOf[jobStateTimeLimitActionModel](ctx), NestedObject: schema.NestedBlockObject{ Attributes: map[string]schema.Attribute{ - "action": schema.StringAttribute{ + names.AttrAction: schema.StringAttribute{ CustomType: fwtypes.StringEnumType[awstypes.JobStateTimeLimitActionsAction](), Required: true, }, @@ -135,7 +135,7 @@ func (r *jobQueueResource) Schema(ctx context.Context, request resource.SchemaRe "reason": schema.StringAttribute{ Required: true, }, - "state": schema.StringAttribute{ + names.AttrState: schema.StringAttribute{ CustomType: fwtypes.StringEnumType[awstypes.JobStateTimeLimitActionsState](), Required: true, }, diff --git a/internal/service/batch/job_queue_data_source.go b/internal/service/batch/job_queue_data_source.go index 43fc7bc1d488..310e81b54f2e 100644 --- a/internal/service/batch/job_queue_data_source.go +++ b/internal/service/batch/job_queue_data_source.go @@ -48,7 +48,7 @@ func dataSourceJobQueue() *schema.Resource { Computed: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "action": { + names.AttrAction: { Type: schema.TypeString, Computed: true, }, @@ -60,7 +60,7 @@ func dataSourceJobQueue() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "state": { + names.AttrState: { Type: schema.TypeString, Computed: true, }, @@ -130,10 +130,10 @@ func dataSourceJobQueueRead(ctx context.Context, d *schema.ResourceData, meta in tfList = make([]interface{}, 0) for _, apiObject := range jobQueue.JobStateTimeLimitActions { tfMap := map[string]interface{}{} - tfMap["action"] = apiObject.Action + tfMap[names.AttrAction] = apiObject.Action tfMap["max_time_seconds"] = aws.ToInt32(apiObject.MaxTimeSeconds) tfMap["reason"] = aws.ToString(apiObject.Reason) - tfMap["state"] = apiObject.State + tfMap[names.AttrState] = apiObject.State tfList = append(tfList, tfMap) } if err := d.Set("job_state_time_limit_action", tfList); err != nil { diff --git a/internal/service/batch/job_queue_test.go b/internal/service/batch/job_queue_test.go index e0a5fb083e1e..6ea5dd5ed054 100644 --- a/internal/service/batch/job_queue_test.go +++ b/internal/service/batch/job_queue_test.go @@ -425,7 +425,7 @@ func TestAccBatchJobQueue_jobStateTimeLimitActionsMultiple(t *testing.T) { Config: testAccJobQueueConfig_jobStateTimeLimitAction(rName), Check: resource.ComposeTestCheckFunc( testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), - resource.TestCheckResourceAttr(resourceName, "job_state_time_limit_action.#", "2"), + resource.TestCheckResourceAttr(resourceName, "job_state_time_limit_action.#", acctest.Ct2), ), }, { @@ -437,7 +437,7 @@ func TestAccBatchJobQueue_jobStateTimeLimitActionsMultiple(t *testing.T) { Config: testAccJobQueueConfig_jobStateTimeLimitActionUpdated(rName), Check: resource.ComposeTestCheckFunc( testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), - resource.TestCheckResourceAttr(resourceName, "job_state_time_limit_action.#", "2"), + resource.TestCheckResourceAttr(resourceName, "job_state_time_limit_action.#", acctest.Ct2), ), }, }, From ce5b9e684ee3a185882bd980bd8558e365592792 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 16 Aug 2024 15:30:14 -0400 Subject: [PATCH 7/9] Correct 'upgradeJobQueueResourceStateV0toV1'. --- internal/service/batch/job_queue_migrate.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/internal/service/batch/job_queue_migrate.go b/internal/service/batch/job_queue_migrate.go index 4c20570739c8..c3d766b67d3f 100644 --- a/internal/service/batch/job_queue_migrate.go +++ b/internal/service/batch/job_queue_migrate.go @@ -72,16 +72,17 @@ func upgradeJobQueueResourceStateV0toV1(ctx context.Context, request resource.Up } jobQueueDataV1 := jobQueueResourceModel{ - ComputeEnvironments: jobQueueDataV0.ComputeEnvironments, - ComputeEnvironmentOrder: fwtypes.NewListNestedObjectValueOfNull[computeEnvironmentOrderModel](ctx), - ID: jobQueueDataV0.ID, - JobQueueARN: jobQueueDataV0.JobQueueARN, - JobQueueName: jobQueueDataV0.JobQueueName, - Priority: jobQueueDataV0.Priority, - State: jobQueueDataV0.State, - Tags: jobQueueDataV0.Tags, - TagsAll: jobQueueDataV0.TagsAll, - Timeouts: jobQueueDataV0.Timeouts, + ComputeEnvironments: jobQueueDataV0.ComputeEnvironments, + ComputeEnvironmentOrder: fwtypes.NewListNestedObjectValueOfNull[computeEnvironmentOrderModel](ctx), + ID: jobQueueDataV0.ID, + JobQueueARN: jobQueueDataV0.JobQueueARN, + JobQueueName: jobQueueDataV0.JobQueueName, + JobStateTimeLimitActions: fwtypes.NewListNestedObjectValueOfNull[jobStateTimeLimitActionModel](ctx), + Priority: jobQueueDataV0.Priority, + State: jobQueueDataV0.State, + Tags: jobQueueDataV0.Tags, + TagsAll: jobQueueDataV0.TagsAll, + Timeouts: jobQueueDataV0.Timeouts, } if jobQueueDataV0.SchedulingPolicyARN.ValueString() == "" { From 3a5d46360f15866aa3227db0bdd9521d918102bc Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 16 Aug 2024 15:57:30 -0400 Subject: [PATCH 8/9] Fix 'TestAccBatchJobQueueDataSource_schedulingPolicy'. --- internal/service/batch/job_queue_data_source_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/batch/job_queue_data_source_test.go b/internal/service/batch/job_queue_data_source_test.go index 85c6c6f9ceb0..dabf2440c08a 100644 --- a/internal/service/batch/job_queue_data_source_test.go +++ b/internal/service/batch/job_queue_data_source_test.go @@ -128,7 +128,7 @@ resource "aws_batch_job_queue" "test" { job_state_time_limit_action { action = "CANCEL" - max_time_seconds = 123 + max_time_seconds = 600 reason = "foobar" state = "RUNNABLE" } From 6ba70db574a71947339ff06ff8d920c6b6e0ada6 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 16 Aug 2024 16:02:41 -0400 Subject: [PATCH 9/9] Fix 'TestAccBatchJobQueueDataSource_schedulingPolicy'. --- internal/service/batch/job_queue_data_source_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/batch/job_queue_data_source_test.go b/internal/service/batch/job_queue_data_source_test.go index dabf2440c08a..dd11bf1bde53 100644 --- a/internal/service/batch/job_queue_data_source_test.go +++ b/internal/service/batch/job_queue_data_source_test.go @@ -129,7 +129,7 @@ resource "aws_batch_job_queue" "test" { job_state_time_limit_action { action = "CANCEL" max_time_seconds = 600 - reason = "foobar" + reason = "MISCONFIGURATION:JOB_RESOURCE_REQUIREMENT" state = "RUNNABLE" } }