diff --git a/.changelog/4870.txt b/.changelog/4870.txt new file mode 100644 index 00000000000..884c8b79646 --- /dev/null +++ b/.changelog/4870.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +`google_dialogflow_cx_version` +``` diff --git a/google/dialogflow_cx_operation.go b/google/dialogflow_cx_operation.go new file mode 100644 index 00000000000..038ba0a7b47 --- /dev/null +++ b/google/dialogflow_cx_operation.go @@ -0,0 +1,72 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- +package google + +import ( + "encoding/json" + "fmt" + "time" +) + +type DialogflowCXOperationWaiter struct { + Config *Config + UserAgent string + CommonOperationWaiter +} + +func (w *DialogflowCXOperationWaiter) QueryOp() (interface{}, error) { + if w == nil { + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") + } + // Returns the proper get. + url := fmt.Sprintf("https://dialogflow.googleapis.com/v3/%s", w.CommonOperationWaiter.Op.Name) + + return sendRequest(w.Config, "GET", "", url, w.UserAgent, nil) +} + +func createDialogflowCXWaiter(config *Config, op map[string]interface{}, activity, userAgent string) (*DialogflowCXOperationWaiter, error) { + w := &DialogflowCXOperationWaiter{ + Config: config, + UserAgent: userAgent, + } + if err := w.CommonOperationWaiter.SetOp(op); err != nil { + return nil, err + } + return w, nil +} + +// nolint: deadcode,unused +func dialogflowCXOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, activity, userAgent string, timeout time.Duration) error { + w, err := createDialogflowCXWaiter(config, op, activity, userAgent) + if err != nil { + return err + } + if err := OperationWait(w, activity, timeout, config.PollInterval); err != nil { + return err + } + return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response) +} + +func dialogflowCXOperationWaitTime(config *Config, op map[string]interface{}, activity, userAgent string, timeout time.Duration) error { + if val, ok := op["name"]; !ok || val == "" { + // This was a synchronous call - there is no operation to wait for. + return nil + } + w, err := createDialogflowCXWaiter(config, op, activity, userAgent) + if err != nil { + // If w is nil, the op was synchronous. + return err + } + return OperationWait(w, activity, timeout, config.PollInterval) +} diff --git a/google/provider.go b/google/provider.go index 0915e56c932..99dab9f3ec3 100644 --- a/google/provider.go +++ b/google/provider.go @@ -791,9 +791,9 @@ func Provider() *schema.Provider { return provider } -// Generated resources: 208 +// Generated resources: 209 // Generated IAM resources: 90 -// Total generated resources: 298 +// Total generated resources: 299 func ResourceMap() map[string]*schema.Resource { resourceMap, _ := ResourceMapWithErrors() return resourceMap @@ -966,6 +966,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) { "google_dialogflow_cx_agent": resourceDialogflowCXAgent(), "google_dialogflow_cx_intent": resourceDialogflowCXIntent(), "google_dialogflow_cx_flow": resourceDialogflowCXFlow(), + "google_dialogflow_cx_version": resourceDialogflowCXVersion(), "google_dns_managed_zone": resourceDNSManagedZone(), "google_dns_policy": resourceDNSPolicy(), "google_dns_record_set": resourceDNSResourceDnsRecordSet(), diff --git a/google/resource_dialogflow_cx_version.go b/google/resource_dialogflow_cx_version.go new file mode 100644 index 00000000000..d1e1f30dd12 --- /dev/null +++ b/google/resource_dialogflow_cx_version.go @@ -0,0 +1,426 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "fmt" + "log" + "reflect" + "strings" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func resourceDialogflowCXVersion() *schema.Resource { + return &schema.Resource{ + Create: resourceDialogflowCXVersionCreate, + Read: resourceDialogflowCXVersionRead, + Update: resourceDialogflowCXVersionUpdate, + Delete: resourceDialogflowCXVersionDelete, + + Importer: &schema.ResourceImporter{ + State: resourceDialogflowCXVersionImport, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(40 * time.Minute), + Update: schema.DefaultTimeout(40 * time.Minute), + Delete: schema.DefaultTimeout(4 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "display_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringLenBetween(0, 64), + Description: `The human-readable name of the version. Limit of 64 characters.`, + }, + "description": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringLenBetween(0, 500), + Description: `The description of the version. The maximum length is 500 characters. If exceeded, the request is rejected.`, + }, + "parent": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: `The Flow to create an Version for. +Format: projects//locations//agents//flows/.`, + }, + "create_time": { + Type: schema.TypeString, + Computed: true, + Description: `A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, + }, + "name": { + Type: schema.TypeString, + Computed: true, + Description: `Format: projects//locations//agents//flows//versions/. Version ID is a self-increasing number generated by Dialogflow upon version creation.`, + }, + "nlu_settings": { + Type: schema.TypeList, + Computed: true, + Description: `The NLU settings of the flow at version creation.`, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "classification_threshold": { + Type: schema.TypeFloat, + Optional: true, + Description: `To filter out false positive results and still get variety in matched natural language inputs for your agent, you can tune the machine learning classification threshold. If the returned score value is less than the threshold value, then a no-match event will be triggered. +The score values range from 0.0 (completely uncertain) to 1.0 (completely certain). If set to 0.0, the default of 0.3 is used.`, + }, + "model_training_mode": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"MODEL_TRAINING_MODE_AUTOMATIC", "MODEL_TRAINING_MODE_MANUAL", ""}, false), + Description: `Indicates NLU model training mode. +* MODEL_TRAINING_MODE_AUTOMATIC: NLU model training is automatically triggered when a flow gets modified. User can also manually trigger model training in this mode. +* MODEL_TRAINING_MODE_MANUAL: User needs to manually trigger NLU model training. Best for large flows whose models take long time to train. Possible values: ["MODEL_TRAINING_MODE_AUTOMATIC", "MODEL_TRAINING_MODE_MANUAL"]`, + }, + "model_type": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{"MODEL_TYPE_STANDARD", "MODEL_TYPE_ADVANCED", ""}, false), + Description: `Indicates the type of NLU model. +* MODEL_TYPE_STANDARD: Use standard NLU model. +* MODEL_TYPE_ADVANCED: Use advanced NLU model. Possible values: ["MODEL_TYPE_STANDARD", "MODEL_TYPE_ADVANCED"]`, + }, + }, + }, + }, + "state": { + Type: schema.TypeString, + Computed: true, + Description: `The state of this version. +* RUNNING: Version is not ready to serve (e.g. training is running). +* SUCCEEDED: Training has succeeded and this version is ready to serve. +* FAILED: Version training failed.`, + }, + }, + UseJSONNumber: true, + } +} + +func resourceDialogflowCXVersionCreate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return err + } + + obj := make(map[string]interface{}) + displayNameProp, err := expandDialogflowCXVersionDisplayName(d.Get("display_name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("display_name"); !isEmptyValue(reflect.ValueOf(displayNameProp)) && (ok || !reflect.DeepEqual(v, displayNameProp)) { + obj["displayName"] = displayNameProp + } + descriptionProp, err := expandDialogflowCXVersionDescription(d.Get("description"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { + obj["description"] = descriptionProp + } + + url, err := replaceVars(d, config, "{{DialogflowCXBasePath}}{{parent}}/versions") + if err != nil { + return err + } + + log.Printf("[DEBUG] Creating new Version: %#v", obj) + billingProject := "" + + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := sendRequestWithTimeout(config, "POST", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutCreate)) + if err != nil { + return fmt.Errorf("Error creating Version: %s", err) + } + + // Store the ID now + id, err := replaceVars(d, config, "{{parent}}/versions/{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + // Use the resource in the operation response to populate + // identity fields and d.Id() before read + var opRes map[string]interface{} + err = dialogflowCXOperationWaitTimeWithResponse( + config, res, &opRes, "Creating Version", userAgent, + d.Timeout(schema.TimeoutCreate)) + if err != nil { + // The resource didn't actually create + d.SetId("") + return fmt.Errorf("Error waiting to create Version: %s", err) + } + + if err := d.Set("name", flattenDialogflowCXVersionName(opRes["name"], d, config)); err != nil { + return err + } + + // This may have caused the ID to update - update it if so. + id, err = replaceVars(d, config, "{{parent}}/versions/{{name}}") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + log.Printf("[DEBUG] Finished creating Version %q: %#v", d.Id(), res) + + return resourceDialogflowCXVersionRead(d, meta) +} + +func resourceDialogflowCXVersionRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return err + } + + url, err := replaceVars(d, config, "{{DialogflowCXBasePath}}{{parent}}/versions/{{name}}") + if err != nil { + return err + } + + billingProject := "" + + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := sendRequest(config, "GET", billingProject, url, userAgent, nil) + if err != nil { + return handleNotFoundError(err, d, fmt.Sprintf("DialogflowCXVersion %q", d.Id())) + } + + if err := d.Set("name", flattenDialogflowCXVersionName(res["name"], d, config)); err != nil { + return fmt.Errorf("Error reading Version: %s", err) + } + if err := d.Set("display_name", flattenDialogflowCXVersionDisplayName(res["displayName"], d, config)); err != nil { + return fmt.Errorf("Error reading Version: %s", err) + } + if err := d.Set("description", flattenDialogflowCXVersionDescription(res["description"], d, config)); err != nil { + return fmt.Errorf("Error reading Version: %s", err) + } + if err := d.Set("nlu_settings", flattenDialogflowCXVersionNluSettings(res["nluSettings"], d, config)); err != nil { + return fmt.Errorf("Error reading Version: %s", err) + } + if err := d.Set("create_time", flattenDialogflowCXVersionCreateTime(res["createTime"], d, config)); err != nil { + return fmt.Errorf("Error reading Version: %s", err) + } + if err := d.Set("state", flattenDialogflowCXVersionState(res["state"], d, config)); err != nil { + return fmt.Errorf("Error reading Version: %s", err) + } + + return nil +} + +func resourceDialogflowCXVersionUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return err + } + + billingProject := "" + + obj := make(map[string]interface{}) + displayNameProp, err := expandDialogflowCXVersionDisplayName(d.Get("display_name"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("display_name"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, displayNameProp)) { + obj["displayName"] = displayNameProp + } + descriptionProp, err := expandDialogflowCXVersionDescription(d.Get("description"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { + obj["description"] = descriptionProp + } + + url, err := replaceVars(d, config, "{{DialogflowCXBasePath}}{{parent}}/versions/{{name}}") + if err != nil { + return err + } + + log.Printf("[DEBUG] Updating Version %q: %#v", d.Id(), obj) + updateMask := []string{} + + if d.HasChange("display_name") { + updateMask = append(updateMask, "displayName") + } + + if d.HasChange("description") { + updateMask = append(updateMask, "description") + } + // updateMask is a URL parameter but not present in the schema, so replaceVars + // won't set it + url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")}) + if err != nil { + return err + } + + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := sendRequestWithTimeout(config, "PATCH", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutUpdate)) + + if err != nil { + return fmt.Errorf("Error updating Version %q: %s", d.Id(), err) + } else { + log.Printf("[DEBUG] Finished updating Version %q: %#v", d.Id(), res) + } + + err = dialogflowCXOperationWaitTime( + config, res, "Updating Version", userAgent, + d.Timeout(schema.TimeoutUpdate)) + + if err != nil { + return err + } + + return resourceDialogflowCXVersionRead(d, meta) +} + +func resourceDialogflowCXVersionDelete(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + userAgent, err := generateUserAgentString(d, config.userAgent) + if err != nil { + return err + } + + billingProject := "" + + url, err := replaceVars(d, config, "{{DialogflowCXBasePath}}{{parent}}/versions/{{name}}") + if err != nil { + return err + } + + var obj map[string]interface{} + log.Printf("[DEBUG] Deleting Version %q", d.Id()) + + // err == nil indicates that the billing_project value was found + if bp, err := getBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := sendRequestWithTimeout(config, "DELETE", billingProject, url, userAgent, obj, d.Timeout(schema.TimeoutDelete)) + if err != nil { + return handleNotFoundError(err, d, "Version") + } + + err = dialogflowCXOperationWaitTime( + config, res, "Deleting Version", userAgent, + d.Timeout(schema.TimeoutDelete)) + + if err != nil { + return err + } + + log.Printf("[DEBUG] Finished deleting Version %q: %#v", d.Id(), res) + return nil +} + +func resourceDialogflowCXVersionImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + config := meta.(*Config) + + // current import_formats can't import fields with forward slashes in their value and parent contains slashes + if err := parseImportId([]string{ + "(?P.+)/versions/(?P[^/]+)", + "(?P.+)/(?P[^/]+)", + }, d, config); err != nil { + return nil, err + } + + // Replace import id for the resource id + id, err := replaceVars(d, config, "{{parent}}/versions/{{name}}") + if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + return []*schema.ResourceData{d}, nil +} + +func flattenDialogflowCXVersionName(v interface{}, d *schema.ResourceData, config *Config) interface{} { + if v == nil { + return v + } + return NameFromSelfLinkStateFunc(v) +} + +func flattenDialogflowCXVersionDisplayName(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXVersionDescription(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXVersionNluSettings(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["model_type"] = + flattenDialogflowCXVersionNluSettingsModelType(original["modelType"], d, config) + transformed["classification_threshold"] = + flattenDialogflowCXVersionNluSettingsClassificationThreshold(original["classificationThreshold"], d, config) + transformed["model_training_mode"] = + flattenDialogflowCXVersionNluSettingsModelTrainingMode(original["modelTrainingMode"], d, config) + return []interface{}{transformed} +} +func flattenDialogflowCXVersionNluSettingsModelType(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXVersionNluSettingsClassificationThreshold(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXVersionNluSettingsModelTrainingMode(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXVersionCreateTime(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func flattenDialogflowCXVersionState(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + +func expandDialogflowCXVersionDisplayName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandDialogflowCXVersionDescription(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} diff --git a/google/resource_dialogflow_cx_version_generated_test.go b/google/resource_dialogflow_cx_version_generated_test.go new file mode 100644 index 00000000000..a8040a3a5bf --- /dev/null +++ b/google/resource_dialogflow_cx_version_generated_test.go @@ -0,0 +1,108 @@ +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package google + +import ( + "fmt" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func TestAccDialogflowCXVersion_dialogflowcxVersionFullExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": randString(t, 10), + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckDialogflowCXVersionDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccDialogflowCXVersion_dialogflowcxVersionFullExample(context), + }, + { + ResourceName: "google_dialogflow_cx_version.version_1", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"parent"}, + }, + }, + }) +} + +func testAccDialogflowCXVersion_dialogflowcxVersionFullExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_dialogflow_cx_agent" "agent" { + display_name = "tf-test-dialogflowcx-agent%{random_suffix}" + location = "global" + default_language_code = "en" + supported_language_codes = ["fr","de","es"] + time_zone = "America/New_York" + description = "Example description." + avatar_uri = "https://cloud.google.com/_static/images/cloud/icons/favicons/onecloud/super_cloud.png" + enable_stackdriver_logging = true + enable_spell_correction = true + speech_to_text_settings { + enable_speech_adaptation = true + } +} + + +resource "google_dialogflow_cx_version" "version_1" { + parent = google_dialogflow_cx_agent.agent.start_flow + display_name = "1.0.0" + description = "version 1.0.0" +} +`, context) +} + +func testAccCheckDialogflowCXVersionDestroyProducer(t *testing.T) func(s *terraform.State) error { + return func(s *terraform.State) error { + for name, rs := range s.RootModule().Resources { + if rs.Type != "google_dialogflow_cx_version" { + continue + } + if strings.HasPrefix(name, "data.") { + continue + } + + config := googleProviderConfig(t) + + url, err := replaceVarsForTest(config, rs, "{{DialogflowCXBasePath}}{{parent}}/versions/{{name}}") + if err != nil { + return err + } + + billingProject := "" + + if config.BillingProject != "" { + billingProject = config.BillingProject + } + + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) + if err == nil { + return fmt.Errorf("DialogflowCXVersion still exists at %s", url) + } + } + + return nil + } +} diff --git a/google/resource_dialogflowcx_version_test.go b/google/resource_dialogflowcx_version_test.go new file mode 100644 index 00000000000..81fa470d206 --- /dev/null +++ b/google/resource_dialogflowcx_version_test.go @@ -0,0 +1,104 @@ +package google + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccDialogflowCXVersion_update(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "org_id": getTestOrgFromEnv(t), + "billing_account": getTestBillingAccountFromEnv(t), + "random_suffix": randString(t, 10), + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDialogflowCXVersion_basic(context), + }, + { + ResourceName: "google_dialogflow_cx_version.version1", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccDialogflowCXVersion_full(context), + }, + { + ResourceName: "google_dialogflow_cx_version.version1", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccDialogflowCXVersion_basic(context map[string]interface{}) string { + return Nprintf(` + resource "google_service_account" "dialogflowcx_service_account" { + account_id = "tf-test-dialogflow-%{random_suffix}" + } + + resource "google_project_iam_member" "agent_create" { + role = "roles/dialogflow.admin" + member = "serviceAccount:${google_service_account.dialogflowcx_service_account.email}" + } + + resource "google_dialogflow_cx_agent" "agent_version" { + display_name = "tf-test-%{random_suffix}" + location = "global" + default_language_code = "en" + supported_language_codes = ["fr","de","es"] + time_zone = "America/New_York" + description = "Description 1." + avatar_uri = "https://storage.cloud.google.com/dialogflow-test-host-image/cloud-logo.png" + depends_on = [google_project_iam_member.agent_create] + } + + resource "google_dialogflow_cx_version" "version1" { + parent = google_dialogflow_cx_agent.agent_version.start_flow + display_name = "1.0.0" + description = "version 1.0.0" + } + `, context) +} + +func testAccDialogflowCXVersion_full(context map[string]interface{}) string { + return Nprintf(` + resource "google_service_account" "dialogflowcx_service_account" { + account_id = "tf-test-dialogflow-%{random_suffix}" + } + + resource "google_project_iam_member" "agent_create" { + role = "roles/dialogflow.admin" + member = "serviceAccount:${google_service_account.dialogflowcx_service_account.email}" + } + + resource "google_dialogflow_cx_agent" "agent_version" { + display_name = "tf-test-%{random_suffix}update" + location = "global" + default_language_code = "en" + supported_language_codes = ["no"] + time_zone = "Europe/London" + description = "Description 2!" + avatar_uri = "https://storage.cloud.google.com/dialogflow-test-host-image/cloud-logo-2.png" + enable_stackdriver_logging = true + enable_spell_correction = true + speech_to_text_settings { + enable_speech_adaptation = true + } + depends_on = [google_project_iam_member.agent_create] + } + resource "google_dialogflow_cx_version" "version1" { + parent = google_dialogflow_cx_agent.agent_version.start_flow + display_name = "1.0.0" + description = "version 1.0.0" + } + `, context) +} diff --git a/website/docs/r/dialogflow_cx_version.html.markdown b/website/docs/r/dialogflow_cx_version.html.markdown new file mode 100644 index 00000000000..4ecca19dc42 --- /dev/null +++ b/website/docs/r/dialogflow_cx_version.html.markdown @@ -0,0 +1,151 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in +# .github/CONTRIBUTING.md. +# +# ---------------------------------------------------------------------------- +subcategory: "Dialogflow CX" +layout: "google" +page_title: "Google: google_dialogflow_cx_version" +sidebar_current: "docs-google-dialogflow-cx-version" +description: |- + You can create multiple versions of your agent flows and deploy them to separate serving environments. +--- + +# google\_dialogflow\_cx\_version + +You can create multiple versions of your agent flows and deploy them to separate serving environments. +When you edit a flow, you are editing a draft flow. At any point, you can save a draft flow as a flow version. A flow version is an immutable snapshot of your flow data and associated agent data like intents, entities, webhooks, pages, route groups, etc. + + +To get more information about Version, see: + +* [API documentation](https://cloud.google.com/dialogflow/cx/docs/reference/rest/v3/projects.locations.agents.flows.versions) +* How-to Guides + * [Official Documentation](https://cloud.google.com/dialogflow/cx/docs) + + +## Example Usage - Dialogflowcx Version Full + + +```hcl +resource "google_dialogflow_cx_agent" "agent" { + display_name = "dialogflowcx-agent" + location = "global" + default_language_code = "en" + supported_language_codes = ["fr","de","es"] + time_zone = "America/New_York" + description = "Example description." + avatar_uri = "https://cloud.google.com/_static/images/cloud/icons/favicons/onecloud/super_cloud.png" + enable_stackdriver_logging = true + enable_spell_correction = true + speech_to_text_settings { + enable_speech_adaptation = true + } +} + + +resource "google_dialogflow_cx_version" "version_1" { + parent = google_dialogflow_cx_agent.agent.start_flow + display_name = "1.0.0" + description = "version 1.0.0" +} +``` + +## Argument Reference + +The following arguments are supported: + + +* `display_name` - + (Required) + The human-readable name of the version. Limit of 64 characters. + + +- - - + + +* `description` - + (Optional) + The description of the version. The maximum length is 500 characters. If exceeded, the request is rejected. + +* `parent` - + (Optional) + The Flow to create an Version for. + Format: projects//locations//agents//flows/. + + +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are exported: + +* `id` - an identifier for the resource with format `{{parent}}/versions/{{name}}` + +* `name` - + Format: projects//locations//agents//flows//versions/. Version ID is a self-increasing number generated by Dialogflow upon version creation. + +* `nlu_settings` - + The NLU settings of the flow at version creation. + Structure is documented below. + +* `create_time` - + A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z". + +* `state` - + The state of this version. + * RUNNING: Version is not ready to serve (e.g. training is running). + * SUCCEEDED: Training has succeeded and this version is ready to serve. + * FAILED: Version training failed. + + +The `nlu_settings` block contains: + +* `model_type` - + (Optional) + Indicates the type of NLU model. + * MODEL_TYPE_STANDARD: Use standard NLU model. + * MODEL_TYPE_ADVANCED: Use advanced NLU model. + Possible values are `MODEL_TYPE_STANDARD` and `MODEL_TYPE_ADVANCED`. + +* `classification_threshold` - + (Optional) + To filter out false positive results and still get variety in matched natural language inputs for your agent, you can tune the machine learning classification threshold. If the returned score value is less than the threshold value, then a no-match event will be triggered. + The score values range from 0.0 (completely uncertain) to 1.0 (completely certain). If set to 0.0, the default of 0.3 is used. + +* `model_training_mode` - + (Optional) + Indicates NLU model training mode. + * MODEL_TRAINING_MODE_AUTOMATIC: NLU model training is automatically triggered when a flow gets modified. User can also manually trigger model training in this mode. + * MODEL_TRAINING_MODE_MANUAL: User needs to manually trigger NLU model training. Best for large flows whose models take long time to train. + Possible values are `MODEL_TRAINING_MODE_AUTOMATIC` and `MODEL_TRAINING_MODE_MANUAL`. + +## Timeouts + +This resource provides the following +[Timeouts](/docs/configuration/resources.html#timeouts) configuration options: + +- `create` - Default is 40 minutes. +- `update` - Default is 40 minutes. +- `delete` - Default is 4 minutes. + +## Import + + +Version can be imported using any of these accepted formats: + +``` +$ terraform import google_dialogflow_cx_version.default {{parent}}/versions/{{name}} +$ terraform import google_dialogflow_cx_version.default {{parent}}/{{name}} +``` diff --git a/website/google.erb b/website/google.erb index a0349bd21b5..a59120a1413 100644 --- a/website/google.erb +++ b/website/google.erb @@ -2320,6 +2320,10 @@ google_dialogflow_cx_intent +
  • + google_dialogflow_cx_version +
  • +