Skip to content

[BREAKING] 💥 remove compute environments from job queue #40751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
3 changes: 3 additions & 0 deletions .changelog/40751.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:breaking-change
resource/aws_batch_job_queue: Remove deprecated parameter `compute_environments` in place of `compute_environment_order`
```
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 9 additions & 0 deletions internal/service/batch/compute_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
247 changes: 247 additions & 0 deletions internal/service/batch/compute_environment_migrate.go
Original file line number Diff line number Diff line change
@@ -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
}
94 changes: 94 additions & 0 deletions internal/service/batch/compute_environment_migrate_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
Loading
Loading