diff --git a/.changelog/4797.txt b/.changelog/4797.txt new file mode 100644 index 0000000000..aed76bff49 --- /dev/null +++ b/.changelog/4797.txt @@ -0,0 +1,3 @@ +```release-note:bug +composer: fixed a check that did not allow for preview versions in `google_composer_environment` +``` diff --git a/google-beta/resource_composer_environment.go b/google-beta/resource_composer_environment.go index 95e8fa6da1..5ab3dd7978 100644 --- a/google-beta/resource_composer_environment.go +++ b/google-beta/resource_composer_environment.go @@ -16,7 +16,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{}{ @@ -1504,7 +1504,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. @@ -1521,7 +1521,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/google-beta/resource_composer_environment_test.go b/google-beta/resource_composer_environment_test.go index 66a8273436..a985bc217c 100644 --- a/google-beta/resource_composer_environment_test.go +++ b/google-beta/resource_composer_environment_test.go @@ -39,12 +39,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) } } } diff --git a/google-beta/resource_dataproc_cluster_test.go b/google-beta/resource_dataproc_cluster_test.go index ab4878c979..e2592b3a32 100644 --- a/google-beta/resource_dataproc_cluster_test.go +++ b/google-beta/resource_dataproc_cluster_test.go @@ -13,9 +13,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "google.golang.org/api/googleapi" - dataproc "google.golang.org/api/dataproc/v1beta2" + "google.golang.org/api/googleapi" ) func TestDataprocExtractInitTimeout(t *testing.T) {