|
| 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 | +} |
0 commit comments