From 1a68f307e2ce32da804769d145192570189898db Mon Sep 17 00:00:00 2001 From: Cameron Thornton Date: Thu, 5 Mar 2020 11:59:06 -0800 Subject: [PATCH] Make tier ignore_read (#3223) --- products/dialogflow/api.yaml | 5 ++-- products/dialogflow/terraform.yaml | 5 +--- .../post_create/dialogflow_agent_tier.go.erb | 28 ------------------- .../resource_dialogflow_agent_test.go.erb | 4 +-- 4 files changed, 5 insertions(+), 37 deletions(-) delete mode 100644 templates/terraform/post_create/dialogflow_agent_tier.go.erb diff --git a/products/dialogflow/api.yaml b/products/dialogflow/api.yaml index e5fdc23e3653..92322ceb4942 100644 --- a/products/dialogflow/api.yaml +++ b/products/dialogflow/api.yaml @@ -124,9 +124,8 @@ objects: * TIER_STANDARD: Standard tier. * TIER_ENTERPRISE: Enterprise tier (Essentials). * TIER_ENTERPRISE_PLUS: Enterprise tier (Plus). - NOTE: This field seems to have eventual consistency in the API. Updating this field to a new value, or even - creating a new agent with a tier that is different from a previous agent in the same project will take some - time to propagate. The provider will wait for the API to show consistency, which can lead to longer apply times. + NOTE: Due to consistency issues, the provider will not read this field from the API. Drift is possible between + the Terraform state and Dialogflow if the agent tier is changed outside of Terraform. values: - :TIER_STANDARD - :TIER_ENTERPRISE diff --git a/products/dialogflow/terraform.yaml b/products/dialogflow/terraform.yaml index 11adb781b635..7ec431400661 100644 --- a/products/dialogflow/terraform.yaml +++ b/products/dialogflow/terraform.yaml @@ -41,10 +41,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides matchMode: !ruby/object:Overrides::Terraform::PropertyOverride default_from_api: true tier: !ruby/object:Overrides::Terraform::PropertyOverride - default_from_api: true - custom_code: !ruby/object:Provider::Terraform::CustomCode - post_update: 'templates/terraform/post_create/dialogflow_agent_tier.go.erb' - post_create: 'templates/terraform/post_create/dialogflow_agent_tier.go.erb' + ignore_read: true # This is for copying files over files: !ruby/object:Provider::Config::Files diff --git a/templates/terraform/post_create/dialogflow_agent_tier.go.erb b/templates/terraform/post_create/dialogflow_agent_tier.go.erb deleted file mode 100644 index 2aabc8d5b0d4..000000000000 --- a/templates/terraform/post_create/dialogflow_agent_tier.go.erb +++ /dev/null @@ -1,28 +0,0 @@ - -// The tier field is eventually consistent, we need to test for consistency before moving on. -// Otherwise, the user will see diffs on the field. -if d.HasChange("tier") { - old, new := d.GetChange("tier") - readUrl, err := replaceVars(d, config, "{{DialogflowBasePath}}projects/{{project}}/agent") - if err != nil { - return fmt.Errorf("Error preparing read URL: %s",err) - } - stateConf := &resource.StateChangeConf{ - Pending: []string{old.(string)}, - Target: []string{new.(string)}, - Refresh: func() (interface{}, string, error) { - res, err := sendRequest(config, "GET", project, readUrl, nil) - if err != nil { - return 0, "", err - } - return res, res["tier"].(string), nil - }, - Timeout: 40 * time.Minute, - MinTimeout: 30 * time.Second, - ContinuousTargetOccurence: 12, - } - _, err = stateConf.WaitForState() - if err != nil { - return fmt.Errorf("Timed out waiting for agent tier to return correct value. Waiting for %s, got %s.", new, old) - } -} \ No newline at end of file diff --git a/third_party/terraform/tests/resource_dialogflow_agent_test.go.erb b/third_party/terraform/tests/resource_dialogflow_agent_test.go.erb index f3cbb27af3b6..0e2b648f410d 100644 --- a/third_party/terraform/tests/resource_dialogflow_agent_test.go.erb +++ b/third_party/terraform/tests/resource_dialogflow_agent_test.go.erb @@ -29,7 +29,7 @@ func TestAccDialogflowAgent_update(t *testing.T) { ResourceName: "google_dialogflow_agent.foobar", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"avatar_uri"}, + ImportStateVerifyIgnore: []string{"avatar_uri","tier"}, }, { Config: testAccDialogflowAgent_full2(projectID, orgID, agentNameUpdate), @@ -38,7 +38,7 @@ func TestAccDialogflowAgent_update(t *testing.T) { ResourceName: "google_dialogflow_agent.foobar", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"avatar_uri"}, + ImportStateVerifyIgnore: []string{"avatar_uri","tier"}, }, }, })