Skip to content

Commit

Permalink
Make tier ignore_read (#3223) (#1829)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Mar 5, 2020
1 parent 980607a commit 34414fa
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 73 deletions.
3 changes: 3 additions & 0 deletions .changelog/3223.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
dialogflow: Changed `google_dialogflow_agent` to not read `tier` status
```
69 changes: 2 additions & 67 deletions google-beta/resource_dialogflow_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"reflect"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
)
Expand Down Expand Up @@ -122,16 +121,14 @@ using @sys.any or very large developer entities.`,
},
"tier": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"TIER_STANDARD", "TIER_ENTERPRISE", "TIER_ENTERPRISE_PLUS", ""}, false),
Description: `The agent tier. If not specified, TIER_STANDARD is assumed.
* 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.`,
},
"avatar_uri_backend": {
Type: schema.TypeString,
Expand Down Expand Up @@ -244,34 +241,6 @@ func resourceDialogflowAgentCreate(d *schema.ResourceData, meta interface{}) err

log.Printf("[DEBUG] Finished creating Agent %q: %#v", d.Id(), res)

// 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)
}
}

return resourceDialogflowAgentRead(d, meta)
}

Expand Down Expand Up @@ -326,9 +295,6 @@ func resourceDialogflowAgentRead(d *schema.ResourceData, meta interface{}) error
if err := d.Set("api_version", flattenDialogflowAgentApiVersion(res["apiVersion"], d, config)); err != nil {
return fmt.Errorf("Error reading Agent: %s", err)
}
if err := d.Set("tier", flattenDialogflowAgentTier(res["tier"], d, config)); err != nil {
return fmt.Errorf("Error reading Agent: %s", err)
}

return nil
}
Expand Down Expand Up @@ -421,33 +387,6 @@ func resourceDialogflowAgentUpdate(d *schema.ResourceData, meta interface{}) err
return fmt.Errorf("Error updating Agent %q: %s", d.Id(), err)
}

// 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)
}
}
return resourceDialogflowAgentRead(d, meta)
}

Expand Down Expand Up @@ -534,10 +473,6 @@ func flattenDialogflowAgentApiVersion(v interface{}, d *schema.ResourceData, con
return v
}

func flattenDialogflowAgentTier(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func expandDialogflowAgentDisplayName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
Expand Down
2 changes: 1 addition & 1 deletion google-beta/resource_dialogflow_agent_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestAccDialogflowAgent_dialogflowAgentFullExample(t *testing.T) {
ResourceName: "google_dialogflow_agent.full_agent",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"avatar_uri"},
ImportStateVerifyIgnore: []string{"avatar_uri", "tier"},
},
},
})
Expand Down
4 changes: 2 additions & 2 deletions google-beta/resource_dialogflow_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,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),
Expand All @@ -36,7 +36,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"},
},
},
})
Expand Down
5 changes: 2 additions & 3 deletions website/docs/r/dialogflow_agent.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ The following arguments are supported:
* 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.

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.
Expand Down

0 comments on commit 34414fa

Please sign in to comment.