From 6e82d5203e41034bf95cf9c08c20dd1cf51cc4ad Mon Sep 17 00:00:00 2001 From: The Magician Date: Sat, 11 Sep 2021 22:04:38 -0500 Subject: [PATCH] change ignore_read on deployment to custom_flatten (#5187) (#10058) Signed-off-by: Modular Magician --- .changelog/5187.txt | 3 + ...esource_app_engine_flexible_app_version.go | 59 +++++++++++++++++++ ...ine_flexible_app_version_generated_test.go | 2 +- ...ce_app_engine_flexible_app_version_test.go | 4 +- 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 .changelog/5187.txt diff --git a/.changelog/5187.txt b/.changelog/5187.txt new file mode 100644 index 00000000000..d486c962e81 --- /dev/null +++ b/.changelog/5187.txt @@ -0,0 +1,3 @@ +```release-note:bug +appengine: fixed bug where `deployment.container.image` would update to an old version even if in `ignore_changes` +``` diff --git a/google/resource_app_engine_flexible_app_version.go b/google/resource_app_engine_flexible_app_version.go index c6134c2b41d..237ec530b30 100644 --- a/google/resource_app_engine_flexible_app_version.go +++ b/google/resource_app_engine_flexible_app_version.go @@ -408,6 +408,7 @@ A duration in seconds with up to nine fractional digits, terminated by 's'. Exam }, "container": { Type: schema.TypeList, + Computed: true, Optional: true, Description: `The Docker image for the container that runs the version.`, MaxItems: 1, @@ -1163,6 +1164,9 @@ func resourceAppEngineFlexibleAppVersionRead(d *schema.ResourceData, meta interf if err := d.Set("nobuild_files_regex", flattenAppEngineFlexibleAppVersionNobuildFilesRegex(res["nobuildFilesRegex"], d, config)); err != nil { return fmt.Errorf("Error reading FlexibleAppVersion: %s", err) } + if err := d.Set("deployment", flattenAppEngineFlexibleAppVersionDeployment(res["deployment"], d, config)); err != nil { + return fmt.Errorf("Error reading FlexibleAppVersion: %s", err) + } if err := d.Set("endpoints_api_service", flattenAppEngineFlexibleAppVersionEndpointsApiService(res["endpointsApiService"], d, config)); err != nil { return fmt.Errorf("Error reading FlexibleAppVersion: %s", err) } @@ -1930,6 +1934,61 @@ func flattenAppEngineFlexibleAppVersionNobuildFilesRegex(v interface{}, d *schem return v } +func flattenAppEngineFlexibleAppVersionDeployment(v interface{}, d *schema.ResourceData, config *Config) interface{} { + original := v.(map[string]interface{}) + transformed := make(map[string]interface{}) + transformed["zip"] = d.Get("deployment.0.zip") + transformed["files"] = d.Get("deployment.0.files") + transformed["container"] = + flattenAppEngineFlexibleAppVersionDeploymentContainer(original["container"], d, config) + transformed["cloud_build_options"] = + flattenAppEngineFlexibleAppVersionDeploymentCloudBuildOptions(original["cloudBuildOptions"], d, config) + + return []interface{}{transformed} +} + +func flattenAppEngineFlexibleAppVersionDeploymentContainer(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["image"] = + flattenAppEngineFlexibleAppVersionDeploymentContainerImage(original["image"], d, config) + return []interface{}{transformed} +} + +func flattenAppEngineFlexibleAppVersionDeploymentContainerImage(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenAppEngineFlexibleAppVersionDeploymentCloudBuildOptions(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["app_yaml_path"] = + flattenAppEngineFlexibleAppVersionDeploymentCloudBuildOptionsAppYamlPath(original["appYamlPath"], d, config) + transformed["cloud_build_timeout"] = + flattenAppEngineFlexibleAppVersionDeploymentCloudBuildOptionsCloudBuildTimeout(original["cloudBuildTimeout"], d, config) + return []interface{}{transformed} +} + +func flattenAppEngineFlexibleAppVersionDeploymentCloudBuildOptionsAppYamlPath(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenAppEngineFlexibleAppVersionDeploymentCloudBuildOptionsCloudBuildTimeout(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + func flattenAppEngineFlexibleAppVersionEndpointsApiService(v interface{}, d *schema.ResourceData, config *Config) interface{} { if v == nil { return nil diff --git a/google/resource_app_engine_flexible_app_version_generated_test.go b/google/resource_app_engine_flexible_app_version_generated_test.go index 642d2cbc75e..8481a473a7f 100644 --- a/google/resource_app_engine_flexible_app_version_generated_test.go +++ b/google/resource_app_engine_flexible_app_version_generated_test.go @@ -44,7 +44,7 @@ func TestAccAppEngineFlexibleAppVersion_appEngineFlexibleAppVersionExample(t *te ResourceName: "google_app_engine_flexible_app_version.myapp_v1", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"beta_settings", "env_variables", "deployment", "entrypoint", "service", "noop_on_destroy"}, + ImportStateVerifyIgnore: []string{"beta_settings", "env_variables", "entrypoint", "service", "noop_on_destroy", "deployment.0.zip"}, }, }, }) diff --git a/google/resource_app_engine_flexible_app_version_test.go b/google/resource_app_engine_flexible_app_version_test.go index 390dbe07270..c201b9a3486 100644 --- a/google/resource_app_engine_flexible_app_version_test.go +++ b/google/resource_app_engine_flexible_app_version_test.go @@ -26,7 +26,7 @@ func TestAccAppEngineFlexibleAppVersion_update(t *testing.T) { ResourceName: "google_app_engine_flexible_app_version.foo", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"env_variables", "deployment", "entrypoint", "service", "noop_on_destroy"}, + ImportStateVerifyIgnore: []string{"env_variables", "deployment.0.files", "entrypoint", "service", "noop_on_destroy"}, }, { Config: testAccAppEngineFlexibleAppVersion_pythonUpdate(context), @@ -35,7 +35,7 @@ func TestAccAppEngineFlexibleAppVersion_update(t *testing.T) { ResourceName: "google_app_engine_flexible_app_version.foo", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"env_variables", "deployment", "entrypoint", "service", "noop_on_destroy"}, + ImportStateVerifyIgnore: []string{"env_variables", "deployment.0.files", "entrypoint", "service", "noop_on_destroy"}, }, }, })