|
6 | 6 | "testing"
|
7 | 7 |
|
8 | 8 | "log"
|
| 9 | + "regexp" |
9 | 10 | "strings"
|
10 | 11 | "time"
|
11 | 12 |
|
@@ -891,6 +892,35 @@ func TestAccComposerEnvironment_withUpdateOnCreate(t *testing.T) {
|
891 | 892 | })
|
892 | 893 | }
|
893 | 894 |
|
| 895 | +func TestAccComposerEnvironment_fixPyPiPackages(t *testing.T) { |
| 896 | + t.Parallel() |
| 897 | + |
| 898 | + envName := fmt.Sprintf("%s-%d", testComposerEnvironmentPrefix, randInt(t)) |
| 899 | + network := fmt.Sprintf("%s-%d", testComposerNetworkPrefix, randInt(t)) |
| 900 | + subnetwork := network + "-1" |
| 901 | + serviceAccount := fmt.Sprintf("tf-test-%d", randInt(t)) |
| 902 | + |
| 903 | + vcrTest(t, resource.TestCase{ |
| 904 | + PreCheck: func() { testAccPreCheck(t) }, |
| 905 | + Providers: testAccProviders, |
| 906 | + CheckDestroy: testAccComposerEnvironmentDestroyProducer(t), |
| 907 | + Steps: []resource.TestStep{ |
| 908 | + { |
| 909 | + Config: testAccComposerEnvironment_fixPyPiPackages(envName, network, subnetwork, serviceAccount), |
| 910 | + ExpectError: regexp.MustCompile("Failed to install pypi packages"), |
| 911 | + }, |
| 912 | + { |
| 913 | + Config: testAccComposerEnvironment_fixPyPiPackagesUpdate(envName, network, subnetwork, serviceAccount), |
| 914 | + }, |
| 915 | + { |
| 916 | + ResourceName: "google_composer_environment.test", |
| 917 | + ImportState: true, |
| 918 | + ImportStateVerify: true, |
| 919 | + }, |
| 920 | + }, |
| 921 | + }) |
| 922 | +} |
| 923 | + |
894 | 924 | func testAccComposerEnvironmentDestroyProducer(t *testing.T) func(s *terraform.State) error {
|
895 | 925 | return func(s *terraform.State) error {
|
896 | 926 | config := googleProviderConfig(t)
|
@@ -2061,6 +2091,161 @@ resource "google_compute_subnetwork" "test" {
|
2061 | 2091 | `, name, network, subnetwork)
|
2062 | 2092 | }
|
2063 | 2093 |
|
| 2094 | +func testAccComposerEnvironment_fixPyPiPackages(environment, network, subnetwork, serviceAccount string) string { |
| 2095 | + return fmt.Sprintf(` |
| 2096 | +resource "google_composer_environment" "test" { |
| 2097 | + name = "%s" |
| 2098 | + region = "us-central1" |
| 2099 | + config { |
| 2100 | +
|
| 2101 | + software_config { |
| 2102 | + image_version = "composer-2-airflow-2" |
| 2103 | +
|
| 2104 | + pypi_packages = { |
| 2105 | + "google-cloud-bigquery" = "==1" |
| 2106 | + } |
| 2107 | + } |
| 2108 | +
|
| 2109 | + private_environment_config { |
| 2110 | + enable_private_endpoint = true |
| 2111 | + master_ipv4_cidr_block = "10.10.0.0/28" |
| 2112 | + } |
| 2113 | +
|
| 2114 | + workloads_config { |
| 2115 | + scheduler { |
| 2116 | + cpu = 0.5 |
| 2117 | + memory_gb = 1.875 |
| 2118 | + storage_gb = 1 |
| 2119 | + count = 1 |
| 2120 | + } |
| 2121 | + web_server { |
| 2122 | + cpu = 0.5 |
| 2123 | + memory_gb = 1.875 |
| 2124 | + storage_gb = 1 |
| 2125 | + } |
| 2126 | + worker { |
| 2127 | + cpu = 0.5 |
| 2128 | + memory_gb = 1.875 |
| 2129 | + storage_gb = 1 |
| 2130 | + min_count = 1 |
| 2131 | + max_count = 3 |
| 2132 | + } |
| 2133 | + } |
| 2134 | +
|
| 2135 | + environment_size = "ENVIRONMENT_SIZE_SMALL" |
| 2136 | +
|
| 2137 | + node_config { |
| 2138 | + network = google_compute_network.test.id |
| 2139 | + subnetwork = google_compute_subnetwork.test.id |
| 2140 | + service_account = google_service_account.test.name |
| 2141 | + } |
| 2142 | + } |
| 2143 | +} |
| 2144 | +
|
| 2145 | +// use a separate network to avoid conflicts with other tests running in parallel |
| 2146 | +// that use the default network/subnet |
| 2147 | +resource "google_compute_network" "test" { |
| 2148 | + name = "%s" |
| 2149 | + auto_create_subnetworks = false |
| 2150 | +} |
| 2151 | +
|
| 2152 | +resource "google_compute_subnetwork" "test" { |
| 2153 | + name = "%s" |
| 2154 | + ip_cidr_range = "10.2.0.0/16" |
| 2155 | + region = "us-central1" |
| 2156 | + network = google_compute_network.test.self_link |
| 2157 | +} |
| 2158 | +
|
| 2159 | +resource "google_service_account" "test" { |
| 2160 | + account_id = "%s" |
| 2161 | + display_name = "Test Service Account for Composer Environment" |
| 2162 | +} |
| 2163 | +
|
| 2164 | +data "google_project" "project" {} |
| 2165 | +
|
| 2166 | +resource "google_project_iam_member" "composer-worker" { |
| 2167 | + project = data.google_project.project.project_id |
| 2168 | + role = "roles/composer.worker" |
| 2169 | + member = "serviceAccount:${google_service_account.test.email}" |
| 2170 | +}`, environment, network, subnetwork, serviceAccount) |
| 2171 | +} |
| 2172 | + |
| 2173 | +func testAccComposerEnvironment_fixPyPiPackagesUpdate(environment, network, subnetwork, serviceAccount string) string { |
| 2174 | + return fmt.Sprintf(` |
| 2175 | +resource "google_composer_environment" "test" { |
| 2176 | + name = "%s" |
| 2177 | + region = "us-central1" |
| 2178 | + config { |
| 2179 | +
|
| 2180 | + software_config { |
| 2181 | + image_version = "composer-2-airflow-2" |
| 2182 | + } |
| 2183 | +
|
| 2184 | + private_environment_config { |
| 2185 | + enable_private_endpoint = true |
| 2186 | + master_ipv4_cidr_block = "10.10.0.0/28" |
| 2187 | + } |
| 2188 | +
|
| 2189 | + workloads_config { |
| 2190 | + scheduler { |
| 2191 | + cpu = 0.5 |
| 2192 | + memory_gb = 1.875 |
| 2193 | + storage_gb = 1 |
| 2194 | + count = 1 |
| 2195 | + } |
| 2196 | + web_server { |
| 2197 | + cpu = 0.5 |
| 2198 | + memory_gb = 1.875 |
| 2199 | + storage_gb = 1 |
| 2200 | + } |
| 2201 | + worker { |
| 2202 | + cpu = 0.5 |
| 2203 | + memory_gb = 1.875 |
| 2204 | + storage_gb = 1 |
| 2205 | + min_count = 1 |
| 2206 | + max_count = 3 |
| 2207 | + } |
| 2208 | + } |
| 2209 | +
|
| 2210 | + environment_size = "ENVIRONMENT_SIZE_SMALL" |
| 2211 | +
|
| 2212 | + node_config { |
| 2213 | + network = google_compute_network.test.id |
| 2214 | + subnetwork = google_compute_subnetwork.test.id |
| 2215 | + service_account = google_service_account.test.name |
| 2216 | + } |
| 2217 | + } |
| 2218 | +} |
| 2219 | +
|
| 2220 | +// use a separate network to avoid conflicts with other tests running in parallel |
| 2221 | +// that use the default network/subnet |
| 2222 | +resource "google_compute_network" "test" { |
| 2223 | + name = "%s" |
| 2224 | + auto_create_subnetworks = false |
| 2225 | +} |
| 2226 | +
|
| 2227 | +resource "google_compute_subnetwork" "test" { |
| 2228 | + name = "%s" |
| 2229 | + ip_cidr_range = "10.2.0.0/16" |
| 2230 | + region = "us-central1" |
| 2231 | + network = google_compute_network.test.self_link |
| 2232 | +} |
| 2233 | +
|
| 2234 | +resource "google_service_account" "test" { |
| 2235 | + account_id = "%s" |
| 2236 | + display_name = "Test Service Account for Composer Environment" |
| 2237 | +} |
| 2238 | +
|
| 2239 | +data "google_project" "project" {} |
| 2240 | +
|
| 2241 | +resource "google_project_iam_member" "composer-worker" { |
| 2242 | + project = data.google_project.project.project_id |
| 2243 | + role = "roles/composer.worker" |
| 2244 | + member = "serviceAccount:${google_service_account.test.email}" |
| 2245 | +} |
| 2246 | +`, environment, network, subnetwork, serviceAccount) |
| 2247 | +} |
| 2248 | + |
2064 | 2249 | /**
|
2065 | 2250 | * CLEAN UP HELPER FUNCTIONS
|
2066 | 2251 | * Because the environments are flaky and bucket deletion rates can be
|
|
0 commit comments