Skip to content

Commit dd34c67

Browse files
authored
Merge pull request #40751 from danquack/39568/migrate-compute-environment
[BREAKING] 💥 remove compute environments from job queue
2 parents f7becce + 165deaa commit dd34c67

29 files changed

+949
-315
lines changed

.changelog/40751.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:breaking-change
2+
resource/aws_batch_job_queue: Remove deprecated parameter `compute_environments` in place of `compute_environment_order`
3+
```

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ BUG FIXES:
203203
* resource/aws_sns_topic_subscription: Fix to handle eventually consistent subscription read operations ([#42093](https://github.com/hashicorp/terraform-provider-aws/issues/42093))
204204
* 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))
205205
* 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))
206-
>>>>>>> v5.94.0
207206

208207
## 5.93.0 (March 27, 2025)
209208

internal/service/batch/compute_environment.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ func resourceComputeEnvironment() *schema.Resource {
4848

4949
CustomizeDiff: resourceComputeEnvironmentCustomizeDiff,
5050

51+
SchemaVersion: 1,
52+
StateUpgraders: []schema.StateUpgrader{
53+
{
54+
Type: computeEnvironmentSchemaV0().CoreConfigSchema().ImpliedType(),
55+
Upgrade: computeEnvironmentStateUpgradeV0,
56+
Version: 0,
57+
},
58+
},
59+
5160
Schema: map[string]*schema.Schema{
5261
names.AttrARN: {
5362
Type: schema.TypeString,
Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package batch
5+
6+
import (
7+
"context"
8+
9+
awstypes "github.com/aws/aws-sdk-go-v2/service/batch/types"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
11+
"github.com/hashicorp/terraform-provider-aws/internal/sdkv2"
12+
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
13+
"github.com/hashicorp/terraform-provider-aws/names"
14+
)
15+
16+
func computeEnvironmentSchemaV0() *schema.Resource {
17+
return &schema.Resource{
18+
Schema: map[string]*schema.Schema{
19+
names.AttrARN: {
20+
Type: schema.TypeString,
21+
Computed: true,
22+
},
23+
"compute_environment_name": {
24+
Type: schema.TypeString,
25+
Optional: true,
26+
Computed: true,
27+
ForceNew: true,
28+
ConflictsWith: []string{"compute_environment_name_prefix"},
29+
},
30+
"compute_environment_name_prefix": {
31+
Type: schema.TypeString,
32+
Optional: true,
33+
Computed: true,
34+
ForceNew: true,
35+
ConflictsWith: []string{"compute_environment_name"},
36+
},
37+
"compute_resources": {
38+
Type: schema.TypeList,
39+
Optional: true,
40+
ForceNew: true,
41+
MinItems: 0,
42+
MaxItems: 1,
43+
Elem: &schema.Resource{
44+
Schema: map[string]*schema.Schema{
45+
"allocation_strategy": {
46+
Type: schema.TypeString,
47+
Optional: true,
48+
StateFunc: sdkv2.ToUpperSchemaStateFunc,
49+
},
50+
"bid_percentage": {
51+
Type: schema.TypeInt,
52+
Optional: true,
53+
},
54+
"desired_vcpus": {
55+
Type: schema.TypeInt,
56+
Optional: true,
57+
Computed: true,
58+
},
59+
"ec2_configuration": {
60+
Type: schema.TypeList,
61+
Optional: true,
62+
Computed: true,
63+
ForceNew: true,
64+
MaxItems: 2,
65+
Elem: &schema.Resource{
66+
Schema: map[string]*schema.Schema{
67+
"image_id_override": {
68+
Type: schema.TypeString,
69+
Optional: true,
70+
Computed: true,
71+
},
72+
"image_type": {
73+
Type: schema.TypeString,
74+
Optional: true,
75+
},
76+
},
77+
},
78+
},
79+
"ec2_key_pair": {
80+
Type: schema.TypeString,
81+
Optional: true,
82+
},
83+
"image_id": {
84+
Type: schema.TypeString,
85+
Optional: true,
86+
},
87+
"instance_role": {
88+
Type: schema.TypeString,
89+
Optional: true,
90+
},
91+
names.AttrInstanceType: {
92+
Type: schema.TypeSet,
93+
Optional: true,
94+
Elem: &schema.Schema{Type: schema.TypeString},
95+
},
96+
names.AttrLaunchTemplate: {
97+
Type: schema.TypeList,
98+
Optional: true,
99+
ForceNew: true,
100+
MaxItems: 1,
101+
Elem: &schema.Resource{
102+
Schema: map[string]*schema.Schema{
103+
"launch_template_id": {
104+
Type: schema.TypeString,
105+
Optional: true,
106+
ConflictsWith: []string{"compute_resources.0.launch_template.0.launch_template_name"},
107+
},
108+
"launch_template_name": {
109+
Type: schema.TypeString,
110+
Optional: true,
111+
ConflictsWith: []string{"compute_resources.0.launch_template.0.launch_template_id"},
112+
},
113+
names.AttrVersion: {
114+
Type: schema.TypeString,
115+
Optional: true,
116+
Computed: true,
117+
},
118+
},
119+
},
120+
},
121+
"max_vcpus": {
122+
Type: schema.TypeInt,
123+
Required: true,
124+
},
125+
"min_vcpus": {
126+
Type: schema.TypeInt,
127+
Optional: true,
128+
},
129+
"placement_group": {
130+
Type: schema.TypeString,
131+
Optional: true,
132+
ForceNew: true,
133+
},
134+
names.AttrSecurityGroupIDs: {
135+
Type: schema.TypeSet,
136+
Optional: true,
137+
Elem: &schema.Schema{Type: schema.TypeString},
138+
},
139+
"spot_iam_fleet_role": {
140+
Type: schema.TypeString,
141+
Optional: true,
142+
ForceNew: true,
143+
},
144+
names.AttrSubnets: {
145+
Type: schema.TypeSet,
146+
Required: true,
147+
Elem: &schema.Schema{Type: schema.TypeString},
148+
},
149+
names.AttrTags: tftags.TagsSchema(),
150+
names.AttrType: {
151+
Type: schema.TypeString,
152+
Required: true,
153+
StateFunc: sdkv2.ToUpperSchemaStateFunc,
154+
},
155+
},
156+
},
157+
},
158+
"ecs_cluster_arn": {
159+
Type: schema.TypeString,
160+
Computed: true,
161+
},
162+
"eks_configuration": {
163+
Type: schema.TypeList,
164+
Optional: true,
165+
ForceNew: true,
166+
MinItems: 0,
167+
MaxItems: 1,
168+
Elem: &schema.Resource{
169+
Schema: map[string]*schema.Schema{
170+
"eks_cluster_arn": {
171+
Type: schema.TypeString,
172+
Required: true,
173+
ForceNew: true,
174+
},
175+
"kubernetes_namespace": {
176+
Type: schema.TypeString,
177+
Required: true,
178+
ForceNew: true,
179+
},
180+
},
181+
},
182+
},
183+
names.AttrServiceRole: {
184+
Type: schema.TypeString,
185+
Optional: true,
186+
Computed: true,
187+
},
188+
names.AttrState: {
189+
Type: schema.TypeString,
190+
Optional: true,
191+
Default: awstypes.CEStateEnabled,
192+
StateFunc: sdkv2.ToUpperSchemaStateFunc,
193+
},
194+
names.AttrStatus: {
195+
Type: schema.TypeString,
196+
Computed: true,
197+
},
198+
names.AttrStatusReason: {
199+
Type: schema.TypeString,
200+
Computed: true,
201+
},
202+
names.AttrTags: tftags.TagsSchema(),
203+
names.AttrTagsAll: tftags.TagsSchemaComputed(),
204+
names.AttrType: {
205+
Type: schema.TypeString,
206+
Required: true,
207+
ForceNew: true,
208+
StateFunc: sdkv2.ToUpperSchemaStateFunc,
209+
},
210+
"update_policy": {
211+
Type: schema.TypeList,
212+
Optional: true,
213+
MaxItems: 1,
214+
Elem: &schema.Resource{
215+
Schema: map[string]*schema.Schema{
216+
"job_execution_timeout_minutes": {
217+
Type: schema.TypeInt,
218+
Required: true,
219+
},
220+
"terminate_jobs_on_update": {
221+
Type: schema.TypeBool,
222+
Required: true,
223+
},
224+
},
225+
},
226+
},
227+
},
228+
}
229+
}
230+
231+
func computeEnvironmentStateUpgradeV0(_ context.Context, rawState map[string]any, meta any) (map[string]any, error) {
232+
if rawState == nil {
233+
rawState = map[string]any{}
234+
}
235+
236+
if v, ok := rawState["compute_environment_name"].(string); ok && v != "" {
237+
rawState[names.AttrName] = v
238+
delete(rawState, "compute_environment_name")
239+
}
240+
241+
if v, ok := rawState["compute_environment_name_prefix"].(string); ok && v != "" {
242+
rawState[names.AttrNamePrefix] = v
243+
delete(rawState, "compute_environment_name_prefix")
244+
}
245+
246+
return rawState, nil
247+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package batch_test
5+
6+
import (
7+
"context"
8+
"testing"
9+
10+
"github.com/google/go-cmp/cmp"
11+
tfbatch "github.com/hashicorp/terraform-provider-aws/internal/service/batch"
12+
"github.com/hashicorp/terraform-provider-aws/names"
13+
)
14+
15+
func TestComputeEnvironmentStateUpgradeV0(t *testing.T) {
16+
t.Parallel()
17+
18+
tests := []struct {
19+
name string
20+
rawState map[string]any
21+
expected map[string]any
22+
}{
23+
{
24+
name: "empty rawState",
25+
rawState: nil,
26+
expected: map[string]any{},
27+
},
28+
{
29+
name: "only compute_environment_name",
30+
rawState: map[string]any{
31+
"compute_environment_name": "test-environment",
32+
},
33+
expected: map[string]any{
34+
names.AttrName: "test-environment",
35+
},
36+
},
37+
{
38+
name: "only compute_environment_name_prefix",
39+
rawState: map[string]any{
40+
"compute_environment_name_prefix": "test-prefix",
41+
},
42+
expected: map[string]any{
43+
names.AttrNamePrefix: "test-prefix",
44+
},
45+
},
46+
{
47+
name: "both compute_environment_name and compute_environment_name_prefix",
48+
rawState: map[string]any{
49+
"compute_environment_name": "test-environment",
50+
"compute_environment_name_prefix": "test-prefix",
51+
},
52+
expected: map[string]any{
53+
names.AttrName: "test-environment",
54+
names.AttrNamePrefix: "test-prefix",
55+
},
56+
},
57+
{
58+
name: "unrelated keys in rawState",
59+
rawState: map[string]any{
60+
"compute_environment_name": "test-environment",
61+
"compute_environment_name_prefix": "test-prefix",
62+
"other_key": "other-value",
63+
},
64+
expected: map[string]any{
65+
names.AttrName: "test-environment",
66+
names.AttrNamePrefix: "test-prefix",
67+
"other_key": "other-value",
68+
},
69+
},
70+
{
71+
name: "no compute_environment_name or compute_environment_name_prefix",
72+
rawState: map[string]any{
73+
"other_key": "other-value",
74+
},
75+
expected: map[string]any{
76+
"other_key": "other-value",
77+
},
78+
},
79+
}
80+
81+
for _, tt := range tests {
82+
t.Run(tt.name, func(t *testing.T) {
83+
t.Parallel()
84+
85+
result, err := tfbatch.ComputeEnvironmentStateUpgradeV0(context.Background(), tt.rawState, nil)
86+
if err != nil {
87+
t.Fatalf("unexpected error: %v", err)
88+
}
89+
if diff := cmp.Diff(tt.expected, result); diff != "" {
90+
t.Errorf("unexpected result (-want +got):\n%s", diff)
91+
}
92+
})
93+
}
94+
}

0 commit comments

Comments
 (0)