Skip to content

Commit

Permalink
Adding resilience_mode field support to Cloud Composer (#8058) (#14939)
Browse files Browse the repository at this point in the history
* Adding High Resilience Fields Support To Terraform

* Bumping composer api version to 0.125.0

* Adding Test for composerV2HighResilience

* Fixing function name

* retrigger checks

* retrigger checks

* Replacing go.sum with the fresh version

* Replacing go.mod.erb with the fresh version

* Removing high resilience test and adding field to composerv2 test

* Fixing Indentation

* Remove HighResilience TEST

* Removing HR test

* Fixing Removing ComposerV2 test

* Fixing go mod and go sum

* Added Test for HighResilience

* Fixed Indentation

* Revert go.mod.erb and go.sum changes

* Apply review comments

* retrigger checks

---------

Signed-off-by: Modular Magician <magic-modules@google.com>
Co-authored-by: Khaled Hassan <hkhaled@google.com>
Co-authored-by: Ryan Oaks <ryanoaks@google.com>
Co-authored-by: Przemek Wiech <pwiech@google.com>
  • Loading branch information
4 people committed Jun 20, 2023
1 parent f832b63 commit 3b1428c
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/8058.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
composer: added `resilience_mode` field in `google_composer_environment`
```
96 changes: 96 additions & 0 deletions google/resource_composer_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,39 @@ func TestAccComposerEnvironment_ComposerV2(t *testing.T) {
})
}

func TestAccComposerEnvironment_ComposerV2HighResilience(t *testing.T) {
t.Parallel()

envName := fmt.Sprintf("%s-%d", testComposerEnvironmentPrefix, RandInt(t))
network := fmt.Sprintf("%s-%d", testComposerNetworkPrefix, RandInt(t))
subnetwork := network + "-1"

VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
CheckDestroy: testAccComposerEnvironmentDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComposerEnvironment_composerV2HighResilience(envName, network, subnetwork),
},
{
ResourceName: "google_composer_environment.test",
ImportState: true,
ImportStateVerify: true,
},
// This is a terrible clean-up step in order to get destroy to succeed,
// due to dangling firewall rules left by the Composer Environment blocking network deletion.
// TODO(dzarmola): Remove this check if firewall rules bug gets fixed by Composer.
{
PlanOnly: true,
ExpectNonEmptyPlan: false,
Config: testAccComposerEnvironment_composerV2HighResilience(envName, network, subnetwork),
Check: testAccCheckClearComposerEnvironmentFirewalls(t, network),
},
},
})
}

func TestAccComposerEnvironment_UpdateComposerV2(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1595,6 +1628,69 @@ resource "google_compute_subnetwork" "test" {
`, envName, network, subnetwork)
}

func testAccComposerEnvironment_composerV2HighResilience(envName, network, subnetwork string) string {
return fmt.Sprintf(`
resource "google_composer_environment" "test" {
name = "%s"
region = "us-east1"
config {
node_config {
network = google_compute_network.test.self_link
subnetwork = google_compute_subnetwork.test.self_link
}
software_config {
image_version = "composer-2-airflow-2"
}
workloads_config {
scheduler {
cpu = 1.25
memory_gb = 2.5
storage_gb = 5.4
count = 2
}
web_server {
cpu = 1.75
memory_gb = 3.0
storage_gb = 4.4
}
worker {
cpu = 0.5
memory_gb = 2.0
storage_gb = 3.4
min_count = 2
max_count = 5
}
}
environment_size = "ENVIRONMENT_SIZE_MEDIUM"
resilience_mode = "HIGH_RESILIENCE"
private_environment_config {
enable_private_endpoint = true
cloud_composer_network_ipv4_cidr_block = "10.3.192.0/24"
master_ipv4_cidr_block = "172.16.194.0/23"
cloud_sql_ipv4_cidr_block = "10.3.224.0/20"
}
}
}
resource "google_compute_network" "test" {
name = "%s"
auto_create_subnetworks = false
}
resource "google_compute_subnetwork" "test" {
name = "%s"
ip_cidr_range = "10.2.0.0/16"
region = "us-east1"
network = google_compute_network.test.self_link
private_ip_google_access = true
}
`, envName, network, subnetwork)
}

func testAccComposerEnvironment_composerV2PrivateServiceConnect(envName, network, subnetwork string) string {
return fmt.Sprintf(`
resource "google_composer_environment" "test" {
Expand Down
25 changes: 25 additions & 0 deletions google/services/composer/resource_composer_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ var (
"config.0.workloads_config",
"config.0.environment_size",
"config.0.master_authorized_networks_config",
"config.0.resilience_mode",
}

recoveryConfigKeys = []string{
Expand Down Expand Up @@ -739,6 +740,15 @@ func ResourceComposerEnvironment() *schema.Resource {
ValidateFunc: validation.StringInSlice([]string{"ENVIRONMENT_SIZE_SMALL", "ENVIRONMENT_SIZE_MEDIUM", "ENVIRONMENT_SIZE_LARGE"}, false),
Description: `The size of the Cloud Composer environment. This field is supported for Cloud Composer environments in versions composer-2.*.*-airflow-*.*.* and newer.`,
},
"resilience_mode": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
AtLeastOneOf: composerConfigKeys,
ValidateFunc: validation.StringInSlice([]string{"HIGH_RESILIENCE"}, false),
Description: `Whether high resilience is enabled or not. This field is supported for Cloud Composer environments in versions composer-2.1.15-airflow-*.*.* and newer.`,
},
"master_authorized_networks_config": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -1205,6 +1215,7 @@ func flattenComposerEnvironmentConfig(envCfg *composer.EnvironmentConfig) interf
transformed["workloads_config"] = flattenComposerEnvironmentConfigWorkloadsConfig(envCfg.WorkloadsConfig)
transformed["recovery_config"] = flattenComposerEnvironmentConfigRecoveryConfig(envCfg.RecoveryConfig)
transformed["environment_size"] = envCfg.EnvironmentSize
transformed["resilience_mode"] = envCfg.ResilienceMode
transformed["master_authorized_networks_config"] = flattenComposerEnvironmentConfigMasterAuthorizedNetworksConfig(envCfg.MasterAuthorizedNetworksConfig)
return []interface{}{transformed}
}
Expand Down Expand Up @@ -1520,6 +1531,13 @@ func expandComposerEnvironmentConfig(v interface{}, d *schema.ResourceData, conf
return nil, err
}
transformed.EnvironmentSize = transformedEnvironmentSize

transformedResilienceMode, err := expandComposerEnvironmentConfigResilienceMode(original["resilience_mode"], d, config)
if err != nil {
return nil, err
}
transformed.ResilienceMode = transformedResilienceMode

transformedMasterAuthorizedNetworksConfig, err := expandComposerEnvironmentConfigMasterAuthorizedNetworksConfig(original["master_authorized_networks_config"], d, config)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1743,6 +1761,13 @@ func expandComposerEnvironmentConfigEnvironmentSize(v interface{}, d *schema.Res
return v.(string), nil
}

func expandComposerEnvironmentConfigResilienceMode(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) (string, error) {
if v == nil {
return "", nil
}
return v.(string), nil
}

func expandComposerEnvironmentConfigPrivateEnvironmentConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) (*composer.PrivateEnvironmentConfig, error) {
l := v.([]interface{})
if len(l) == 0 {
Expand Down
6 changes: 6 additions & 0 deletions website/docs/r/composer_environment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,12 @@ The `config` block supports:
environment size are `ENVIRONMENT_SIZE_SMALL`, `ENVIRONMENT_SIZE_MEDIUM`,
and `ENVIRONMENT_SIZE_LARGE`.

* `resilience_mode` -
(Optional, Cloud Composer 2.1.15 or newer only)
The resilience mode states whether high resilience is enabled for
the environment or not. Value for resilience mode is `HIGH_RESILIENCE`.
If unspecified, defaults to standard resilience.

* `master_authorized_networks_config` -
(Optional)
Configuration options for the master authorized networks feature. Enabled
Expand Down

0 comments on commit 3b1428c

Please sign in to comment.