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` +``` 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/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..2fd153f37e7d --- /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[names.AttrName] = v + delete(rawState, "compute_environment_name") + } + + if v, ok := rawState["compute_environment_name_prefix"].(string); ok && v != "" { + rawState[names.AttrNamePrefix] = 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..5115bd5acbde --- /dev/null +++ b/internal/service/batch/compute_environment_migrate_test.go @@ -0,0 +1,94 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package batch_test + +import ( + "context" + "testing" + + "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) { + 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{ + names.AttrName: "test-environment", + }, + }, + { + name: "only compute_environment_name_prefix", + rawState: map[string]any{ + "compute_environment_name_prefix": "test-prefix", + }, + expected: map[string]any{ + names.AttrNamePrefix: "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{ + names.AttrName: "test-environment", + names.AttrNamePrefix: "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{ + names.AttrName: "test-environment", + names.AttrNamePrefix: "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..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" @@ -282,6 +283,54 @@ 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, ""), + ), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + PostApplyPostRefresh: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + }, + }, + }, + }) +} + func TestAccBatchComputeEnvironment_eksConfiguration(t *testing.T) { ctx := acctest.Context(t) var ce awstypes.ComputeEnvironmentDetail @@ -2106,6 +2155,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(` 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.go b/internal/service/batch/job_queue.go index 1b99732c458e..6403b80ed965 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" @@ -17,7 +15,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" @@ -33,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" @@ -60,15 +56,10 @@ type jobQueueResource struct { 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{ @@ -165,8 +156,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() { @@ -229,27 +218,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.Int32ToFrameworkInt64Legacy(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)...) } @@ -277,11 +251,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) { @@ -386,23 +355,19 @@ func (r *jobQueueResource) Delete(ctx context.Context, request resource.DeleteRe } } -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, + }, } } @@ -534,7 +499,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"` @@ -569,26 +533,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_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_test.go b/internal/service/batch/job_queue_test.go index 9f120ef20cc9..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" @@ -21,18 +22,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 +37,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 +49,9 @@ func TestAccBatchJobQueue_basicCEO(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: ignoreDeprecatedCEOForImports, + ResourceName: resourceName, + RefreshState: true, + PlanOnly: true, }, }, }) @@ -127,65 +81,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 +97,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 +112,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), ), }, { @@ -444,6 +339,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), + Check: resource.ComposeTestCheckFunc( + testAccCheckJobQueueExists(ctx, resourceName, &jobQueue1), + ), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectEmptyPlan(), + }, + }, + }, + }, + }) +} + func testAccCheckJobQueueExists(ctx context.Context, n string, v *awstypes.JobQueueDetail) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -473,7 +407,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 +442,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) @@ -608,9 +541,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 @@ -632,10 +565,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 +618,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 +634,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 +652,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 @@ -739,9 +670,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 @@ -786,9 +717,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 @@ -810,11 +741,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 @@ -823,9 +761,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 @@ -847,10 +785,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 +814,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 @@ -891,3 +836,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 = < \ No newline at end of file + 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/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. 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/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 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" {