Skip to content

Commit

Permalink
Match preview versions in google_composer_environment regex (#4797) (#…
Browse files Browse the repository at this point in the history
…9255)

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored May 27, 2021
1 parent 89008b4 commit bc5e747
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/4797.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
composer: fixed a check that did not allow for preview versions in `google_composer_environment`
```
6 changes: 3 additions & 3 deletions google/resource_composer_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{
Expand Down Expand Up @@ -1241,7 +1241,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.
Expand All @@ -1258,7 +1258,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)
}
Expand Down
4 changes: 2 additions & 2 deletions google/resource_composer_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit bc5e747

Please sign in to comment.