From 9a1656323771815b69e4bb10f098f3049d82d2d5 Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Wed, 19 May 2021 13:00:33 -0700 Subject: [PATCH 1/2] Match preview versions in google_composer_environment regex --- .../terraform/resources/resource_composer_environment.go.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/third_party/terraform/resources/resource_composer_environment.go.erb b/mmv1/third_party/terraform/resources/resource_composer_environment.go.erb index 6216d75db9ce..af88e6ad91dc 100644 --- a/mmv1/third_party/terraform/resources/resource_composer_environment.go.erb +++ b/mmv1/third_party/terraform/resources/resource_composer_environment.go.erb @@ -17,7 +17,7 @@ import ( const ( composerEnvironmentEnvVariablesRegexp = "[a-zA-Z_][a-zA-Z0-9_]*." composerEnvironmentReservedAirflowEnvVarRegexp = "AIRFLOW__[A-Z0-9_]+__[A-Z0-9_]+" - composerEnvironmentVersionRegexp = `composer-([0-9]+\.[0-9]+\.[0-9]+|latest)-airflow-([0-9]+\.[0-9]+(\.[0-9]+.*)?)` + composerEnvironmentVersionRegexp = `composer-([0-9]+\.[0-9]+\.[0-9]+(-preview.[0-9]+)?|latest)-airflow-([0-9]+\.[0-9]+(\.[0-9]+.*)?)` ) var composerEnvironmentReservedEnvVar = map[string]struct{}{ From 824271e501d877e53f130f71e6a3932086d1e335 Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Thu, 27 May 2021 11:38:26 -0700 Subject: [PATCH 2/2] Fixup dsf, add unit test case --- .../terraform/resources/resource_composer_environment.go.erb | 4 ++-- .../terraform/tests/resource_composer_environment_test.go.erb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mmv1/third_party/terraform/resources/resource_composer_environment.go.erb b/mmv1/third_party/terraform/resources/resource_composer_environment.go.erb index af88e6ad91dc..5344ecbfd2e1 100644 --- a/mmv1/third_party/terraform/resources/resource_composer_environment.go.erb +++ b/mmv1/third_party/terraform/resources/resource_composer_environment.go.erb @@ -1540,7 +1540,7 @@ func composerImageVersionDiffSuppress(_, old, new string, _ *schema.ResourceData versionRe := regexp.MustCompile(composerEnvironmentVersionRegexp) oldVersions := versionRe.FindStringSubmatch(old) newVersions := versionRe.FindStringSubmatch(new) - if oldVersions == nil || len(oldVersions) < 3 { + if oldVersions == nil || len(oldVersions) < 4 { // Somehow one of the versions didn't match the regexp or didn't // have values in the capturing groups. In that case, fall back to // an equality check. @@ -1557,7 +1557,7 @@ func composerImageVersionDiffSuppress(_, old, new string, _ *schema.ResourceData // Check airflow version using the version package to account for // diffs like 1.10 and 1.10.0 - eq, err := versionsEqual(oldVersions[2], newVersions[2]) + eq, err := versionsEqual(oldVersions[3], newVersions[3]) if err != nil { log.Printf("[WARN] Could not parse airflow version, %s", err) } diff --git a/mmv1/third_party/terraform/tests/resource_composer_environment_test.go.erb b/mmv1/third_party/terraform/tests/resource_composer_environment_test.go.erb index 2335472668ab..62f6d6ea3e1d 100644 --- a/mmv1/third_party/terraform/tests/resource_composer_environment_test.go.erb +++ b/mmv1/third_party/terraform/tests/resource_composer_environment_test.go.erb @@ -40,12 +40,12 @@ func TestComposerImageVersionDiffSuppress(t *testing.T) { {"new latest", "composer-1.4.1-airflow-1.10.0", "composer-latest-airflow-1.10.0", true}, {"airflow equivalent", "composer-1.4.0-airflow-1.10.0", "composer-1.4.0-airflow-1.10", true}, {"airflow different", "composer-1.4.0-airflow-1.10.0", "composer-1.4-airflow-1.9.0", false}, - {"airflow different composer latest", "composer-1.4.0-airflow-1.10.0", "composer-latest-airflow-1.9.0", false}, + {"preview matches", "composer-1.17.0-preview.0-airflow-2.0.1", "composer-1.17.0-preview.0-airflow-2.0.1", true}, } for _, tc := range cases { if actual := composerImageVersionDiffSuppress("", tc.old, tc.new, nil); actual != tc.expected { - t.Fatalf("'%s' failed, expected %v but got %v", tc.name, tc.expected, actual) + t.Errorf("'%s' failed, expected %v but got %v", tc.name, tc.expected, actual) } } }