| // Copyright (c) HashiCorp, Inc. |
| // SPDX-License-Identifier: MPL-2.0 |
| package dialogflowcx_test |
| |
| import ( |
| "testing" |
| |
| "github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest" |
| "github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar" |
| |
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| ) |
| |
| func TestAccDialogflowCXEnvironment_update(t *testing.T) { |
| t.Parallel() |
| |
| context := map[string]interface{}{ |
| "org_id": envvar.GetTestOrgFromEnv(t), |
| "billing_account": envvar.GetTestBillingAccountFromEnv(t), |
| "random_suffix": acctest.RandString(t, 10), |
| } |
| |
| acctest.VcrTest(t, resource.TestCase{ |
| PreCheck: func() { acctest.AccTestPreCheck(t) }, |
| ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), |
| Steps: []resource.TestStep{ |
| { |
| Config: testAccDialogflowCXEnvironment_basic(context), |
| }, |
| { |
| ResourceName: "google_dialogflow_cx_environment.development", |
| ImportState: true, |
| ImportStateVerify: true, |
| }, |
| { |
| Config: testAccDialogflowCXEnvironment_full(context), |
| }, |
| { |
| ResourceName: "google_dialogflow_cx_environment.development", |
| ImportState: true, |
| ImportStateVerify: true, |
| }, |
| }, |
| }) |
| } |
| |
| func testAccDialogflowCXEnvironment_basic(context map[string]interface{}) string { |
| return acctest.Nprintf(` |
| 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" |
| } |
| |
| 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" |
| } |
| |
| resource "google_dialogflow_cx_environment" "development" { |
| parent = google_dialogflow_cx_agent.agent_version.id |
| display_name = "Development" |
| version_configs { |
| version = google_dialogflow_cx_version.version1.id |
| } |
| } |
| `, context) |
| } |
| |
| func testAccDialogflowCXEnvironment_full(context map[string]interface{}) string { |
| return acctest.Nprintf(` |
| 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" |
| } |
| |
| 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" |
| } |
| |
| resource "google_dialogflow_cx_version" "version2" { |
| parent = google_dialogflow_cx_agent.agent_version.start_flow |
| display_name = "2.0.0" |
| description = "version 2.0.0" |
| } |
| |
| resource "google_dialogflow_cx_environment" "development" { |
| parent = google_dialogflow_cx_agent.agent_version.id |
| display_name = "Development updated" |
| version_configs { |
| version = google_dialogflow_cx_version.version2.id |
| } |
| } |
| `, context) |
| } |