Skip to content

Commit

Permalink
image_version and python_version are ga in composer (#2323)
Browse files Browse the repository at this point in the history
Merged PR #2323.
  • Loading branch information
danawillow authored and modular-magician committed Sep 18, 2019
1 parent 48b0aeb commit 68deae1
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 28 deletions.
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import (
const (
composerEnvironmentEnvVariablesRegexp = "[a-zA-Z_][a-zA-Z0-9_]*."
composerEnvironmentReservedAirflowEnvVarRegexp = "AIRFLOW__[A-Z0-9_]+__[A-Z0-9_]+"
<% unless version == 'ga' -%>
composerEnvironmentVersionRegexp = `composer-([0-9]+\.[0-9]+\.[0-9]+|latest)-airflow-([0-9]+\.[0-9]+(\.[0-9]+.*)?)`
<% end -%>
)

var composerEnvironmentReservedEnvVar = map[string]struct{}{
Expand Down Expand Up @@ -227,7 +225,6 @@ func resourceComposerEnvironment() *schema.Resource {
"image_version": {
Type: schema.TypeString,
Computed: true,
<% unless version == 'ga' -%>
Optional: true,
ValidateFunc: validateRegexp(composerEnvironmentVersionRegexp),
DiffSuppressFunc: composerImageVersionDiffSuppress,
Expand All @@ -237,7 +234,6 @@ func resourceComposerEnvironment() *schema.Resource {
Optional: true,
Computed: true,
ForceNew: true,
<% end -%>
},
},
},
Expand Down Expand Up @@ -399,7 +395,6 @@ func resourceComposerEnvironmentUpdate(d *schema.ResourceData, meta interface{})
return err
}

<% unless version == 'ga' -%>
if d.HasChange("config.0.software_config.0.image_version") {
patchObj := &composer.Environment{
Config: &composer.EnvironmentConfig{
Expand All @@ -415,7 +410,6 @@ func resourceComposerEnvironmentUpdate(d *schema.ResourceData, meta interface{})
}
d.SetPartial("config")
}
<% end -%>

if d.HasChange("config.0.software_config.0.airflow_config_overrides") {
patchObj := &composer.Environment{
Expand Down Expand Up @@ -669,9 +663,7 @@ func flattenComposerEnvironmentConfigSoftwareConfig(softwareCfg *composer.Softwa
}
transformed := make(map[string]interface{})
transformed["image_version"] = softwareCfg.ImageVersion
<% unless version == 'ga' -%>
transformed["python_version"] = softwareCfg.PythonVersion
<% end -%>
transformed["airflow_config_overrides"] = softwareCfg.AirflowConfigOverrides
transformed["pypi_packages"] = softwareCfg.PypiPackages
transformed["env_variables"] = softwareCfg.EnvVariables
Expand Down Expand Up @@ -945,9 +937,7 @@ func expandComposerEnvironmentConfigSoftwareConfig(v interface{}, d *schema.Reso
transformed := &composer.SoftwareConfig{}

transformed.ImageVersion = original["image_version"].(string)
<% unless version == 'ga' -%>
transformed.PythonVersion = original["python_version"].(string)
<% end -%>
transformed.AirflowConfigOverrides = expandComposerEnvironmentConfigSoftwareConfigStringMap(original, "airflow_config_overrides")
transformed.PypiPackages = expandComposerEnvironmentConfigSoftwareConfigStringMap(original, "pypi_packages")
transformed.EnvVariables = expandComposerEnvironmentConfigSoftwareConfigStringMap(original, "env_variables")
Expand Down Expand Up @@ -1113,7 +1103,6 @@ func validateServiceAccountRelativeNameOrEmail(v interface{}, k string) (ws []st
return
}

<% unless version == 'ga' -%>
func composerImageVersionDiffSuppress(_, old, new string, _ *schema.ResourceData) bool {
versionRe := regexp.MustCompile(composerEnvironmentVersionRegexp)
oldVersions := versionRe.FindStringSubmatch(old)
Expand Down Expand Up @@ -1169,4 +1158,3 @@ func versionsEqual(old, new string) (bool, error) {
}
return o.Equal(n), nil
}
<% end -%>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func init() {
})
}

<% unless version == 'ga' -%>
func TestComposerImageVersionDiffSuppress(t *testing.T) {
t.Parallel()

Expand All @@ -51,7 +50,6 @@ func TestComposerImageVersionDiffSuppress(t *testing.T) {
}
}
}
<% end -%>

// Checks environment creation with minimum required information.
func TestAccComposerEnvironment_basic(t *testing.T) {
Expand Down Expand Up @@ -191,7 +189,6 @@ func TestAccComposerEnvironment_withNodeConfig(t *testing.T) {
})
}

<% unless version == 'ga' -%>
func TestAccComposerEnvironment_withSoftwareConfig(t *testing.T) {
t.Parallel()
envName := acctest.RandomWithPrefix(testComposerEnvironmentPrefix)
Expand All @@ -213,7 +210,6 @@ func TestAccComposerEnvironment_withSoftwareConfig(t *testing.T) {
},
})
}
<% end -%>

// Checks behavior of config for creation for attributes that must
// be updated during create.
Expand Down Expand Up @@ -352,9 +348,7 @@ resource "google_composer_environment" "test" {
node_count = 4

software_config {
<% unless version == 'ga' -%>
image_version = "${data.google_composer_image_versions.all.image_versions.0.image_version_id}"
<% end -%>

airflow_config_overrides = {
core-load_example = "True"
Expand Down Expand Up @@ -420,15 +414,14 @@ resource "google_project_iam_member" "composer-worker" {
`, environment, network, subnetwork, serviceAccount)
}

<% unless version == 'ga' -%>
func testAccComposerEnvironment_softwareCfg(name string) string {
return fmt.Sprintf(`
data "google_composer_image_versions" "all" {
}

resource "google_composer_environment" "test" {
name = "%s"
region = "us-central1"
name = "%s"
region = "us-central1"
config {
software_config {
image_version = "${data.google_composer_image_versions.all.image_versions.0.image_version_id}"
Expand All @@ -438,7 +431,6 @@ resource "google_composer_environment" "test" {
}
`, name)
}
<% end -%>

func testAccComposerEnvironment_updateOnlyFields(name string) string {
return fmt.Sprintf(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,16 @@ The `software_config` block supports:
SQL_USER
```

* `image_version` (Optional, [Beta](https://terraform.io/docs/providers/google/provider_versions.html)) -
* `image_version` (Optional) -
The version of the software running in the environment. This encapsulates both the version of Cloud Composer
functionality and the version of Apache Airflow. It must match the regular expression
`composer-[0-9]+\.[0-9]+(\.[0-9]+)?-airflow-[0-9]+\.[0-9]+(\.[0-9]+.*)?`.
The Cloud Composer portion of the version is a semantic version.
The portion of the image version following 'airflow-' is an official Apache Airflow repository release name.
See [documentation](https://cloud.google.com/composer/docs/reference/rest/v1beta1/projects.locations.environments#softwareconfig)
for allowed release names. This field can only be set in the [Beta](https://terraform.io/docs/providers/google/provider_versions.html))
provider, but is an output-only attribute in the GA provider.
for allowed release names.

* `python_version` (Optional, [Beta](https://terraform.io/docs/providers/google/provider_versions.html)) -
* `python_version` (Optional) -
The major version of Python used to run the Apache Airflow scheduler, worker, and webserver processes.
Can be set to '2' or '3'. If not specified, the default is '2'. Cannot be updated.

Expand Down

0 comments on commit 68deae1

Please sign in to comment.