Skip to content

Commit dd37ba5

Browse files
Allow composer_environment region to be computed (#5747) (#11178)
Signed-off-by: Modular Magician <[email protected]>
1 parent da2f9d9 commit dd37ba5

File tree

2 files changed

+114
-105
lines changed

2 files changed

+114
-105
lines changed

.changelog/5747.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
composer: allow region to be undefined in configuration for `google_composer_environment`
3+
```

google/resource_composer_environment.go

+111-105
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,18 @@ var (
7979
allowedIpRangesConfig = &schema.Resource{
8080
Schema: map[string]*schema.Schema{
8181
"value": {
82-
Type: schema.TypeString,
83-
Required: true,
84-
Description: `IP address or range, defined using CIDR notation, of requests that this rule applies to. Examples: 192.168.1.1 or 192.168.0.0/16 or 2001:db8::/32 or 2001:0db8:0000:0042:0000:8a2e:0370:7334. IP range prefixes should be properly truncated. For example, 1.2.3.4/24 should be truncated to 1.2.3.0/24. Similarly, for IPv6, 2001:db8::1/32 should be truncated to 2001:db8::/32.`,
82+
Type: schema.TypeString,
83+
Required: true,
84+
Description: `IP address or range, defined using CIDR notation, of requests that this rule applies to. Examples: 192.168.1.1 or 192.168.0.0/16 or 2001:db8::/32 or 2001:0db8:0000:0042:0000:8a2e:0370:7334. IP range prefixes should be properly truncated. For example, 1.2.3.4/24 should be truncated to 1.2.3.0/24. Similarly, for IPv6, 2001:db8::1/32 should be truncated to 2001:db8::/32.`,
8585
},
8686
"description": {
87-
Type: schema.TypeString,
88-
Optional: true,
89-
Description: `A description of this ip range.`,
87+
Type: schema.TypeString,
88+
Optional: true,
89+
Description: `A description of this ip range.`,
9090
},
9191
},
9292
}
93+
9394
)
9495

9596
func resourceComposerEnvironment() *schema.Resource {
@@ -120,6 +121,7 @@ func resourceComposerEnvironment() *schema.Resource {
120121
},
121122
"region": {
122123
Type: schema.TypeString,
124+
Computed: true
123125
Optional: true,
124126
ForceNew: true,
125127
Description: `The location or Compute Engine region for the environment.`,
@@ -261,7 +263,7 @@ func resourceComposerEnvironment() *schema.Resource {
261263
Type: schema.TypeString,
262264
Optional: true,
263265
ForceNew: true,
264-
AtLeastOneOf: composerIpAllocationPolicyKeys,
266+
AtLeastOneOf: composerIpAllocationPolicyKeys,
265267
Description: `The IP address range used to allocate IP addresses to pods in the cluster. For Cloud Composer environments in versions composer-1.*.*-airflow-*.*.*, this field is applicable only when use_ip_aliases is true. Set to blank to have GKE choose a range with the default size. Set to /netmask (e.g. /14) to have GKE choose a range with a specific netmask. Set to a CIDR notation (e.g. 10.96.0.0/14) from the RFC-1918 private networks (e.g. 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) to pick a specific range to use. Specify either cluster_secondary_range_name or cluster_ipv4_cidr_block but not both.`,
266268
DiffSuppressFunc: cidrOrSizeDiffSuppress,
267269
ConflictsWith: []string{"config.0.node_config.0.ip_allocation_policy.0.cluster_secondary_range_name"},
@@ -270,7 +272,7 @@ func resourceComposerEnvironment() *schema.Resource {
270272
Type: schema.TypeString,
271273
Optional: true,
272274
ForceNew: true,
273-
AtLeastOneOf: composerIpAllocationPolicyKeys,
275+
AtLeastOneOf: composerIpAllocationPolicyKeys,
274276
Description: `The IP address range used to allocate IP addresses in this cluster. For Cloud Composer environments in versions composer-1.*.*-airflow-*.*.*, this field is applicable only when use_ip_aliases is true. Set to blank to have GKE choose a range with the default size. Set to /netmask (e.g. /14) to have GKE choose a range with a specific netmask. Set to a CIDR notation (e.g. 10.96.0.0/14) from the RFC-1918 private networks (e.g. 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) to pick a specific range to use. Specify either services_secondary_range_name or services_ipv4_cidr_block but not both.`,
275277
DiffSuppressFunc: cidrOrSizeDiffSuppress,
276278
ConflictsWith: []string{"config.0.node_config.0.ip_allocation_policy.0.services_secondary_range_name"},
@@ -351,55 +353,55 @@ func resourceComposerEnvironment() *schema.Resource {
351353
Elem: &schema.Resource{
352354
Schema: map[string]*schema.Schema{
353355
"enable_private_endpoint": {
354-
Type: schema.TypeBool,
355-
Optional: true,
356-
Default: true,
356+
Type: schema.TypeBool,
357+
Optional: true,
358+
Default: true,
357359
AtLeastOneOf: composerPrivateEnvironmentConfig,
358-
ForceNew: true,
359-
Description: `If true, access to the public endpoint of the GKE cluster is denied. If this field is set to true, ip_allocation_policy.use_ip_aliases must be set to true for Cloud Composer environments in versions composer-1.*.*-airflow-*.*.*.`,
360+
ForceNew: true,
361+
Description: `If true, access to the public endpoint of the GKE cluster is denied. If this field is set to true, ip_allocation_policy.use_ip_aliases must be set to true for Cloud Composer environments in versions composer-1.*.*-airflow-*.*.*.`,
360362
},
361363
"master_ipv4_cidr_block": {
362-
Type: schema.TypeString,
363-
Optional: true,
364-
Computed: true,
364+
Type: schema.TypeString,
365+
Optional: true,
366+
Computed: true,
365367
AtLeastOneOf: composerPrivateEnvironmentConfig,
366-
ForceNew: true,
367-
Description: `The IP range in CIDR notation to use for the hosted master network. This range is used for assigning internal IP addresses to the cluster master or set of masters and to the internal load balancer virtual IP. This range must not overlap with any other ranges in use within the cluster's network. If left blank, the default value of '172.16.0.0/28' is used.`,
368+
ForceNew: true,
369+
Description: `The IP range in CIDR notation to use for the hosted master network. This range is used for assigning internal IP addresses to the cluster master or set of masters and to the internal load balancer virtual IP. This range must not overlap with any other ranges in use within the cluster's network. If left blank, the default value of '172.16.0.0/28' is used.`,
368370
},
369371
"web_server_ipv4_cidr_block": {
370-
Type: schema.TypeString,
371-
Optional: true,
372-
Computed: true,
372+
Type: schema.TypeString,
373+
Optional: true,
374+
Computed: true,
373375
AtLeastOneOf: composerPrivateEnvironmentConfig,
374-
ForceNew: true,
375-
Description: `The CIDR block from which IP range for web server will be reserved. Needs to be disjoint from master_ipv4_cidr_block and cloud_sql_ipv4_cidr_block. This field is supported for Cloud Composer environments in versions composer-1.*.*-airflow-*.*.*.`,
376+
ForceNew: true,
377+
Description: `The CIDR block from which IP range for web server will be reserved. Needs to be disjoint from master_ipv4_cidr_block and cloud_sql_ipv4_cidr_block. This field is supported for Cloud Composer environments in versions composer-1.*.*-airflow-*.*.*.`,
376378
},
377379
"cloud_sql_ipv4_cidr_block": {
378-
Type: schema.TypeString,
379-
Optional: true,
380-
Computed: true,
380+
Type: schema.TypeString,
381+
Optional: true,
382+
Computed: true,
381383
AtLeastOneOf: composerPrivateEnvironmentConfig,
382-
ForceNew: true,
383-
Description: `The CIDR block from which IP range in tenant project will be reserved for Cloud SQL. Needs to be disjoint from web_server_ipv4_cidr_block.`,
384+
ForceNew: true,
385+
Description: `The CIDR block from which IP range in tenant project will be reserved for Cloud SQL. Needs to be disjoint from web_server_ipv4_cidr_block.`,
384386
},
385387
"cloud_composer_network_ipv4_cidr_block": {
386-
Type: schema.TypeString,
387-
Optional: true,
388-
Computed: true,
388+
Type: schema.TypeString,
389+
Optional: true,
390+
Computed: true,
389391
AtLeastOneOf: composerPrivateEnvironmentConfig,
390-
ForceNew: true,
391-
Description: `The CIDR block from which IP range for Cloud Composer Network in tenant project will be reserved. Needs to be disjoint from private_cluster_config.master_ipv4_cidr_block and cloud_sql_ipv4_cidr_block. This field is supported for Cloud Composer environments in versions composer-2.*.*-airflow-*.*.* and newer.`,
392+
ForceNew: true,
393+
Description: `The CIDR block from which IP range for Cloud Composer Network in tenant project will be reserved. Needs to be disjoint from private_cluster_config.master_ipv4_cidr_block and cloud_sql_ipv4_cidr_block. This field is supported for Cloud Composer environments in versions composer-2.*.*-airflow-*.*.* and newer.`,
392394
},
393395
},
394396
},
395397
},
396398
"web_server_network_access_control": {
397-
Type: schema.TypeList,
398-
Optional: true,
399-
Computed: true,
399+
Type: schema.TypeList,
400+
Optional: true,
401+
Computed: true,
400402
AtLeastOneOf: composerConfigKeys,
401-
MaxItems: 1,
402-
Description: `The network-level access control policy for the Airflow web server. If unspecified, no network-level access restrictions will be applied. This field is supported for Cloud Composer environments in versions composer-1.*.*-airflow-*.*.*.`,
403+
MaxItems: 1,
404+
Description: `The network-level access control policy for the Airflow web server. If unspecified, no network-level access restrictions will be applied. This field is supported for Cloud Composer environments in versions composer-1.*.*-airflow-*.*.*.`,
403405
Elem: &schema.Resource{
404406
Schema: map[string]*schema.Schema{
405407
"allowed_ip_range": {
@@ -422,8 +424,8 @@ func resourceComposerEnvironment() *schema.Resource {
422424
Elem: &schema.Resource{
423425
Schema: map[string]*schema.Schema{
424426
"machine_type": {
425-
Type: schema.TypeString,
426-
Required: true,
427+
Type: schema.TypeString,
428+
Required: true,
427429
Description: `Optional. Cloud SQL machine type used by Airflow database. It has to be one of: db-n1-standard-2, db-n1-standard-4, db-n1-standard-8 or db-n1-standard-16. If not specified, db-n1-standard-2 will be used.`,
428430
},
429431
},
@@ -439,8 +441,8 @@ func resourceComposerEnvironment() *schema.Resource {
439441
Elem: &schema.Resource{
440442
Schema: map[string]*schema.Schema{
441443
"machine_type": {
442-
Type: schema.TypeString,
443-
Required: true,
444+
Type: schema.TypeString,
445+
Required: true,
444446
Description: `Optional. Machine type on which Airflow web server is running. It has to be one of: composer-n1-webserver-2, composer-n1-webserver-4 or composer-n1-webserver-8. If not specified, composer-n1-webserver-2 will be used. Value custom is returned only in response, if Airflow web server parameters were manually changed to a non-standard values.`,
445447
},
446448
},
@@ -456,9 +458,9 @@ func resourceComposerEnvironment() *schema.Resource {
456458
Elem: &schema.Resource{
457459
Schema: map[string]*schema.Schema{
458460
"kms_key_name": {
459-
Type: schema.TypeString,
460-
Required: true,
461-
ForceNew: true,
461+
Type: schema.TypeString,
462+
Required: true,
463+
ForceNew: true,
462464
Description: `Optional. Customer-managed Encryption Key available through Google's Key Management Service. Cannot be updated.`,
463465
},
464466
},
@@ -508,7 +510,7 @@ func resourceComposerEnvironment() *schema.Resource {
508510
Optional: true,
509511
ForceNew: false,
510512
Description: `Configuration for resources used by Airflow schedulers.`,
511-
MaxItems: 1,
513+
MaxItems: 1,
512514
Elem: &schema.Resource{
513515
Schema: map[string]*schema.Schema{
514516
"cpu": {
@@ -519,11 +521,11 @@ func resourceComposerEnvironment() *schema.Resource {
519521
Description: `CPU request and limit for a single Airflow scheduler replica`,
520522
},
521523
"memory_gb": {
522-
Type: schema.TypeFloat,
523-
Optional: true,
524-
ForceNew: false,
524+
Type: schema.TypeFloat,
525+
Optional: true,
526+
ForceNew: false,
525527
ValidateFunc: validation.FloatAtLeast(0),
526-
Description: `Memory (GB) request and limit for a single Airflow scheduler replica.`,
528+
Description: `Memory (GB) request and limit for a single Airflow scheduler replica.`,
527529
},
528530
"storage_gb": {
529531
Type: schema.TypeFloat,
@@ -547,7 +549,7 @@ func resourceComposerEnvironment() *schema.Resource {
547549
Optional: true,
548550
ForceNew: false,
549551
Description: `Configuration for resources used by Airflow web server.`,
550-
MaxItems: 1,
552+
MaxItems: 1,
551553
Elem: &schema.Resource{
552554
Schema: map[string]*schema.Schema{
553555
"cpu": {
@@ -579,7 +581,7 @@ func resourceComposerEnvironment() *schema.Resource {
579581
Optional: true,
580582
ForceNew: false,
581583
Description: `Configuration for resources used by Airflow workers.`,
582-
MaxItems: 1,
584+
MaxItems: 1,
583585
Elem: &schema.Resource{
584586
Schema: map[string]*schema.Schema{
585587
"cpu": {
@@ -624,14 +626,14 @@ func resourceComposerEnvironment() *schema.Resource {
624626
},
625627
},
626628
"environment_size": {
627-
Type: schema.TypeString,
628-
Optional: true,
629-
Computed: true,
630-
ForceNew: false,
631-
AtLeastOneOf: composerConfigKeys,
632-
ValidateFunc: validation.StringInSlice([]string{"ENVIRONMENT_SIZE_SMALL", "ENVIRONMENT_SIZE_MEDIUM", "ENVIRONMENT_SIZE_LARGE"}, false),
633-
Description: `The size of the Cloud Composer environment. This field is supported for Cloud Composer environments in versions composer-2.*.*-airflow-*.*.* and newer.`,
634-
},
629+
Type: schema.TypeString,
630+
Optional: true,
631+
Computed: true,
632+
ForceNew: false,
633+
AtLeastOneOf: composerConfigKeys,
634+
ValidateFunc: validation.StringInSlice([]string{"ENVIRONMENT_SIZE_SMALL", "ENVIRONMENT_SIZE_MEDIUM", "ENVIRONMENT_SIZE_LARGE"}, false),
635+
Description: `The size of the Cloud Composer environment. This field is supported for Cloud Composer environments in versions composer-2.*.*-airflow-*.*.* and newer.`,
636+
},
635637
"airflow_uri": {
636638
Type: schema.TypeString,
637639
Computed: true,
@@ -920,16 +922,16 @@ func resourceComposerEnvironmentUpdate(d *schema.ResourceData, meta interface{})
920922
return err
921923
}
922924
}
923-
if d.HasChange("config.0.environment_size") {
925+
if d.HasChange("config.0.environment_size") {
924926
patchObj := &composer.Environment{Config: &composer.EnvironmentConfig{}}
925927
if config != nil {
926928
patchObj.Config.EnvironmentSize = config.EnvironmentSize
927929
}
928930
err = resourceComposerEnvironmentPatchField("config.EnvironmentSize", userAgent, patchObj, d, tfConfig)
929-
if err != nil {
931+
if err != nil {
930932
return err
931933
}
932-
}
934+
}
933935
}
934936

935937
if d.HasChange("labels") {
@@ -1130,45 +1132,46 @@ func flattenComposerEnvironmentConfigWorkloadsConfig(workloadsConfig *composer.W
11301132
return nil
11311133
}
11321134

1133-
transformed := make(map[string]interface{})
1134-
transformedScheduler := make(map[string]interface{})
1135-
transformedWebServer := make(map[string]interface{})
1136-
transformedWorker := make(map[string]interface{})
1137-
1138-
wlCfgScheduler := workloadsConfig.Scheduler
1139-
wlCfgWebServer := workloadsConfig.WebServer
1140-
wlCfgWorker := workloadsConfig.Worker
1135+
transformed := make(map[string]interface{})
1136+
transformedScheduler := make(map[string]interface{})
1137+
transformedWebServer := make(map[string]interface{})
1138+
transformedWorker := make(map[string]interface{})
1139+
1140+
wlCfgScheduler := workloadsConfig.Scheduler
1141+
wlCfgWebServer := workloadsConfig.WebServer
1142+
wlCfgWorker := workloadsConfig.Worker
1143+
1144+
if wlCfgScheduler == nil {
1145+
transformedScheduler = nil
1146+
} else {
1147+
transformedScheduler["cpu"] = wlCfgScheduler.Cpu
1148+
transformedScheduler["memory_gb"] = wlCfgScheduler.MemoryGb
1149+
transformedScheduler["storage_gb"] = wlCfgScheduler.StorageGb
1150+
transformedScheduler["count"] = wlCfgScheduler.Count
1151+
}
1152+
1153+
if wlCfgWebServer == nil {
1154+
transformedWebServer = nil
1155+
} else {
1156+
transformedWebServer["cpu"] = wlCfgWebServer.Cpu
1157+
transformedWebServer["memory_gb"] = wlCfgWebServer.MemoryGb
1158+
transformedWebServer["storage_gb"] = wlCfgWebServer.StorageGb
1159+
}
1160+
1161+
if wlCfgWorker == nil {
1162+
transformedWorker = nil
1163+
} else {
1164+
transformedWorker["cpu"] = wlCfgWorker.Cpu
1165+
transformedWorker["memory_gb"] = wlCfgWorker.MemoryGb
1166+
transformedWorker["storage_gb"] = wlCfgWorker.StorageGb
1167+
transformedWorker["min_count"] = wlCfgWorker.MinCount
1168+
transformedWorker["max_count"] = wlCfgWorker.MaxCount
1169+
}
1170+
1171+
transformed["scheduler"] = []interface{}{transformedScheduler}
1172+
transformed["web_server"] = []interface{}{transformedWebServer}
1173+
transformed["worker"] = []interface{}{transformedWorker}
11411174

1142-
if wlCfgScheduler == nil {
1143-
transformedScheduler = nil
1144-
} else {
1145-
transformedScheduler["cpu"] = wlCfgScheduler.Cpu
1146-
transformedScheduler["memory_gb"] = wlCfgScheduler.MemoryGb
1147-
transformedScheduler["storage_gb"] = wlCfgScheduler.StorageGb
1148-
transformedScheduler["count"] = wlCfgScheduler.Count
1149-
}
1150-
1151-
if wlCfgWebServer == nil {
1152-
transformedWebServer = nil
1153-
} else {
1154-
transformedWebServer["cpu"] = wlCfgWebServer.Cpu
1155-
transformedWebServer["memory_gb"] = wlCfgWebServer.MemoryGb
1156-
transformedWebServer["storage_gb"] = wlCfgWebServer.StorageGb
1157-
}
1158-
1159-
if wlCfgWorker == nil {
1160-
transformedWorker = nil
1161-
} else {
1162-
transformedWorker["cpu"] = wlCfgWorker.Cpu
1163-
transformedWorker["memory_gb"] = wlCfgWorker.MemoryGb
1164-
transformedWorker["storage_gb"] = wlCfgWorker.StorageGb
1165-
transformedWorker["min_count"] = wlCfgWorker.MinCount
1166-
transformedWorker["max_count"] = wlCfgWorker.MaxCount
1167-
}
1168-
1169-
transformed["scheduler"] = []interface{}{transformedScheduler}
1170-
transformed["web_server"] = []interface{}{transformedWebServer}
1171-
transformed["worker"] = []interface{}{transformedWorker}
11721175

11731176
return []interface{}{transformed}
11741177
}
@@ -1247,6 +1250,7 @@ func flattenComposerEnvironmentConfigSoftwareConfig(softwareCfg *composer.Softwa
12471250
return []interface{}{transformed}
12481251
}
12491252

1253+
12501254
func expandComposerEnvironmentConfig(v interface{}, d *schema.ResourceData, config *Config) (*composer.EnvironmentConfig, error) {
12511255
l := v.([]interface{})
12521256
if len(l) == 0 {
@@ -1317,10 +1321,10 @@ func expandComposerEnvironmentConfig(v interface{}, d *schema.ResourceData, conf
13171321
transformed.WorkloadsConfig = transformedWorkloadsConfig
13181322

13191323
transformedEnvironmentSize, err := expandComposerEnvironmentConfigEnvironmentSize(original["environment_size"], d, config)
1320-
if err != nil {
1321-
return nil, err
1322-
}
1323-
transformed.EnvironmentSize = transformedEnvironmentSize
1324+
if err != nil {
1325+
return nil, err
1326+
}
1327+
transformed.EnvironmentSize = transformedEnvironmentSize
13241328
return transformed, nil
13251329
}
13261330

@@ -1360,6 +1364,7 @@ func expandComposerEnvironmentConfigWebServerNetworkAccessControl(v interface{},
13601364
return transformed, nil
13611365
}
13621366

1367+
13631368
func expandComposerEnvironmentConfigDatabaseConfig(v interface{}, d *schema.ResourceData, config *Config) (*composer.DatabaseConfig, error) {
13641369
l := v.([]interface{})
13651370
if len(l) == 0 || l[0] == nil {
@@ -1540,6 +1545,7 @@ func expandComposerEnvironmentConfigNodeConfig(v interface{}, d *schema.Resource
15401545
transformed.ServiceAccount = transformedServiceAccount
15411546
}
15421547

1548+
15431549
var nodeConfigZone string
15441550
if v, ok := original["zone"]; ok {
15451551
transformedZone, err := expandComposerEnvironmentZone(v, d, config)

0 commit comments

Comments
 (0)