Skip to content

Commit 2445ffe

Browse files
Update tests for Composer 1 & 2 with node_config, also Update docs for Composer 2 (#7670) (#14315)
* Update decumentation. Composer2 also has tags as optional parameter. CHG: Realistic oauth_scopes. * FIX: wrong function. * FIX: Disk size 2-> 20. * CHG: Name to reflect broather sense of tests. * FIX: composer version 1->2 in proper test. Rm: Unused function. * CHG: Names remove _withTags. RM: Zone, max_pods, use_ip_aliases from Composer2. Signed-off-by: Modular Magician <[email protected]>
1 parent 98c5642 commit 2445ffe

File tree

3 files changed

+104
-5
lines changed

3 files changed

+104
-5
lines changed

.changelog/7670.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
```release-note:none
2+
Update docs for Composer 2.
3+
4+
Add tests for network tags field for Composer 1 & 2.
5+
```

google/resource_composer_environment_test.go

+92-5
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,7 @@ func TestAccComposerEnvironment_composerV2MasterAuthNetworksUpdate(t *testing.T)
724724
})
725725
}
726726

727-
// Checks behavior of node config, including dependencies on Compute resources.
728-
func TestAccComposerEnvironment_withNodeConfig(t *testing.T) {
727+
func TestAccComposer1Environment_withNodeConfig(t *testing.T) {
729728
t.Parallel()
730729

731730
envName := fmt.Sprintf("%s-%d", testComposerEnvironmentPrefix, RandInt(t))
@@ -739,7 +738,7 @@ func TestAccComposerEnvironment_withNodeConfig(t *testing.T) {
739738
CheckDestroy: testAccComposerEnvironmentDestroyProducer(t),
740739
Steps: []resource.TestStep{
741740
{
742-
Config: testAccComposerEnvironment_nodeCfg(envName, network, subnetwork, serviceAccount),
741+
Config: testAccComposer1Environment_nodeCfg(envName, network, subnetwork, serviceAccount),
743742
},
744743
{
745744
ResourceName: "google_composer_environment.test",
@@ -752,7 +751,41 @@ func TestAccComposerEnvironment_withNodeConfig(t *testing.T) {
752751
{
753752
PlanOnly: true,
754753
ExpectNonEmptyPlan: false,
755-
Config: testAccComposerEnvironment_nodeCfg(envName, network, subnetwork, serviceAccount),
754+
Config: testAccComposer1Environment_nodeCfg(envName, network, subnetwork, serviceAccount),
755+
Check: testAccCheckClearComposerEnvironmentFirewalls(t, network),
756+
},
757+
},
758+
})
759+
}
760+
761+
func TestAccComposer2Environment_withNodeConfig(t *testing.T) {
762+
t.Parallel()
763+
764+
envName := fmt.Sprintf("%s-%d", testComposerEnvironmentPrefix, RandInt(t))
765+
network := fmt.Sprintf("%s-%d", testComposerNetworkPrefix, RandInt(t))
766+
subnetwork := network + "-1"
767+
serviceAccount := fmt.Sprintf("tf-test-%d", RandInt(t))
768+
769+
VcrTest(t, resource.TestCase{
770+
PreCheck: func() { AccTestPreCheck(t) },
771+
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
772+
CheckDestroy: testAccComposerEnvironmentDestroyProducer(t),
773+
Steps: []resource.TestStep{
774+
{
775+
Config: testAccComposer2Environment_nodeCfg(envName, network, subnetwork, serviceAccount),
776+
},
777+
{
778+
ResourceName: "google_composer_environment.test",
779+
ImportState: true,
780+
ImportStateVerify: true,
781+
},
782+
// This is a terrible clean-up step in order to get destroy to succeed,
783+
// due to dangling firewall rules left by the Composer Environment blocking network deletion.
784+
// TODO: Remove this check if firewall rules bug gets fixed by Composer.
785+
{
786+
PlanOnly: true,
787+
ExpectNonEmptyPlan: false,
788+
Config: testAccComposer2Environment_nodeCfg(envName, network, subnetwork, serviceAccount),
756789
Check: testAccCheckClearComposerEnvironmentFirewalls(t, network),
757790
},
758791
},
@@ -1832,7 +1865,7 @@ resource "google_compute_subnetwork" "test" {
18321865
`, name, network, subnetwork)
18331866
}
18341867

1835-
func testAccComposerEnvironment_nodeCfg(environment, network, subnetwork, serviceAccount string) string {
1868+
func testAccComposer1Environment_nodeCfg(environment, network, subnetwork, serviceAccount string) string {
18361869
return fmt.Sprintf(`
18371870
data "google_project" "project" {}
18381871
@@ -1850,6 +1883,10 @@ resource "google_composer_environment" "test" {
18501883
use_ip_aliases = true
18511884
cluster_ipv4_cidr_block = "10.0.0.0/16"
18521885
}
1886+
tags = toset(["t1", "t2"])
1887+
machine_type = "n2-highcpu-2"
1888+
disk_size_gb = 20
1889+
oauth_scopes = toset(["https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/bigquery"])
18531890
}
18541891
software_config {
18551892
image_version = "composer-1-airflow-2"
@@ -1883,6 +1920,56 @@ resource "google_project_iam_member" "composer-worker" {
18831920
`, environment, network, subnetwork, serviceAccount)
18841921
}
18851922

1923+
func testAccComposer2Environment_nodeCfg(environment, network, subnetwork, serviceAccount string) string {
1924+
return fmt.Sprintf(`
1925+
data "google_project" "project" {}
1926+
1927+
resource "google_composer_environment" "test" {
1928+
name = "%s"
1929+
region = "us-central1"
1930+
config {
1931+
node_config {
1932+
network = google_compute_network.test.self_link
1933+
subnetwork = google_compute_subnetwork.test.self_link
1934+
1935+
service_account = google_service_account.test.name
1936+
ip_allocation_policy {
1937+
cluster_ipv4_cidr_block = "10.0.0.0/16"
1938+
}
1939+
tags = toset(["t1", "t2"])
1940+
}
1941+
software_config {
1942+
image_version = "composer-2-airflow-2"
1943+
}
1944+
}
1945+
depends_on = [google_project_iam_member.composer-worker]
1946+
}
1947+
1948+
resource "google_compute_network" "test" {
1949+
name = "%s"
1950+
auto_create_subnetworks = false
1951+
}
1952+
1953+
resource "google_compute_subnetwork" "test" {
1954+
name = "%s"
1955+
ip_cidr_range = "10.2.0.0/16"
1956+
region = "us-central1"
1957+
network = google_compute_network.test.self_link
1958+
}
1959+
1960+
resource "google_service_account" "test" {
1961+
account_id = "%s"
1962+
display_name = "Test Service Account for Composer Environment"
1963+
}
1964+
1965+
resource "google_project_iam_member" "composer-worker" {
1966+
project = data.google_project.project.project_id
1967+
role = "roles/composer.worker"
1968+
member = "serviceAccount:${google_service_account.test.email}"
1969+
}
1970+
`, environment, network, subnetwork, serviceAccount)
1971+
}
1972+
18861973
func testAccComposerEnvironment_airflow2RecoveryCfg(name, network, subnetwork string) string {
18871974
return fmt.Sprintf(`
18881975
resource "google_composer_environment" "test" {

website/docs/r/composer_environment.html.markdown

+7
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,13 @@ The `node_config` block supports:
713713
note that the service account must have `roles/composer.worker`
714714
for any GCP resources created under the Cloud Composer Environment.
715715

716+
* `tags` -
717+
(Optional)
718+
The list of instance tags applied to all node VMs. Tags are
719+
used to identify valid sources or targets for network
720+
firewalls. Each tag within the list must comply with RFC1035.
721+
Cannot be updated.
722+
716723
* `ip_allocation_policy` -
717724
(Optional)
718725
Configuration for controlling how IPs are allocated in the GKE cluster.

0 commit comments

Comments
 (0)