From 6bd0f913037902db60fff01df8b38ae5dd31702a Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush <25692880+danquack@users.noreply.github.com> Date: Thu, 2 Jan 2025 13:55:18 -0500 Subject: [PATCH 01/13] :boom: remove compute environments from job queue --- internal/service/batch/job_queue.go | 49 +--- .../batch/job_queue_data_source_test.go | 33 ++- internal/service/batch/job_queue_migrate.go | 150 +++++++++++- .../service/batch/job_queue_migration_test.go | 84 +++++++ internal/service/batch/job_queue_test.go | 219 +++++------------- .../testdata/JobQueue/data.tags/main_gen.tf | 5 +- .../JobQueue/data.tags_defaults/main_gen.tf | 5 +- .../JobQueue/data.tags_ignore/main_gen.tf | 5 +- .../batch/testdata/JobQueue/tags/main_gen.tf | 5 +- .../JobQueue/tagsComputed1/main_gen.tf | 5 +- .../JobQueue/tagsComputed2/main_gen.tf | 5 +- .../JobQueue/tags_defaults/main_gen.tf | 5 +- .../testdata/JobQueue/tags_ignore/main_gen.tf | 5 +- .../batch/testdata/tmpl/job_queue_tags.gtpl | 6 +- internal/service/events/target_test.go | 12 +- internal/service/pipes/pipe_test.go | 12 +- .../python/r/batch_job_queue.html.markdown | 3 +- website/docs/r/batch_job_queue.html.markdown | 1 - 18 files changed, 379 insertions(+), 230 deletions(-) create mode 100644 internal/service/batch/job_queue_migration_test.go diff --git a/internal/service/batch/job_queue.go b/internal/service/batch/job_queue.go index fc193b631bbb..1b11a1cf31ae 100644 --- a/internal/service/batch/job_queue.go +++ b/internal/service/batch/job_queue.go @@ -17,7 +17,6 @@ import ( awstypes "github.com/aws/aws-sdk-go-v2/service/batch/types" "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/path" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -64,15 +63,10 @@ func (*jobQueueResource) Metadata(_ context.Context, request resource.MetadataRe func (r *jobQueueResource) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) { response.Schema = schema.Schema{ - Version: 1, + Version: 2, Attributes: map[string]schema.Attribute{ names.AttrARN: framework.ARNAttributeComputedOnly(), - "compute_environments": schema.ListAttribute{ - ElementType: fwtypes.ARNType, - Optional: true, - DeprecationMessage: "This parameter will be replaced by `compute_environment_order`.", - }, - names.AttrID: framework.IDAttribute(), + names.AttrID: framework.IDAttribute(), names.AttrName: schema.StringAttribute{ Required: true, PlanModifiers: []planmodifier.String{ @@ -169,8 +163,6 @@ func (r *jobQueueResource) Create(ctx context.Context, request resource.CreateRe if response.Diagnostics.HasError() { return } - } else { - input.ComputeEnvironmentOrder = expandComputeEnvironments(ctx, data.ComputeEnvironments) } response.Diagnostics.Append(fwflex.Expand(ctx, data.JobStateTimeLimitActions, &input.JobStateTimeLimitActions)...) if response.Diagnostics.HasError() { @@ -233,27 +225,12 @@ func (r *jobQueueResource) Read(ctx context.Context, request resource.ReadReques } // Set attributes for import. - if !data.ComputeEnvironmentOrder.IsNull() { - response.Diagnostics.Append(fwflex.Flatten(ctx, jobQueue.ComputeEnvironmentOrder, &data.ComputeEnvironmentOrder)...) - if response.Diagnostics.HasError() { - return - } - } else { - data.ComputeEnvironments = flattenComputeEnvironments(ctx, jobQueue.ComputeEnvironmentOrder) - } - - data.JobQueueARN = fwflex.StringToFrameworkLegacy(ctx, jobQueue.JobQueueArn) - data.JobQueueName = fwflex.StringToFramework(ctx, jobQueue.JobQueueName) - response.Diagnostics.Append(fwflex.Flatten(ctx, jobQueue.JobStateTimeLimitActions, &data.JobStateTimeLimitActions)...) + response.Diagnostics.Append(fwflex.Flatten(ctx, jobQueue, &data, fwflex.WithFieldNamePrefix("JobQueue"))...) 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)...) } @@ -281,11 +258,6 @@ func (r *jobQueueResource) Update(ctx context.Context, request resource.UpdateRe return } update = true - } else { - if !new.ComputeEnvironments.Equal(old.ComputeEnvironments) { - input.ComputeEnvironmentOrder = expandComputeEnvironments(ctx, new.ComputeEnvironments) - update = true - } } if !new.JobStateTimeLimitActions.Equal(old.JobStateTimeLimitActions) { @@ -392,23 +364,19 @@ func (r *jobQueueResource) ModifyPlan(ctx context.Context, request resource.Modi r.SetTagsAll(ctx, request, response) } -func (r *jobQueueResource) ConfigValidators(_ context.Context) []resource.ConfigValidator { - return []resource.ConfigValidator{ - resourcevalidator.ExactlyOneOf( - path.MatchRoot("compute_environments"), - path.MatchRoot("compute_environment_order"), - ), - } -} - func (r *jobQueueResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader { schemaV0 := jobQueueSchema0(ctx) + schemaV1 := jobQueueSchema1(ctx) return map[int64]resource.StateUpgrader{ 0: { PriorSchema: &schemaV0, StateUpgrader: upgradeJobQueueResourceStateV0toV1, }, + 1: { + PriorSchema: &schemaV1, + StateUpgrader: upgradeJobQueueResourceStateV1toV2, + }, } } @@ -540,7 +508,6 @@ 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"` diff --git a/internal/service/batch/job_queue_data_source_test.go b/internal/service/batch/job_queue_data_source_test.go index dd11bf1bde53..f559cbf3b624 100644 --- a/internal/service/batch/job_queue_data_source_test.go +++ b/internal/service/batch/job_queue_data_source_test.go @@ -31,7 +31,7 @@ func TestAccBatchJobQueueDataSource_basic(t *testing.T) { Config: testAccJobQueueDataSourceConfig_basic(rName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrPair(dataSourceName, names.AttrARN, resourceName, names.AttrARN), - resource.TestCheckResourceAttrPair(dataSourceName, "compute_environment_order.#", resourceName, "compute_environments.#"), + resource.TestCheckResourceAttrPair(dataSourceName, "compute_environment_order.#", resourceName, "compute_environment_order.#"), 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"), @@ -62,7 +62,7 @@ func TestAccBatchJobQueueDataSource_schedulingPolicy(t *testing.T) { Config: testAccJobQueueDataSourceConfig_schedulingPolicy(rName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrPair(dataSourceName, names.AttrARN, resourceName, names.AttrARN), - resource.TestCheckResourceAttrPair(dataSourceName, "compute_environment_order.#", resourceName, "compute_environments.#"), + resource.TestCheckResourceAttrPair(dataSourceName, "compute_environment_order.#", resourceName, "compute_environment_order.#"), 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), @@ -82,17 +82,24 @@ func testAccJobQueueDataSourceConfig_basic(rName string) string { testAccJobQueueConfig_base(rName), fmt.Sprintf(` resource "aws_batch_job_queue" "test" { - name = "%[1]s" - state = "ENABLED" - priority = 1 - compute_environments = [aws_batch_compute_environment.test.arn] + name = "%[1]s" + state = "ENABLED" + priority = 1 + compute_environment_order { + compute_environment = aws_batch_compute_environment.test.arn + order = 1 + } } resource "aws_batch_job_queue" "wrong" { - name = "%[1]s_wrong" - state = "ENABLED" - priority = 2 - compute_environments = [aws_batch_compute_environment.test.arn] + name = "%[1]s_wrong" + state = "ENABLED" + priority = 2 + compute_environment_order { + compute_environment = aws_batch_compute_environment.test.arn + order = 1 + } + } data "aws_batch_job_queue" "by_name" { @@ -124,7 +131,11 @@ resource "aws_batch_job_queue" "test" { scheduling_policy_arn = aws_batch_scheduling_policy.test.arn state = "ENABLED" priority = 1 - compute_environments = [aws_batch_compute_environment.test.arn] + compute_environment_order { + compute_environment = aws_batch_compute_environment.test.arn + order = 1 + } + job_state_time_limit_action { action = "CANCEL" diff --git a/internal/service/batch/job_queue_migrate.go b/internal/service/batch/job_queue_migrate.go index 3d442ce44206..093bbdfe2bee 100644 --- a/internal/service/batch/job_queue_migrate.go +++ b/internal/service/batch/job_queue_migrate.go @@ -6,10 +6,18 @@ package batch import ( "context" + "github.com/YakDriver/regexache" + awstypes "github.com/aws/aws-sdk-go-v2/service/batch/types" "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "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-provider-aws/internal/enum" "github.com/hashicorp/terraform-provider-aws/internal/framework" fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" @@ -51,6 +59,105 @@ func jobQueueSchema0(ctx context.Context) schema.Schema { } } +func jobQueueSchema1(ctx context.Context) schema.Schema { + return schema.Schema{ + Version: 1, + Attributes: map[string]schema.Attribute{ + names.AttrARN: framework.ARNAttributeComputedOnly(), + names.AttrID: framework.IDAttribute(), + names.AttrName: schema.StringAttribute{ + Required: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + Validators: []validator.String{ + stringvalidator.RegexMatches(regexache.MustCompile(`^[0-9A-Za-z]{1}[0-9A-Za-z_-]{0,127}$`), + "must be up to 128 letters (uppercase and lowercase), numbers, underscores and dashes, and must start with an alphanumeric"), + }, + }, + "compute_environments": schema.ListAttribute{ + ElementType: types.StringType, + Required: true, + }, + names.AttrPriority: schema.Int64Attribute{ + Required: true, + }, + "scheduling_policy_arn": schema.StringAttribute{ + CustomType: fwtypes.ARNType, + Optional: true, + }, + names.AttrState: schema.StringAttribute{ + Required: true, + Validators: []validator.String{ + enum.FrameworkValidateIgnoreCase[awstypes.JQState](), + }, + }, + names.AttrTags: tftags.TagsAttribute(), + names.AttrTagsAll: tftags.TagsAttributeComputedOnly(), + }, + Blocks: map[string]schema.Block{ + names.AttrTimeouts: timeouts.Block(ctx, timeouts.Opts{ + Create: true, + Update: true, + Delete: true, + }), + "compute_environment_order": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[computeEnvironmentOrderModel](ctx), + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "compute_environment": schema.StringAttribute{ + CustomType: fwtypes.ARNType, + Required: true, + }, + "order": schema.Int64Attribute{ + Required: true, + }, + }, + }, + }, + "job_state_time_limit_action": schema.ListNestedBlock{ + CustomType: fwtypes.NewListNestedObjectTypeOf[jobStateTimeLimitActionModel](ctx), + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + names.AttrAction: schema.StringAttribute{ + CustomType: fwtypes.StringEnumType[awstypes.JobStateTimeLimitActionsAction](), + Required: true, + }, + "max_time_seconds": schema.Int64Attribute{ + Required: true, + Validators: []validator.Int64{ + int64validator.Between(600, 86400), + }, + }, + "reason": schema.StringAttribute{ + Required: true, + }, + names.AttrState: schema.StringAttribute{ + CustomType: fwtypes.StringEnumType[awstypes.JobStateTimeLimitActionsState](), + Required: true, + }, + }, + }, + }, + }, + } +} + +type resourceJobQueueDataV1 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"` + 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 tftags.Map `tfsdk:"tags"` + TagsAll tftags.Map `tfsdk:"tags_all"` + Timeouts timeouts.Value `tfsdk:"timeouts"` +} + func upgradeJobQueueResourceStateV0toV1(ctx context.Context, request resource.UpgradeStateRequest, response *resource.UpgradeStateResponse) { type resourceJobQueueDataV0 struct { ComputeEnvironments types.List `tfsdk:"compute_environments"` @@ -71,7 +178,7 @@ func upgradeJobQueueResourceStateV0toV1(ctx context.Context, request resource.Up return } - jobQueueDataV1 := jobQueueResourceModel{ + jobQueueDataV1 := resourceJobQueueDataV1{ ComputeEnvironments: jobQueueDataV0.ComputeEnvironments, ComputeEnvironmentOrder: fwtypes.NewListNestedObjectValueOfNull[computeEnvironmentOrderModel](ctx), ID: jobQueueDataV0.ID, @@ -91,3 +198,44 @@ func upgradeJobQueueResourceStateV0toV1(ctx context.Context, request resource.Up response.Diagnostics.Append(response.State.Set(ctx, jobQueueDataV1)...) } + +func upgradeJobQueueResourceStateV1toV2(ctx context.Context, request resource.UpgradeStateRequest, response *resource.UpgradeStateResponse) { + var jobQueueDataV1 resourceJobQueueDataV1 + response.Diagnostics.Append(request.State.Get(ctx, &jobQueueDataV1)...) + if response.Diagnostics.HasError() { + return + } + + jobQueueDataV2 := jobQueueResourceModel{ + ComputeEnvironmentOrder: jobQueueDataV1.ComputeEnvironmentOrder, + ID: jobQueueDataV1.ID, + JobQueueARN: jobQueueDataV1.JobQueueARN, + JobQueueName: jobQueueDataV1.JobQueueName, + JobStateTimeLimitActions: jobQueueDataV1.JobStateTimeLimitActions, + Priority: jobQueueDataV1.Priority, + State: jobQueueDataV1.State, + Tags: jobQueueDataV1.Tags, + TagsAll: jobQueueDataV1.TagsAll, + Timeouts: jobQueueDataV1.Timeouts, + SchedulingPolicyARN: jobQueueDataV1.SchedulingPolicyARN, + } + + if !jobQueueDataV1.ComputeEnvironments.IsNull() { + var computeEnvironments []string + diags := jobQueueDataV1.ComputeEnvironments.ElementsAs(ctx, &computeEnvironments, false) + response.Diagnostics.Append(diags...) + if response.Diagnostics.HasError() { + return + } + computeEnvironmentOrder := make([]*computeEnvironmentOrderModel, len(computeEnvironments)) + for i, env := range computeEnvironments { + computeEnvironmentOrder[i] = &computeEnvironmentOrderModel{ + ComputeEnvironment: fwtypes.ARNValue(env), + Order: types.Int64Value(int64(i)), + } + } + jobQueueDataV2.ComputeEnvironmentOrder = fwtypes.NewListNestedObjectValueOfSliceMust(ctx, computeEnvironmentOrder) + } + + response.Diagnostics.Append(response.State.Set(ctx, jobQueueDataV2)...) +} diff --git a/internal/service/batch/job_queue_migration_test.go b/internal/service/batch/job_queue_migration_test.go new file mode 100644 index 000000000000..f8a1f3c7831a --- /dev/null +++ b/internal/service/batch/job_queue_migration_test.go @@ -0,0 +1,84 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package batch_test + +import ( + "fmt" + "testing" + + awstypes "github.com/aws/aws-sdk-go-v2/service/batch/types" + sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func TestAccBatchJobQueue_migrateFromComputeEnvironments(t *testing.T) { + + ctx := acctest.Context(t) + var jobQueue1 awstypes.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), + CheckDestroy: testAccCheckJobQueueDestroy(ctx), + Steps: []resource.TestStep{ + { + ExternalProviders: map[string]resource.ExternalProvider{ + "aws": { + Source: "hashicorp/aws", + VersionConstraint: "5.23.0", + }, + }, + Config: testAccJobQueueConfig_computeEnvironments_initial(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), + ), + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Config: testAccJobQueueConfig_computeEnvironments_updated(rName), + PlanOnly: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Config: testAccJobQueueConfig_computeEnvironments_updated(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), + ), + }, + }, + }) +} + +func testAccJobQueueConfig_computeEnvironments_initial(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 = "ENABLED" +} +`, rName)) +} + +func testAccJobQueueConfig_computeEnvironments_updated(rName string) string { + return acctest.ConfigCompose( + testAccJobQueueConfig_base(rName), + fmt.Sprintf(` +resource "aws_batch_job_queue" "test" { + compute_environment_order { + compute_environment = aws_batch_compute_environment.test.arn + order = 0 + } + name = %[1]q + priority = 1 + state = "ENABLED" +} +`, rName)) +} diff --git a/internal/service/batch/job_queue_test.go b/internal/service/batch/job_queue_test.go index 9f120ef20cc9..0b89d887b237 100644 --- a/internal/service/batch/job_queue_test.go +++ b/internal/service/batch/job_queue_test.go @@ -21,18 +21,6 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -// ComputeEnvironments has been deprecated. The Import step of tests that use ComputeEnvironments -// need to ignore -var ignoreDeprecatedCEOForImports = []string{ - "compute_environment_order", - "compute_environment_order.#", - "compute_environment_order.0.%", - "compute_environment_order.0.compute_environment", - "compute_environment_order.0.order", - "compute_environments.#", - "compute_environments.0", -} - func TestAccBatchJobQueue_basic(t *testing.T) { ctx := acctest.Context(t) var jobQueue1 awstypes.JobQueueDetail @@ -48,45 +36,11 @@ func TestAccBatchJobQueue_basic(t *testing.T) { { Config: testAccJobQueueConfig_state(rName, string(awstypes.JQStateEnabled)), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), - acctest.CheckResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "batch", fmt.Sprintf("job-queue/%s", rName)), - resource.TestCheckResourceAttr(resourceName, "compute_environments.#", "1"), - resource.TestCheckResourceAttrPair(resourceName, "compute_environments.0", "aws_batch_compute_environment.test", names.AttrARN), - resource.TestCheckResourceAttr(resourceName, "job_state_time_limit_action.#", "0"), - resource.TestCheckResourceAttr(resourceName, names.AttrName, rName), - resource.TestCheckResourceAttr(resourceName, names.AttrPriority, "1"), - resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.JQStateEnabled)), - resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "0"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccBatchJobQueue_basicCEO(t *testing.T) { - ctx := acctest.Context(t) - var jobQueue1 awstypes.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: testAccJobQueueConfig_stateCEO(rName, string(awstypes.JQStateEnabled)), - Check: resource.ComposeTestCheckFunc( testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), acctest.CheckResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "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", names.AttrARN), + resource.TestCheckResourceAttr(resourceName, "job_state_time_limit_action.#", "0"), resource.TestCheckResourceAttr(resourceName, names.AttrName, rName), resource.TestCheckResourceAttr(resourceName, names.AttrPriority, "1"), resource.TestCheckResourceAttr(resourceName, names.AttrState, string(awstypes.JQStateEnabled)), @@ -94,10 +48,9 @@ func TestAccBatchJobQueue_basicCEO(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: ignoreDeprecatedCEOForImports, + ResourceName: resourceName, + RefreshState: true, + PlanOnly: true, }, }, }) @@ -127,65 +80,6 @@ func TestAccBatchJobQueue_disappears(t *testing.T) { }) } -func TestAccBatchJobQueue_disappearsCEO(t *testing.T) { - ctx := acctest.Context(t) - var jobQueue1 awstypes.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: testAccJobQueueConfig_stateCEO(rName, string(awstypes.JQStateEnabled)), - Check: resource.ComposeTestCheckFunc( - testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), - acctest.CheckFrameworkResourceDisappears(ctx, acctest.Provider, tfbatch.ResourceJobQueue, resourceName), - ), - ExpectNonEmptyPlan: true, - }, - }, - }) -} - -func TestAccBatchJobQueue_MigrateFromPluginSDK(t *testing.T) { - ctx := acctest.Context(t) - var jobQueue1 awstypes.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), - CheckDestroy: testAccCheckJobQueueDestroy(ctx), - Steps: []resource.TestStep{ - { - ExternalProviders: map[string]resource.ExternalProvider{ - "aws": { - Source: "hashicorp/aws", - VersionConstraint: "5.13.1", - }, - }, - Config: testAccJobQueueConfig_state(rName, string(awstypes.JQStateEnabled)), - Check: resource.ComposeTestCheckFunc( - testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), - acctest.CheckResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "batch", fmt.Sprintf("job-queue/%s", rName)), - ), - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Config: testAccJobQueueConfig_state(rName, string(awstypes.JQStateEnabled)), - Check: resource.ComposeTestCheckFunc( - testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), - ), - }, - }, - }) -} - func TestAccBatchJobQueue_ComputeEnvironments_multiple(t *testing.T) { ctx := acctest.Context(t) var jobQueue1 awstypes.JobQueueDetail @@ -202,10 +96,10 @@ func TestAccBatchJobQueue_ComputeEnvironments_multiple(t *testing.T) { Config: testAccJobQueueConfig_ComputeEnvironments_multiple(rName, string(awstypes.JQStateEnabled)), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), - resource.TestCheckResourceAttr(resourceName, "compute_environments.#", "3"), - resource.TestCheckResourceAttrPair(resourceName, "compute_environments.0", "aws_batch_compute_environment.test", names.AttrARN), - resource.TestCheckResourceAttrPair(resourceName, "compute_environments.1", "aws_batch_compute_environment.more.0", names.AttrARN), - resource.TestCheckResourceAttrPair(resourceName, "compute_environments.2", "aws_batch_compute_environment.more.1", names.AttrARN), + resource.TestCheckResourceAttr(resourceName, "compute_environment_order.#", "3"), + resource.TestCheckResourceAttrPair(resourceName, "compute_environment_order.0.compute_environment", "aws_batch_compute_environment.test", names.AttrARN), + resource.TestCheckResourceAttrPair(resourceName, "compute_environment_order.1.compute_environment", "aws_batch_compute_environment.more.0", names.AttrARN), + resource.TestCheckResourceAttrPair(resourceName, "compute_environment_order.2.compute_environment", "aws_batch_compute_environment.more.1", names.AttrARN), ), }, { @@ -217,10 +111,10 @@ func TestAccBatchJobQueue_ComputeEnvironments_multiple(t *testing.T) { Config: testAccJobQueueConfig_ComputeEnvironments_multipleReorder(rName, string(awstypes.JQStateEnabled)), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), - resource.TestCheckResourceAttr(resourceName, "compute_environments.#", "3"), - resource.TestCheckResourceAttrPair(resourceName, "compute_environments.0", "aws_batch_compute_environment.more.0", names.AttrARN), - resource.TestCheckResourceAttrPair(resourceName, "compute_environments.1", "aws_batch_compute_environment.test", names.AttrARN), - resource.TestCheckResourceAttrPair(resourceName, "compute_environments.2", "aws_batch_compute_environment.more.1", names.AttrARN), + resource.TestCheckResourceAttr(resourceName, "compute_environment_order.#", "3"), + resource.TestCheckResourceAttrPair(resourceName, "compute_environment_order.0.compute_environment", "aws_batch_compute_environment.more.0", names.AttrARN), + resource.TestCheckResourceAttrPair(resourceName, "compute_environment_order.1.compute_environment", "aws_batch_compute_environment.test", names.AttrARN), + resource.TestCheckResourceAttrPair(resourceName, "compute_environment_order.2.compute_environment", "aws_batch_compute_environment.more.1", names.AttrARN), ), }, { @@ -473,7 +367,6 @@ func testAccCheckJobQueueDestroy(ctx context.Context) resource.TestCheckFunc { } conn := acctest.Provider.Meta().(*conns.AWSClient).BatchClient(ctx) - _, err := tfbatch.FindJobQueueByID(ctx, conn, rs.Primary.ID) if tfresource.NotFound(err) { @@ -509,8 +402,8 @@ func testAccCheckJobQueueComputeEnvironmentOrderUpdate(ctx context.Context, jobQ return fmt.Errorf("expected one ComputeEnvironmentOrder in Batch Job Queue (%s)", name) } - if aws.ToInt32(input.ComputeEnvironmentOrder[0].Order) != 0 { - return fmt.Errorf("expected first ComputeEnvironmentOrder in Batch Job Queue (%s) to have existing Order value of 0", name) + if aws.ToInt32(input.ComputeEnvironmentOrder[0].Order) != 1 { + return fmt.Errorf("expected first ComputeEnvironmentOrder in Batch Job Queue (%s) to have existing Order value of 1", name) } input.ComputeEnvironmentOrder[0].Order = aws.Int32(1) @@ -632,10 +525,13 @@ func testAccJobQueueConfig_priority(rName string, priority int) string { testAccJobQueueConfig_base(rName), fmt.Sprintf(` resource "aws_batch_job_queue" "test" { - compute_environments = [aws_batch_compute_environment.test.arn] - name = %[1]q - priority = %[2]d - state = "ENABLED" + compute_environment_order { + compute_environment = aws_batch_compute_environment.test.arn + order = 1 + } + name = %[1]q + priority = %[2]d + state = "ENABLED" } `, rName, priority)) } @@ -682,7 +578,10 @@ locals { } resource "aws_batch_job_queue" "test" { - compute_environments = [aws_batch_compute_environment.test.arn] + compute_environment_order { + compute_environment = aws_batch_compute_environment.test.arn + order = 1 + } name = %[1]q priority = 1 scheduling_policy_arn = local.select_scheduling_policy == "first" ? aws_batch_scheduling_policy.test1.arn : aws_batch_scheduling_policy.test2.arn @@ -695,20 +594,6 @@ func testAccJobQueueConfig_state(rName string, state 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 = %[2]q -} -`, rName, state)) -} - -func testAccJobQueueConfig_stateCEO(rName string, state string) string { - return acctest.ConfigCompose( - testAccJobQueueConfig_base(rName), - fmt.Sprintf(` resource "aws_batch_job_queue" "test" { compute_environment_order { compute_environment = aws_batch_compute_environment.test.arn @@ -727,10 +612,16 @@ func testAccJobQueueConfig_ComputeEnvironments_multiple(rName string, state stri testAccJobQueueConfig_base(rName), fmt.Sprintf(` resource "aws_batch_job_queue" "test" { - compute_environments = concat( - [aws_batch_compute_environment.test.arn], - aws_batch_compute_environment.more[*].arn, - ) + dynamic "compute_environment_order" { + for_each = concat( + [aws_batch_compute_environment.test.arn], + aws_batch_compute_environment.more[*].arn, + ) + content { + compute_environment = compute_environment_order.value + order = compute_environment_order.key + 1 + } + } name = %[1]q priority = 1 state = %[2]q @@ -810,11 +701,18 @@ func testAccJobQueueConfig_ComputeEnvironments_multipleReorder(rName string, sta testAccJobQueueConfig_base(rName), fmt.Sprintf(` resource "aws_batch_job_queue" "test" { - compute_environments = [ - aws_batch_compute_environment.more[0].arn, - aws_batch_compute_environment.test.arn, - aws_batch_compute_environment.more[1].arn, - ] + compute_environment_order { + compute_environment = aws_batch_compute_environment.more[0].arn + order = 1 + } + compute_environment_order { + compute_environment = aws_batch_compute_environment.test.arn + order = 2 + } + compute_environment_order { + compute_environment = aws_batch_compute_environment.more[1].arn + order = 3 + } name = %[1]q priority = 1 state = %[2]q @@ -847,10 +745,14 @@ func testAccJobQueueConfig_jobStateTimeLimitAction(rName string) string { 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" + compute_environment_order { + compute_environment = aws_batch_compute_environment.test.arn + order = 1 + } + + name = %[1]q + priority = 1 + state = "DISABLED" job_state_time_limit_action { action = "CANCEL" max_time_seconds = 600 @@ -872,10 +774,13 @@ func testAccJobQueueConfig_jobStateTimeLimitActionUpdated(rName string) string { 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" + compute_environment_order { + compute_environment = aws_batch_compute_environment.test.arn + order = 1 + } + name = %[1]q + priority = 1 + state = "DISABLED" job_state_time_limit_action { action = "CANCEL" max_time_seconds = 610 diff --git a/internal/service/batch/testdata/JobQueue/data.tags/main_gen.tf b/internal/service/batch/testdata/JobQueue/data.tags/main_gen.tf index 67c626ff83b4..e1137c2666da 100644 --- a/internal/service/batch/testdata/JobQueue/data.tags/main_gen.tf +++ b/internal/service/batch/testdata/JobQueue/data.tags/main_gen.tf @@ -11,7 +11,10 @@ resource "aws_batch_job_queue" "test" { priority = 1 state = "DISABLED" - compute_environments = [aws_batch_compute_environment.test.arn] + compute_environment_order { + compute_environment = aws_batch_compute_environment.test.arn + order = 1 + } tags = var.resource_tags } diff --git a/internal/service/batch/testdata/JobQueue/data.tags_defaults/main_gen.tf b/internal/service/batch/testdata/JobQueue/data.tags_defaults/main_gen.tf index 046ee220cb74..306cc943f484 100644 --- a/internal/service/batch/testdata/JobQueue/data.tags_defaults/main_gen.tf +++ b/internal/service/batch/testdata/JobQueue/data.tags_defaults/main_gen.tf @@ -17,7 +17,10 @@ resource "aws_batch_job_queue" "test" { priority = 1 state = "DISABLED" - compute_environments = [aws_batch_compute_environment.test.arn] + compute_environment_order { + compute_environment = aws_batch_compute_environment.test.arn + order = 1 + } tags = var.resource_tags } diff --git a/internal/service/batch/testdata/JobQueue/data.tags_ignore/main_gen.tf b/internal/service/batch/testdata/JobQueue/data.tags_ignore/main_gen.tf index 609983284d8f..9ad2943f853e 100644 --- a/internal/service/batch/testdata/JobQueue/data.tags_ignore/main_gen.tf +++ b/internal/service/batch/testdata/JobQueue/data.tags_ignore/main_gen.tf @@ -20,7 +20,10 @@ resource "aws_batch_job_queue" "test" { priority = 1 state = "DISABLED" - compute_environments = [aws_batch_compute_environment.test.arn] + compute_environment_order { + compute_environment = aws_batch_compute_environment.test.arn + order = 1 + } tags = var.resource_tags } diff --git a/internal/service/batch/testdata/JobQueue/tags/main_gen.tf b/internal/service/batch/testdata/JobQueue/tags/main_gen.tf index effb5d30130b..21e89217761b 100644 --- a/internal/service/batch/testdata/JobQueue/tags/main_gen.tf +++ b/internal/service/batch/testdata/JobQueue/tags/main_gen.tf @@ -6,7 +6,10 @@ resource "aws_batch_job_queue" "test" { priority = 1 state = "DISABLED" - compute_environments = [aws_batch_compute_environment.test.arn] + compute_environment_order { + compute_environment = aws_batch_compute_environment.test.arn + order = 1 + } tags = var.resource_tags } diff --git a/internal/service/batch/testdata/JobQueue/tagsComputed1/main_gen.tf b/internal/service/batch/testdata/JobQueue/tagsComputed1/main_gen.tf index 02127f0e17ec..e4a528791b85 100644 --- a/internal/service/batch/testdata/JobQueue/tagsComputed1/main_gen.tf +++ b/internal/service/batch/testdata/JobQueue/tagsComputed1/main_gen.tf @@ -8,7 +8,10 @@ resource "aws_batch_job_queue" "test" { priority = 1 state = "DISABLED" - compute_environments = [aws_batch_compute_environment.test.arn] + compute_environment_order { + compute_environment = aws_batch_compute_environment.test.arn + order = 1 + } tags = { (var.unknownTagKey) = null_resource.test.id diff --git a/internal/service/batch/testdata/JobQueue/tagsComputed2/main_gen.tf b/internal/service/batch/testdata/JobQueue/tagsComputed2/main_gen.tf index f7c86410ecee..1f791bf8c5bf 100644 --- a/internal/service/batch/testdata/JobQueue/tagsComputed2/main_gen.tf +++ b/internal/service/batch/testdata/JobQueue/tagsComputed2/main_gen.tf @@ -8,7 +8,10 @@ resource "aws_batch_job_queue" "test" { priority = 1 state = "DISABLED" - compute_environments = [aws_batch_compute_environment.test.arn] + compute_environment_order { + compute_environment = aws_batch_compute_environment.test.arn + order = 1 + } tags = { (var.unknownTagKey) = null_resource.test.id diff --git a/internal/service/batch/testdata/JobQueue/tags_defaults/main_gen.tf b/internal/service/batch/testdata/JobQueue/tags_defaults/main_gen.tf index 2e2f1eff2014..3756df02f264 100644 --- a/internal/service/batch/testdata/JobQueue/tags_defaults/main_gen.tf +++ b/internal/service/batch/testdata/JobQueue/tags_defaults/main_gen.tf @@ -12,7 +12,10 @@ resource "aws_batch_job_queue" "test" { priority = 1 state = "DISABLED" - compute_environments = [aws_batch_compute_environment.test.arn] + compute_environment_order { + compute_environment = aws_batch_compute_environment.test.arn + order = 1 + } tags = var.resource_tags } diff --git a/internal/service/batch/testdata/JobQueue/tags_ignore/main_gen.tf b/internal/service/batch/testdata/JobQueue/tags_ignore/main_gen.tf index 8ffe18afbe53..2735f2b9c829 100644 --- a/internal/service/batch/testdata/JobQueue/tags_ignore/main_gen.tf +++ b/internal/service/batch/testdata/JobQueue/tags_ignore/main_gen.tf @@ -15,7 +15,10 @@ resource "aws_batch_job_queue" "test" { priority = 1 state = "DISABLED" - compute_environments = [aws_batch_compute_environment.test.arn] + compute_environment_order { + compute_environment = aws_batch_compute_environment.test.arn + order = 1 + } tags = var.resource_tags } diff --git a/internal/service/batch/testdata/tmpl/job_queue_tags.gtpl b/internal/service/batch/testdata/tmpl/job_queue_tags.gtpl index 139fbd359134..0603f46a9519 100644 --- a/internal/service/batch/testdata/tmpl/job_queue_tags.gtpl +++ b/internal/service/batch/testdata/tmpl/job_queue_tags.gtpl @@ -3,7 +3,11 @@ resource "aws_batch_job_queue" "test" { priority = 1 state = "DISABLED" - compute_environments = [aws_batch_compute_environment.test.arn] + compute_environment_order { + compute_environment = aws_batch_compute_environment.test.arn + order = 1 + } + {{- template "tags" . }} } diff --git a/internal/service/events/target_test.go b/internal/service/events/target_test.go index 7d5af4f9c8af..d3df084d4d98 100644 --- a/internal/service/events/target_test.go +++ b/internal/service/events/target_test.go @@ -2335,10 +2335,14 @@ resource "aws_batch_compute_environment" "test" { } resource "aws_batch_job_queue" "test" { - name = "%[1]s" - state = "ENABLED" - priority = 1 - compute_environments = [aws_batch_compute_environment.test.arn] + name = "%[1]s" + state = "ENABLED" + priority = 1 + compute_environment_order { + compute_environment = aws_batch_compute_environment.test.arn + order = 1 + } + } resource "aws_batch_job_definition" "test" { diff --git a/internal/service/pipes/pipe_test.go b/internal/service/pipes/pipe_test.go index ed7240b270e8..db5af00ca7ba 100644 --- a/internal/service/pipes/pipe_test.go +++ b/internal/service/pipes/pipe_test.go @@ -3262,10 +3262,14 @@ resource "aws_batch_compute_environment" "target" { } resource "aws_batch_job_queue" "target" { - compute_environments = [aws_batch_compute_environment.target.arn] - name = "%[1]s-target" - priority = 1 - state = "ENABLED" + compute_environment_order { + compute_environment = aws_batch_compute_environment.target.arn + order = 1 + } + + name = "%[1]s-target" + priority = 1 + state = "ENABLED" } resource "aws_batch_job_definition" "target" { diff --git a/website/docs/cdktf/python/r/batch_job_queue.html.markdown b/website/docs/cdktf/python/r/batch_job_queue.html.markdown index d3fbb8bcca03..b7169152989e 100644 --- a/website/docs/cdktf/python/r/batch_job_queue.html.markdown +++ b/website/docs/cdktf/python/r/batch_job_queue.html.markdown @@ -93,7 +93,6 @@ class MyConvertedCode(TerraformStack): 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 @@ -154,4 +153,4 @@ Using `terraform import`, import Batch Job Queue using the `arn`. For example: % terraform import aws_batch_job_queue.test_queue arn:aws:batch:us-east-1:123456789012:job-queue/sample ``` - \ No newline at end of file + diff --git a/website/docs/r/batch_job_queue.html.markdown b/website/docs/r/batch_job_queue.html.markdown index a16dda17c70e..e51b69982462 100644 --- a/website/docs/r/batch_job_queue.html.markdown +++ b/website/docs/r/batch_job_queue.html.markdown @@ -73,7 +73,6 @@ resource "aws_batch_job_queue" "example" { 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 From 3dad91fe86be33354e9a556fce5c7ff1fe910314 Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush <25692880+danquack@users.noreply.github.com> Date: Thu, 2 Jan 2025 15:14:31 -0500 Subject: [PATCH 02/13] :memo: changelog --- .changelog/40751.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/40751.txt diff --git a/.changelog/40751.txt b/.changelog/40751.txt new file mode 100644 index 000000000000..b0383095a23c --- /dev/null +++ b/.changelog/40751.txt @@ -0,0 +1,3 @@ +```release-note:breaking-change +resource/aws_batch_job_queue: Remove deprecated parameter `compute_environments` in place of `compute_environment_order` +``` From bf8c04dd15f591cad3ca4c106d38a3fb8e4d195b Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush <25692880+danquack@users.noreply.github.com> Date: Thu, 2 Jan 2025 15:20:17 -0500 Subject: [PATCH 03/13] :wastebasket: remove dead code --- internal/service/batch/job_queue.go | 26 ------------------- .../service/batch/job_queue_migration_test.go | 1 - 2 files changed, 27 deletions(-) diff --git a/internal/service/batch/job_queue.go b/internal/service/batch/job_queue.go index 1b11a1cf31ae..78db83307343 100644 --- a/internal/service/batch/job_queue.go +++ b/internal/service/batch/job_queue.go @@ -4,11 +4,9 @@ package batch import ( - "cmp" "context" "errors" "fmt" - "slices" "time" "github.com/YakDriver/regexache" @@ -32,7 +30,6 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/framework" 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" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" @@ -542,26 +539,3 @@ type jobStateTimeLimitActionModel struct { 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 - - for i, env := range fwflex.ExpandFrameworkStringList(ctx, tfList) { - apiObjects = append(apiObjects, awstypes.ComputeEnvironmentOrder{ - ComputeEnvironment: env, - Order: aws.Int32(int32(i)), - }) - } - - return apiObjects -} - -func flattenComputeEnvironments(ctx context.Context, apiObjects []awstypes.ComputeEnvironmentOrder) types.List { - slices.SortFunc(apiObjects, func(a, b awstypes.ComputeEnvironmentOrder) int { - return cmp.Compare(aws.ToInt32(a.Order), aws.ToInt32(b.Order)) - }) - - return fwflex.FlattenFrameworkStringListLegacy(ctx, tfslices.ApplyToAll(apiObjects, func(v awstypes.ComputeEnvironmentOrder) *string { - return v.ComputeEnvironment - })) -} diff --git a/internal/service/batch/job_queue_migration_test.go b/internal/service/batch/job_queue_migration_test.go index f8a1f3c7831a..3d9850c907fe 100644 --- a/internal/service/batch/job_queue_migration_test.go +++ b/internal/service/batch/job_queue_migration_test.go @@ -15,7 +15,6 @@ import ( ) func TestAccBatchJobQueue_migrateFromComputeEnvironments(t *testing.T) { - ctx := acctest.Context(t) var jobQueue1 awstypes.JobQueueDetail resourceName := "aws_batch_job_queue.test" From ab1de2a101deaead335df125e0cbc983447a6020 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 28 Apr 2025 14:43:30 -0400 Subject: [PATCH 04/13] Fix places still using compute_environment_name --- CHANGELOG.md | 1 - internal/service/batch/job_queue_test.go | 24 +++++++++---------- .../testdata/JobQueue/data.tags/main_gen.tf | 6 ++--- .../JobQueue/data.tags_defaults/main_gen.tf | 6 ++--- .../JobQueue/data.tags_ignore/main_gen.tf | 6 ++--- .../batch/testdata/JobQueue/tags/main_gen.tf | 6 ++--- .../JobQueue/tagsComputed1/main_gen.tf | 6 ++--- .../JobQueue/tagsComputed2/main_gen.tf | 6 ++--- .../JobQueue/tags_defaults/main_gen.tf | 6 ++--- .../testdata/JobQueue/tags_ignore/main_gen.tf | 6 ++--- .../batch/testdata/tmpl/job_queue_tags.gtpl | 6 ++--- internal/service/ecs/tag_test.go | 6 ++--- internal/service/events/target_test.go | 2 +- internal/service/pipes/pipe_test.go | 6 ++--- .../d/batch_compute_environment.html.markdown | 4 ++-- .../r/batch_compute_environment.html.markdown | 14 +++++------ website/docs/r/ecs_tag.html.markdown | 6 ++--- 17 files changed, 58 insertions(+), 59 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0d4668e892e..ef0072774fd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -203,7 +203,6 @@ BUG FIXES: * resource/aws_sns_topic_subscription: Fix to handle eventually consistent subscription read operations ([#42093](https://github.com/hashicorp/terraform-provider-aws/issues/42093)) * resource/aws_sqs_queue: Fix `waiting for SQS Queue... attributes create: timeout while waiting` errors when `sqs_managed_sse_enabled = false` or omitted and `kms_master_key_id` is not set but `kms_data_key_reuse_period_seconds` is set to a non-default value. ([#42062](https://github.com/hashicorp/terraform-provider-aws/issues/42062)) * resource/aws_workspaces_workspace: Properly update `workspace_properties.running_mode_auto_stop_timeout_in_minutes` when modified ([#40953](https://github.com/hashicorp/terraform-provider-aws/issues/40953)) ->>>>>>> v5.94.0 ## 5.93.0 (March 27, 2025) diff --git a/internal/service/batch/job_queue_test.go b/internal/service/batch/job_queue_test.go index 0b89d887b237..6c33c80cfcf4 100644 --- a/internal/service/batch/job_queue_test.go +++ b/internal/service/batch/job_queue_test.go @@ -501,9 +501,9 @@ resource "aws_subnet" "test" { } resource "aws_batch_compute_environment" "test" { - compute_environment_name = %[1]q - service_role = aws_iam_role.test.arn - type = "MANAGED" + name = %[1]q + service_role = aws_iam_role.test.arn + type = "MANAGED" compute_resources { instance_role = aws_iam_instance_profile.ecs_instance_role.arn @@ -630,9 +630,9 @@ resource "aws_batch_job_queue" "test" { resource "aws_batch_compute_environment" "more" { count = 2 - compute_environment_name = "%[1]s-${count.index + 1}" - service_role = aws_iam_role.test.arn - type = "MANAGED" + name = "%[1]s-${count.index + 1}" + service_role = aws_iam_role.test.arn + type = "MANAGED" compute_resources { instance_role = aws_iam_instance_profile.ecs_instance_role.arn @@ -677,9 +677,9 @@ resource "aws_batch_job_queue" "test" { resource "aws_batch_compute_environment" "more" { count = 2 - compute_environment_name = "%[1]s-${count.index + 1}" - service_role = aws_iam_role.test.arn - type = "MANAGED" + name = "%[1]s-${count.index + 1}" + service_role = aws_iam_role.test.arn + type = "MANAGED" compute_resources { instance_role = aws_iam_instance_profile.ecs_instance_role.arn @@ -721,9 +721,9 @@ resource "aws_batch_job_queue" "test" { resource "aws_batch_compute_environment" "more" { count = 2 - compute_environment_name = "%[1]s-${count.index + 1}" - service_role = aws_iam_role.test.arn - type = "MANAGED" + name = "%[1]s-${count.index + 1}" + service_role = aws_iam_role.test.arn + type = "MANAGED" compute_resources { instance_role = aws_iam_instance_profile.ecs_instance_role.arn diff --git a/internal/service/batch/testdata/JobQueue/data.tags/main_gen.tf b/internal/service/batch/testdata/JobQueue/data.tags/main_gen.tf index e1137c2666da..2af86694eb16 100644 --- a/internal/service/batch/testdata/JobQueue/data.tags/main_gen.tf +++ b/internal/service/batch/testdata/JobQueue/data.tags/main_gen.tf @@ -20,9 +20,9 @@ resource "aws_batch_job_queue" "test" { } resource "aws_batch_compute_environment" "test" { - compute_environment_name = var.rName - service_role = aws_iam_role.batch_service.arn - type = "UNMANAGED" + name = var.rName + service_role = aws_iam_role.batch_service.arn + type = "UNMANAGED" depends_on = [aws_iam_role_policy_attachment.batch_service] } diff --git a/internal/service/batch/testdata/JobQueue/data.tags_defaults/main_gen.tf b/internal/service/batch/testdata/JobQueue/data.tags_defaults/main_gen.tf index 306cc943f484..197154fbc343 100644 --- a/internal/service/batch/testdata/JobQueue/data.tags_defaults/main_gen.tf +++ b/internal/service/batch/testdata/JobQueue/data.tags_defaults/main_gen.tf @@ -26,9 +26,9 @@ resource "aws_batch_job_queue" "test" { } resource "aws_batch_compute_environment" "test" { - compute_environment_name = var.rName - service_role = aws_iam_role.batch_service.arn - type = "UNMANAGED" + name = var.rName + service_role = aws_iam_role.batch_service.arn + type = "UNMANAGED" depends_on = [aws_iam_role_policy_attachment.batch_service] } diff --git a/internal/service/batch/testdata/JobQueue/data.tags_ignore/main_gen.tf b/internal/service/batch/testdata/JobQueue/data.tags_ignore/main_gen.tf index 9ad2943f853e..4b816a8c6547 100644 --- a/internal/service/batch/testdata/JobQueue/data.tags_ignore/main_gen.tf +++ b/internal/service/batch/testdata/JobQueue/data.tags_ignore/main_gen.tf @@ -29,9 +29,9 @@ resource "aws_batch_job_queue" "test" { } resource "aws_batch_compute_environment" "test" { - compute_environment_name = var.rName - service_role = aws_iam_role.batch_service.arn - type = "UNMANAGED" + name = var.rName + service_role = aws_iam_role.batch_service.arn + type = "UNMANAGED" depends_on = [aws_iam_role_policy_attachment.batch_service] } diff --git a/internal/service/batch/testdata/JobQueue/tags/main_gen.tf b/internal/service/batch/testdata/JobQueue/tags/main_gen.tf index 21e89217761b..ac01e903b140 100644 --- a/internal/service/batch/testdata/JobQueue/tags/main_gen.tf +++ b/internal/service/batch/testdata/JobQueue/tags/main_gen.tf @@ -15,9 +15,9 @@ resource "aws_batch_job_queue" "test" { } resource "aws_batch_compute_environment" "test" { - compute_environment_name = var.rName - service_role = aws_iam_role.batch_service.arn - type = "UNMANAGED" + name = var.rName + service_role = aws_iam_role.batch_service.arn + type = "UNMANAGED" depends_on = [aws_iam_role_policy_attachment.batch_service] } diff --git a/internal/service/batch/testdata/JobQueue/tagsComputed1/main_gen.tf b/internal/service/batch/testdata/JobQueue/tagsComputed1/main_gen.tf index e4a528791b85..c6ae55fcd851 100644 --- a/internal/service/batch/testdata/JobQueue/tagsComputed1/main_gen.tf +++ b/internal/service/batch/testdata/JobQueue/tagsComputed1/main_gen.tf @@ -19,9 +19,9 @@ resource "aws_batch_job_queue" "test" { } resource "aws_batch_compute_environment" "test" { - compute_environment_name = var.rName - service_role = aws_iam_role.batch_service.arn - type = "UNMANAGED" + name = var.rName + service_role = aws_iam_role.batch_service.arn + type = "UNMANAGED" depends_on = [aws_iam_role_policy_attachment.batch_service] } diff --git a/internal/service/batch/testdata/JobQueue/tagsComputed2/main_gen.tf b/internal/service/batch/testdata/JobQueue/tagsComputed2/main_gen.tf index 1f791bf8c5bf..c2cad831b22f 100644 --- a/internal/service/batch/testdata/JobQueue/tagsComputed2/main_gen.tf +++ b/internal/service/batch/testdata/JobQueue/tagsComputed2/main_gen.tf @@ -20,9 +20,9 @@ resource "aws_batch_job_queue" "test" { } resource "aws_batch_compute_environment" "test" { - compute_environment_name = var.rName - service_role = aws_iam_role.batch_service.arn - type = "UNMANAGED" + name = var.rName + service_role = aws_iam_role.batch_service.arn + type = "UNMANAGED" depends_on = [aws_iam_role_policy_attachment.batch_service] } diff --git a/internal/service/batch/testdata/JobQueue/tags_defaults/main_gen.tf b/internal/service/batch/testdata/JobQueue/tags_defaults/main_gen.tf index 3756df02f264..f6fefbbb7522 100644 --- a/internal/service/batch/testdata/JobQueue/tags_defaults/main_gen.tf +++ b/internal/service/batch/testdata/JobQueue/tags_defaults/main_gen.tf @@ -21,9 +21,9 @@ resource "aws_batch_job_queue" "test" { } resource "aws_batch_compute_environment" "test" { - compute_environment_name = var.rName - service_role = aws_iam_role.batch_service.arn - type = "UNMANAGED" + name = var.rName + service_role = aws_iam_role.batch_service.arn + type = "UNMANAGED" depends_on = [aws_iam_role_policy_attachment.batch_service] } diff --git a/internal/service/batch/testdata/JobQueue/tags_ignore/main_gen.tf b/internal/service/batch/testdata/JobQueue/tags_ignore/main_gen.tf index 2735f2b9c829..6388870bdb2b 100644 --- a/internal/service/batch/testdata/JobQueue/tags_ignore/main_gen.tf +++ b/internal/service/batch/testdata/JobQueue/tags_ignore/main_gen.tf @@ -24,9 +24,9 @@ resource "aws_batch_job_queue" "test" { } resource "aws_batch_compute_environment" "test" { - compute_environment_name = var.rName - service_role = aws_iam_role.batch_service.arn - type = "UNMANAGED" + name = var.rName + service_role = aws_iam_role.batch_service.arn + type = "UNMANAGED" depends_on = [aws_iam_role_policy_attachment.batch_service] } diff --git a/internal/service/batch/testdata/tmpl/job_queue_tags.gtpl b/internal/service/batch/testdata/tmpl/job_queue_tags.gtpl index 0603f46a9519..e8ae0bdd6ed3 100644 --- a/internal/service/batch/testdata/tmpl/job_queue_tags.gtpl +++ b/internal/service/batch/testdata/tmpl/job_queue_tags.gtpl @@ -12,9 +12,9 @@ resource "aws_batch_job_queue" "test" { } resource "aws_batch_compute_environment" "test" { - compute_environment_name = var.rName - service_role = aws_iam_role.batch_service.arn - type = "UNMANAGED" + name = var.rName + service_role = aws_iam_role.batch_service.arn + type = "UNMANAGED" depends_on = [aws_iam_role_policy_attachment.batch_service] } diff --git a/internal/service/ecs/tag_test.go b/internal/service/ecs/tag_test.go index a8730c22fc2c..5b1bb6972a75 100644 --- a/internal/service/ecs/tag_test.go +++ b/internal/service/ecs/tag_test.go @@ -174,9 +174,9 @@ resource "aws_iam_role_policy_attachment" "test" { } resource "aws_batch_compute_environment" "test" { - compute_environment_name = %[1]q - service_role = aws_iam_role.test.arn - type = "UNMANAGED" + name = %[1]q + service_role = aws_iam_role.test.arn + type = "UNMANAGED" depends_on = [aws_iam_role_policy_attachment.test] } diff --git a/internal/service/events/target_test.go b/internal/service/events/target_test.go index d3df084d4d98..71630c7bca1a 100644 --- a/internal/service/events/target_test.go +++ b/internal/service/events/target_test.go @@ -2306,7 +2306,7 @@ resource "aws_subnet" "subnet" { } resource "aws_batch_compute_environment" "test" { - compute_environment_name = "%[1]s" + name = "%[1]s" compute_resources { instance_role = aws_iam_instance_profile.iam_instance_profile.arn diff --git a/internal/service/pipes/pipe_test.go b/internal/service/pipes/pipe_test.go index d3ccf2be1bf8..099bf4e5a1e3 100644 --- a/internal/service/pipes/pipe_test.go +++ b/internal/service/pipes/pipe_test.go @@ -3315,9 +3315,9 @@ resource "aws_security_group" "target" { } resource "aws_batch_compute_environment" "target" { - compute_environment_name = "%[1]s-target" - service_role = aws_iam_role.target.arn - type = "MANAGED" + name = "%[1]s-target" + service_role = aws_iam_role.target.arn + type = "MANAGED" compute_resources { instance_role = aws_iam_instance_profile.ecs_instance_role.arn diff --git a/website/docs/d/batch_compute_environment.html.markdown b/website/docs/d/batch_compute_environment.html.markdown index b7dae8cd3d45..5473fc8b4102 100644 --- a/website/docs/d/batch_compute_environment.html.markdown +++ b/website/docs/d/batch_compute_environment.html.markdown @@ -15,7 +15,7 @@ compute environment within AWS Batch. ```terraform data "aws_batch_compute_environment" "batch-mongo" { - compute_environment_name = "batch-mongo-production" + name = "batch-mongo-production" } ``` @@ -23,7 +23,7 @@ data "aws_batch_compute_environment" "batch-mongo" { This data source supports the following arguments: -* `compute_environment_name` - (Required) Name of the Batch Compute Environment +* `name` - (Required) Name of the Batch Compute Environment ## Attribute Reference diff --git a/website/docs/r/batch_compute_environment.html.markdown b/website/docs/r/batch_compute_environment.html.markdown index 307db495be9a..94b51fc7b0ed 100644 --- a/website/docs/r/batch_compute_environment.html.markdown +++ b/website/docs/r/batch_compute_environment.html.markdown @@ -98,7 +98,7 @@ resource "aws_placement_group" "sample" { } resource "aws_batch_compute_environment" "sample" { - compute_environment_name = "sample" + name = "sample" compute_resources { instance_role = aws_iam_instance_profile.ecs_instance_role.arn @@ -133,7 +133,7 @@ resource "aws_batch_compute_environment" "sample" { ```hcl resource "aws_batch_compute_environment" "sample" { - compute_environment_name = "sample" + name = "sample" compute_resources { max_vcpus = 16 @@ -159,7 +159,7 @@ resource "aws_batch_compute_environment" "sample" { ```hcl resource "aws_batch_compute_environment" "sample" { - compute_environment_name = "sample" + name = "sample" compute_resources { allocation_strategy = "BEST_FIT_PROGRESSIVE" @@ -187,8 +187,8 @@ resource "aws_batch_compute_environment" "sample" { ## Argument Reference -* `compute_environment_name` - (Optional, Forces new resource) The name for your compute environment. Up to 128 letters (uppercase and lowercase), numbers, and underscores are allowed. If omitted, Terraform will assign a random, unique name. -* `compute_environment_name_prefix` - (Optional, Forces new resource) Creates a unique compute environment name beginning with the specified prefix. Conflicts with `compute_environment_name`. +* `name` - (Optional, Forces new resource) The name for your compute environment. Up to 128 letters (uppercase and lowercase), numbers, and underscores are allowed. If omitted, Terraform will assign a random, unique name. +* `name_prefix` - (Optional, Forces new resource) Creates a unique compute environment name beginning with the specified prefix. Conflicts with `name`. * `compute_resources` - (Optional) Details of the compute resources managed by the compute environment. This parameter is required for managed compute environments. See details below. * `eks_configuration` - (Optional) Details for the Amazon EKS cluster that supports the compute environment. See details below. * `service_role` - (Optional) The full Amazon Resource Name (ARN) of the IAM role that allows AWS Batch to make calls to other AWS services on your behalf. @@ -258,7 +258,7 @@ This resource exports the following attributes in addition to the arguments abov ## Import -In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import AWS Batch compute using the `compute_environment_name`. For example: +In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import AWS Batch compute using the `name`. For example: ```terraform import { @@ -267,7 +267,7 @@ import { } ``` -Using `terraform import`, import AWS Batch compute using the `compute_environment_name`. For example: +Using `terraform import`, import AWS Batch compute using the `name`. For example: ```console % terraform import aws_batch_compute_environment.sample sample diff --git a/website/docs/r/ecs_tag.html.markdown b/website/docs/r/ecs_tag.html.markdown index 233a317f35d0..d1847d42b6d5 100644 --- a/website/docs/r/ecs_tag.html.markdown +++ b/website/docs/r/ecs_tag.html.markdown @@ -18,9 +18,9 @@ Manages an individual ECS resource tag. This resource should only be used in cas ```terraform resource "aws_batch_compute_environment" "example" { - compute_environment_name = "example" - service_role = aws_iam_role.example.arn - type = "UNMANAGED" + name = "example" + service_role = aws_iam_role.example.arn + type = "UNMANAGED" } resource "aws_ecs_tag" "example" { From 3247dcc10c2b289bea12d6d69a3f6f5a3b06dcf3 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 28 Apr 2025 14:52:02 -0400 Subject: [PATCH 05/13] Add guidance to v6 upgrade guide --- website/docs/guides/version-6-upgrade.html.markdown | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/website/docs/guides/version-6-upgrade.html.markdown b/website/docs/guides/version-6-upgrade.html.markdown index dcebbc841e3c..a5829a337ebf 100644 --- a/website/docs/guides/version-6-upgrade.html.markdown +++ b/website/docs/guides/version-6-upgrade.html.markdown @@ -38,6 +38,7 @@ Upgrade topics: - [resource/aws_api_gateway_account](#resourceaws_api_gateway_account) - [resource/aws_api_gateway_deployment](#resourceaws_api_gateway_deployment) - [resource/aws_batch_compute_environment](#resourceaws_batch_compute_environment) +- [resource/aws_batch_job_queue](#resourceaws_batch_job_queue) - [resource/aws_bedrock_model_invocation_logging_configuration](#resourceaws_bedrock_model_invocation_logging_configuration) - [resource/aws_cloudfront_key_value_store](#resourceaws_cloudfront_key_value_store) - [resource/aws_cloudfront_response_headers_policy](#resourceaws_cloudfront_response_headers_policy) @@ -315,6 +316,10 @@ terraform import aws_api_gateway_stage.prod / * `compute_environment_name` has been renamed to `name`. * `compute_environment_name_prefix` has been renamed to `name_prefix`. +## resource/aws_batch_job_queue + +`compute_environments` has been removed. Instead, use `compute_environment_order`. + ## resource/aws_bedrock_model_invocation_logging_configuration The following arguments are now list nested blocks instead of single nested blocks. From c896f75ef219e66b5fccaa65134bac36bf687faf Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 28 Apr 2025 16:33:38 -0400 Subject: [PATCH 06/13] Add missing StateUpgrader for ce --- internal/service/batch/compute_environment.go | 9 + .../batch/compute_environment_migrate.go | 247 ++++++++++++++++++ .../batch/compute_environment_migrate_test.go | 90 +++++++ .../service/batch/compute_environment_test.go | 54 ++++ 4 files changed, 400 insertions(+) create mode 100644 internal/service/batch/compute_environment_migrate.go create mode 100644 internal/service/batch/compute_environment_migrate_test.go diff --git a/internal/service/batch/compute_environment.go b/internal/service/batch/compute_environment.go index 6db3bdb6ac80..25224cd4b4a2 100644 --- a/internal/service/batch/compute_environment.go +++ b/internal/service/batch/compute_environment.go @@ -48,6 +48,15 @@ func resourceComputeEnvironment() *schema.Resource { CustomizeDiff: resourceComputeEnvironmentCustomizeDiff, + SchemaVersion: 1, + StateUpgraders: []schema.StateUpgrader{ + { + Type: computeEnvironmentSchemaV0().CoreConfigSchema().ImpliedType(), + Upgrade: computeEnvironmentStateUpgradeV0, + Version: 0, + }, + }, + Schema: map[string]*schema.Schema{ names.AttrARN: { Type: schema.TypeString, diff --git a/internal/service/batch/compute_environment_migrate.go b/internal/service/batch/compute_environment_migrate.go new file mode 100644 index 000000000000..50375f0254a2 --- /dev/null +++ b/internal/service/batch/compute_environment_migrate.go @@ -0,0 +1,247 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package batch + +import ( + "context" + + awstypes "github.com/aws/aws-sdk-go-v2/service/batch/types" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-aws/internal/sdkv2" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func computeEnvironmentSchemaV0() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + names.AttrARN: { + Type: schema.TypeString, + Computed: true, + }, + "compute_environment_name": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ConflictsWith: []string{"compute_environment_name_prefix"}, + }, + "compute_environment_name_prefix": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + ConflictsWith: []string{"compute_environment_name"}, + }, + "compute_resources": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + MinItems: 0, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "allocation_strategy": { + Type: schema.TypeString, + Optional: true, + StateFunc: sdkv2.ToUpperSchemaStateFunc, + }, + "bid_percentage": { + Type: schema.TypeInt, + Optional: true, + }, + "desired_vcpus": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "ec2_configuration": { + Type: schema.TypeList, + Optional: true, + Computed: true, + ForceNew: true, + MaxItems: 2, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "image_id_override": { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + "image_type": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, + }, + "ec2_key_pair": { + Type: schema.TypeString, + Optional: true, + }, + "image_id": { + Type: schema.TypeString, + Optional: true, + }, + "instance_role": { + Type: schema.TypeString, + Optional: true, + }, + names.AttrInstanceType: { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + names.AttrLaunchTemplate: { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "launch_template_id": { + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"compute_resources.0.launch_template.0.launch_template_name"}, + }, + "launch_template_name": { + Type: schema.TypeString, + Optional: true, + ConflictsWith: []string{"compute_resources.0.launch_template.0.launch_template_id"}, + }, + names.AttrVersion: { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + "max_vcpus": { + Type: schema.TypeInt, + Required: true, + }, + "min_vcpus": { + Type: schema.TypeInt, + Optional: true, + }, + "placement_group": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + names.AttrSecurityGroupIDs: { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "spot_iam_fleet_role": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + names.AttrSubnets: { + Type: schema.TypeSet, + Required: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + names.AttrTags: tftags.TagsSchema(), + names.AttrType: { + Type: schema.TypeString, + Required: true, + StateFunc: sdkv2.ToUpperSchemaStateFunc, + }, + }, + }, + }, + "ecs_cluster_arn": { + Type: schema.TypeString, + Computed: true, + }, + "eks_configuration": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + MinItems: 0, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "eks_cluster_arn": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "kubernetes_namespace": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + }, + }, + }, + names.AttrServiceRole: { + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + names.AttrState: { + Type: schema.TypeString, + Optional: true, + Default: awstypes.CEStateEnabled, + StateFunc: sdkv2.ToUpperSchemaStateFunc, + }, + names.AttrStatus: { + Type: schema.TypeString, + Computed: true, + }, + names.AttrStatusReason: { + Type: schema.TypeString, + Computed: true, + }, + names.AttrTags: tftags.TagsSchema(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), + names.AttrType: { + Type: schema.TypeString, + Required: true, + ForceNew: true, + StateFunc: sdkv2.ToUpperSchemaStateFunc, + }, + "update_policy": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "job_execution_timeout_minutes": { + Type: schema.TypeInt, + Required: true, + }, + "terminate_jobs_on_update": { + Type: schema.TypeBool, + Required: true, + }, + }, + }, + }, + }, + } +} + +func computeEnvironmentStateUpgradeV0(_ context.Context, rawState map[string]any, meta any) (map[string]any, error) { + if rawState == nil { + rawState = map[string]any{} + } + + if v, ok := rawState["compute_environment_name"].(string); ok && v != "" { + rawState["name"] = v + delete(rawState, "compute_environment_name") + } + + if v, ok := rawState["compute_environment_name_prefix"].(string); ok && v != "" { + rawState["name_prefix"] = v + delete(rawState, "compute_environment_name_prefix") + } + + return rawState, nil +} diff --git a/internal/service/batch/compute_environment_migrate_test.go b/internal/service/batch/compute_environment_migrate_test.go new file mode 100644 index 000000000000..04ded55fdaf5 --- /dev/null +++ b/internal/service/batch/compute_environment_migrate_test.go @@ -0,0 +1,90 @@ +package batch_test + +import ( + "context" + "testing" + + "github.com/google/go-cmp/cmp" + tfbatch "github.com/hashicorp/terraform-provider-aws/internal/service/batch" +) + +func TestComputeEnvironmentStateUpgradeV0(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + rawState map[string]any + expected map[string]any + }{ + { + name: "empty rawState", + rawState: nil, + expected: map[string]any{}, + }, + { + name: "only compute_environment_name", + rawState: map[string]any{ + "compute_environment_name": "test-environment", + }, + expected: map[string]any{ + "name": "test-environment", + }, + }, + { + name: "only compute_environment_name_prefix", + rawState: map[string]any{ + "compute_environment_name_prefix": "test-prefix", + }, + expected: map[string]any{ + "name_prefix": "test-prefix", + }, + }, + { + name: "both compute_environment_name and compute_environment_name_prefix", + rawState: map[string]any{ + "compute_environment_name": "test-environment", + "compute_environment_name_prefix": "test-prefix", + }, + expected: map[string]any{ + "name": "test-environment", + "name_prefix": "test-prefix", + }, + }, + { + name: "unrelated keys in rawState", + rawState: map[string]any{ + "compute_environment_name": "test-environment", + "compute_environment_name_prefix": "test-prefix", + "other_key": "other-value", + }, + expected: map[string]any{ + "name": "test-environment", + "name_prefix": "test-prefix", + "other_key": "other-value", + }, + }, + { + name: "no compute_environment_name or compute_environment_name_prefix", + rawState: map[string]any{ + "other_key": "other-value", + }, + expected: map[string]any{ + "other_key": "other-value", + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + result, err := tfbatch.ComputeEnvironmentStateUpgradeV0(context.Background(), tt.rawState, nil) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if diff := cmp.Diff(tt.expected, result); diff != "" { + t.Errorf("unexpected result (-want +got):\n%s", diff) + } + }) + } +} diff --git a/internal/service/batch/compute_environment_test.go b/internal/service/batch/compute_environment_test.go index e7111f24f58d..9786efafcfa6 100644 --- a/internal/service/batch/compute_environment_test.go +++ b/internal/service/batch/compute_environment_test.go @@ -282,6 +282,46 @@ func TestAccBatchComputeEnvironment_namePrefix(t *testing.T) { }) } +func TestAccBatchComputeEnvironment_upgradeV0ToV1(t *testing.T) { + ctx := acctest.Context(t) + var ce awstypes.ComputeEnvironmentDetail + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_batch_compute_environment.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, names.BatchServiceID), + CheckDestroy: testAccCheckComputeEnvironmentDestroy(ctx), + Steps: []resource.TestStep{ + { + ExternalProviders: map[string]resource.ExternalProvider{ + "aws": { + Source: "hashicorp/aws", + VersionConstraint: "5.95.0", + }, + }, + Config: testAccComputeEnvironmentConfig_upgradeV0ToV1Legacy(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeEnvironmentExists(ctx, resourceName, &ce), + acctest.CheckResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "batch", fmt.Sprintf("compute-environment/%s", rName)), + resource.TestCheckResourceAttr(resourceName, "compute_environment_name", rName), + resource.TestCheckResourceAttr(resourceName, "compute_environment_name_prefix", ""), + ), + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Config: testAccComputeEnvironmentConfig_basic(rName), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckComputeEnvironmentExists(ctx, resourceName, &ce), + acctest.CheckResourceAttrRegionalARN(ctx, resourceName, names.AttrARN, "batch", fmt.Sprintf("compute-environment/%s", rName)), + resource.TestCheckResourceAttr(resourceName, names.AttrName, rName), + resource.TestCheckResourceAttr(resourceName, names.AttrNamePrefix, ""), + ), + }, + }, + }) +} + func TestAccBatchComputeEnvironment_eksConfiguration(t *testing.T) { ctx := acctest.Context(t) var ce awstypes.ComputeEnvironmentDetail @@ -2106,6 +2146,20 @@ resource "aws_batch_compute_environment" "test" { `, rName)) } +// testAccComputeEnvironmentConfig_legacyV0ToV1Legacy is a test for the legacy V0 to V1 upgrade path. +// WARNING: This is legacy configuration and is no longer valid. +func testAccComputeEnvironmentConfig_upgradeV0ToV1Legacy(rName string) string { + return acctest.ConfigCompose(testAccComputeEnvironmentConfig_base(rName), fmt.Sprintf(` +resource "aws_batch_compute_environment" "test" { + compute_environment_name = %[1]q + + service_role = aws_iam_role.batch_service.arn + type = "UNMANAGED" + depends_on = [aws_iam_role_policy_attachment.batch_service] +} +`, rName)) +} + func testAccComputeEnvironmentConfig_eksConfiguration(rName string) string { //lintignore:AT004 return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` From bdfb0dc317757d3c1016def9c496ae840e5b5d94 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 28 Apr 2025 16:34:10 -0400 Subject: [PATCH 07/13] Move acctest to acctests --- internal/service/batch/exports_test.go | 2 + .../service/batch/job_queue_migration_test.go | 83 --------- internal/service/batch/job_queue_test.go | 172 ++++++++++++++++++ 3 files changed, 174 insertions(+), 83 deletions(-) delete mode 100644 internal/service/batch/job_queue_migration_test.go diff --git a/internal/service/batch/exports_test.go b/internal/service/batch/exports_test.go index 15efdbeb9044..b15075f08515 100644 --- a/internal/service/batch/exports_test.go +++ b/internal/service/batch/exports_test.go @@ -22,4 +22,6 @@ var ( FindSchedulingPolicyByARN = findSchedulingPolicyByARN ListTags = listTags + + ComputeEnvironmentStateUpgradeV0 = computeEnvironmentStateUpgradeV0 ) diff --git a/internal/service/batch/job_queue_migration_test.go b/internal/service/batch/job_queue_migration_test.go deleted file mode 100644 index 3d9850c907fe..000000000000 --- a/internal/service/batch/job_queue_migration_test.go +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package batch_test - -import ( - "fmt" - "testing" - - awstypes "github.com/aws/aws-sdk-go-v2/service/batch/types" - sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" - "github.com/hashicorp/terraform-plugin-testing/helper/resource" - "github.com/hashicorp/terraform-provider-aws/internal/acctest" - "github.com/hashicorp/terraform-provider-aws/names" -) - -func TestAccBatchJobQueue_migrateFromComputeEnvironments(t *testing.T) { - ctx := acctest.Context(t) - var jobQueue1 awstypes.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), - CheckDestroy: testAccCheckJobQueueDestroy(ctx), - Steps: []resource.TestStep{ - { - ExternalProviders: map[string]resource.ExternalProvider{ - "aws": { - Source: "hashicorp/aws", - VersionConstraint: "5.23.0", - }, - }, - Config: testAccJobQueueConfig_computeEnvironments_initial(rName), - Check: resource.ComposeTestCheckFunc( - testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), - ), - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Config: testAccJobQueueConfig_computeEnvironments_updated(rName), - PlanOnly: true, - }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Config: testAccJobQueueConfig_computeEnvironments_updated(rName), - Check: resource.ComposeTestCheckFunc( - testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), - ), - }, - }, - }) -} - -func testAccJobQueueConfig_computeEnvironments_initial(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 = "ENABLED" -} -`, rName)) -} - -func testAccJobQueueConfig_computeEnvironments_updated(rName string) string { - return acctest.ConfigCompose( - testAccJobQueueConfig_base(rName), - fmt.Sprintf(` -resource "aws_batch_job_queue" "test" { - compute_environment_order { - compute_environment = aws_batch_compute_environment.test.arn - order = 0 - } - name = %[1]q - priority = 1 - state = "ENABLED" -} -`, rName)) -} diff --git a/internal/service/batch/job_queue_test.go b/internal/service/batch/job_queue_test.go index 6c33c80cfcf4..59538e3265e7 100644 --- a/internal/service/batch/job_queue_test.go +++ b/internal/service/batch/job_queue_test.go @@ -338,6 +338,45 @@ func TestAccBatchJobQueue_jobStateTimeLimitActionsMultiple(t *testing.T) { }) } +func TestAccBatchJobQueue_upgradeComputeEnvironments(t *testing.T) { + ctx := acctest.Context(t) + var jobQueue1 awstypes.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), + CheckDestroy: testAccCheckJobQueueDestroy(ctx), + Steps: []resource.TestStep{ + { + ExternalProviders: map[string]resource.ExternalProvider{ + "aws": { + Source: "hashicorp/aws", + VersionConstraint: "5.95.0", + }, + }, + Config: testAccJobQueueConfig_StateUpgradeComputeEnvironments_initial(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), + ), + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Config: testAccJobQueueConfig_StateUpgradeComputeEnvironments_updated(rName), + PlanOnly: true, + }, + { + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Config: testAccJobQueueConfig_StateUpgradeComputeEnvironments_updated(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), + ), + }, + }, + }) +} + func testAccCheckJobQueueExists(ctx context.Context, n string, v *awstypes.JobQueueDetail) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -796,3 +835,136 @@ resource "aws_batch_job_queue" "test" { } `, rName)) } + +// testAccJobQueueConfig_base returns the base configuration for the Terraform AWS Provider v5.95.0. +// WARNING: Legacy configuration, breaking changes have been made to the aws_batch_compute_environment resource. +func testAccJobQueueConfig_legacyBase(rName string) string { + return fmt.Sprintf(` +data "aws_partition" "current" {} + +resource "aws_iam_role" "test" { + name = %[1]q + assume_role_policy = < Date: Mon, 28 Apr 2025 16:43:06 -0400 Subject: [PATCH 08/13] Add copyright --- internal/service/batch/compute_environment_migrate_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/service/batch/compute_environment_migrate_test.go b/internal/service/batch/compute_environment_migrate_test.go index 04ded55fdaf5..d3d99ab1bf96 100644 --- a/internal/service/batch/compute_environment_migrate_test.go +++ b/internal/service/batch/compute_environment_migrate_test.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + package batch_test import ( From d651ca7ae111e43dc702b1f3e415243c33a10000 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 28 Apr 2025 17:01:34 -0400 Subject: [PATCH 09/13] Fix constants --- .../service/batch/compute_environment_migrate.go | 4 ++-- .../batch/compute_environment_migrate_test.go | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/service/batch/compute_environment_migrate.go b/internal/service/batch/compute_environment_migrate.go index 50375f0254a2..2fd153f37e7d 100644 --- a/internal/service/batch/compute_environment_migrate.go +++ b/internal/service/batch/compute_environment_migrate.go @@ -234,12 +234,12 @@ func computeEnvironmentStateUpgradeV0(_ context.Context, rawState map[string]any } if v, ok := rawState["compute_environment_name"].(string); ok && v != "" { - rawState["name"] = v + rawState[names.AttrName] = v delete(rawState, "compute_environment_name") } if v, ok := rawState["compute_environment_name_prefix"].(string); ok && v != "" { - rawState["name_prefix"] = v + rawState[names.AttrNamePrefix] = v delete(rawState, "compute_environment_name_prefix") } diff --git a/internal/service/batch/compute_environment_migrate_test.go b/internal/service/batch/compute_environment_migrate_test.go index d3d99ab1bf96..6a3cdc6532f7 100644 --- a/internal/service/batch/compute_environment_migrate_test.go +++ b/internal/service/batch/compute_environment_migrate_test.go @@ -30,7 +30,7 @@ func TestComputeEnvironmentStateUpgradeV0(t *testing.T) { "compute_environment_name": "test-environment", }, expected: map[string]any{ - "name": "test-environment", + names.AttrName: "test-environment", }, }, { @@ -39,7 +39,7 @@ func TestComputeEnvironmentStateUpgradeV0(t *testing.T) { "compute_environment_name_prefix": "test-prefix", }, expected: map[string]any{ - "name_prefix": "test-prefix", + names.AttrNamePrefix: "test-prefix", }, }, { @@ -49,8 +49,8 @@ func TestComputeEnvironmentStateUpgradeV0(t *testing.T) { "compute_environment_name_prefix": "test-prefix", }, expected: map[string]any{ - "name": "test-environment", - "name_prefix": "test-prefix", + names.AttrName: "test-environment", + names.AttrNamePrefix: "test-prefix", }, }, { @@ -61,8 +61,8 @@ func TestComputeEnvironmentStateUpgradeV0(t *testing.T) { "other_key": "other-value", }, expected: map[string]any{ - "name": "test-environment", - "name_prefix": "test-prefix", + names.AttrName: "test-environment", + names.AttrNamePrefix: "test-prefix", "other_key": "other-value", }, }, From 5760b0b780e627803073b5290b20be0fe7fc9d6d Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 28 Apr 2025 17:03:04 -0400 Subject: [PATCH 10/13] gofmt --- internal/service/batch/compute_environment_migrate_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/service/batch/compute_environment_migrate_test.go b/internal/service/batch/compute_environment_migrate_test.go index 6a3cdc6532f7..fc6e1173e0ab 100644 --- a/internal/service/batch/compute_environment_migrate_test.go +++ b/internal/service/batch/compute_environment_migrate_test.go @@ -49,7 +49,7 @@ func TestComputeEnvironmentStateUpgradeV0(t *testing.T) { "compute_environment_name_prefix": "test-prefix", }, expected: map[string]any{ - names.AttrName: "test-environment", + names.AttrName: "test-environment", names.AttrNamePrefix: "test-prefix", }, }, @@ -61,9 +61,9 @@ func TestComputeEnvironmentStateUpgradeV0(t *testing.T) { "other_key": "other-value", }, expected: map[string]any{ - names.AttrName: "test-environment", + names.AttrName: "test-environment", names.AttrNamePrefix: "test-prefix", - "other_key": "other-value", + "other_key": "other-value", }, }, { From 7d33e91b1cecf459c0b9aa00526f870edfafd27a Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 28 Apr 2025 17:15:04 -0400 Subject: [PATCH 11/13] The what? --- internal/service/batch/compute_environment_migrate_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/service/batch/compute_environment_migrate_test.go b/internal/service/batch/compute_environment_migrate_test.go index fc6e1173e0ab..5115bd5acbde 100644 --- a/internal/service/batch/compute_environment_migrate_test.go +++ b/internal/service/batch/compute_environment_migrate_test.go @@ -9,6 +9,7 @@ import ( "github.com/google/go-cmp/cmp" tfbatch "github.com/hashicorp/terraform-provider-aws/internal/service/batch" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestComputeEnvironmentStateUpgradeV0(t *testing.T) { From fb54d661fbd682029c9d98265e97e90daf419920 Mon Sep 17 00:00:00 2001 From: Dirk Avery <31492422+YakDriver@users.noreply.github.com> Date: Tue, 29 Apr 2025 12:57:00 -0400 Subject: [PATCH 12/13] Update internal/service/batch/compute_environment_test.go Co-authored-by: Jared Baker --- internal/service/batch/compute_environment_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/service/batch/compute_environment_test.go b/internal/service/batch/compute_environment_test.go index 9786efafcfa6..5fa78b32ea1f 100644 --- a/internal/service/batch/compute_environment_test.go +++ b/internal/service/batch/compute_environment_test.go @@ -317,6 +317,11 @@ func TestAccBatchComputeEnvironment_upgradeV0ToV1(t *testing.T) { resource.TestCheckResourceAttr(resourceName, names.AttrName, rName), resource.TestCheckResourceAttr(resourceName, names.AttrNamePrefix, ""), ), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + }, }, }, }) From 165deaa03d42b9d43f3527916c63f794edbe4f1a Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Tue, 29 Apr 2025 13:09:07 -0400 Subject: [PATCH 13/13] Testing improvements --- internal/service/batch/compute_environment_test.go | 4 ++++ internal/service/batch/job_queue_test.go | 11 ++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/service/batch/compute_environment_test.go b/internal/service/batch/compute_environment_test.go index 5fa78b32ea1f..829d6145c220 100644 --- a/internal/service/batch/compute_environment_test.go +++ b/internal/service/batch/compute_environment_test.go @@ -16,6 +16,7 @@ import ( "github.com/google/go-cmp/cmp/cmpopts" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/plancheck" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -321,6 +322,9 @@ func TestAccBatchComputeEnvironment_upgradeV0ToV1(t *testing.T) { PreApply: []plancheck.PlanCheck{ plancheck.ExpectEmptyPlan(), }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, }, }, }, diff --git a/internal/service/batch/job_queue_test.go b/internal/service/batch/job_queue_test.go index 59538e3265e7..ec0e2ab2e738 100644 --- a/internal/service/batch/job_queue_test.go +++ b/internal/service/batch/job_queue_test.go @@ -13,6 +13,7 @@ import ( awstypes "github.com/aws/aws-sdk-go-v2/service/batch/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/plancheck" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -361,17 +362,17 @@ func TestAccBatchJobQueue_upgradeComputeEnvironments(t *testing.T) { testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), ), }, - { - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - Config: testAccJobQueueConfig_StateUpgradeComputeEnvironments_updated(rName), - PlanOnly: true, - }, { ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Config: testAccJobQueueConfig_StateUpgradeComputeEnvironments_updated(rName), Check: resource.ComposeTestCheckFunc( testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), ), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + }, }, }, })