-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dialogflow EntityType Resource (#3487)
- Loading branch information
Showing
4 changed files
with
242 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
templates/terraform/examples/dialogflow_entity_type_basic.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
resource "google_dialogflow_agent" "basic_agent" { | ||
display_name = "example_agent" | ||
default_language_code = "en" | ||
time_zone = "America/New_York" | ||
} | ||
|
||
resource "google_dialogflow_entity_type" "<%= ctx[:primary_resource_id] %>" { | ||
depends_on = [google_dialogflow_agent.basic_agent] | ||
display_name = "<%= ctx[:vars]["entity_type_name"] %>" | ||
kind = "KIND_MAP" | ||
entities { | ||
value = "value1" | ||
synonyms = ["synonym1","synonym2"] | ||
} | ||
entities { | ||
value = "value2" | ||
synonyms = ["synonym3","synonym4"] | ||
} | ||
} |
141 changes: 141 additions & 0 deletions
141
third_party/terraform/tests/resource_dialogflow_entity_type_test.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
<% autogen_exception -%> | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/terraform" | ||
) | ||
func TestAccDialogflowEntityType_update(t *testing.T) { | ||
t.Parallel() | ||
|
||
context := map[string]interface{}{ | ||
"org_id": getTestOrgFromEnv(t), | ||
"billing_account": getTestBillingAccountFromEnv(t), | ||
"random_suffix": acctest.RandString(10), | ||
} | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDialogflowEntityType_full1(context), | ||
}, | ||
{ | ||
ResourceName: "google_dialogflow_entity_type.foobar", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
{ | ||
Config: testAccDialogflowEntityType_full2(context), | ||
}, | ||
{ | ||
ResourceName: "google_dialogflow_entity_type.foobar", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDialogflowEntityType_full1(context map[string]interface{}) string { | ||
return Nprintf(` | ||
resource "google_project" "agent_project" { | ||
name = "tf-test-dialogflow-%{random_suffix}" | ||
project_id = "tf-test-dialogflow-%{random_suffix}" | ||
org_id = "%{org_id}" | ||
billing_account = "%{billing_account}" | ||
} | ||
|
||
resource "google_project_service" "agent_project" { | ||
project = google_project.agent_project.project_id | ||
service = "dialogflow.googleapis.com" | ||
disable_dependent_services = false | ||
} | ||
|
||
resource "google_service_account" "dialogflow_service_account" { | ||
account_id = "tf-test-dialogflow-%{random_suffix}" | ||
} | ||
|
||
resource "google_project_iam_member" "agent_create" { | ||
project = google_project_service.agent_project.project | ||
role = "roles/dialogflow.admin" | ||
member = "serviceAccount:${google_service_account.dialogflow_service_account.email}" | ||
} | ||
|
||
resource "google_dialogflow_agent" "agent" { | ||
project = google_project.agent_project.project_id | ||
display_name = "tf-test-agent-%{random_suffix}" | ||
default_language_code = "en" | ||
time_zone = "America/New_York" | ||
depends_on = [google_project_iam_member.agent_create] | ||
} | ||
|
||
resource "google_dialogflow_entity_type" "foobar" { | ||
depends_on = [google_dialogflow_agent.agent] | ||
project = google_project.agent_project.project_id | ||
display_name = "tf-test-entity-%{random_suffix}" | ||
kind = "KIND_MAP" | ||
enable_fuzzy_extraction = true | ||
entities { | ||
value = "value1" | ||
synonyms = ["synonym1","synonym2"] | ||
} | ||
entities { | ||
value = "value2" | ||
synonyms = ["synonym3","synonym4"] | ||
} | ||
} | ||
`, context) | ||
} | ||
|
||
func testAccDialogflowEntityType_full2(context map[string]interface{}) string { | ||
return Nprintf(` | ||
resource "google_project" "agent_project" { | ||
name = "tf-test-dialogflow-%{random_suffix}" | ||
project_id = "tf-test-dialogflow-%{random_suffix}" | ||
org_id = "%{org_id}" | ||
billing_account = "%{billing_account}" | ||
} | ||
|
||
resource "google_project_service" "agent_project" { | ||
project = google_project.agent_project.project_id | ||
service = "dialogflow.googleapis.com" | ||
disable_dependent_services = false | ||
} | ||
|
||
resource "google_service_account" "dialogflow_service_account" { | ||
account_id = "tf-test-dialogflow-%{random_suffix}" | ||
} | ||
|
||
resource "google_project_iam_member" "agent_create" { | ||
project = google_project_service.agent_project.project | ||
role = "roles/dialogflow.admin" | ||
member = "serviceAccount:${google_service_account.dialogflow_service_account.email}" | ||
} | ||
|
||
resource "google_dialogflow_agent" "agent" { | ||
project = google_project.agent_project.project_id | ||
display_name = "tf-test-agent-%{random_suffix}" | ||
default_language_code = "en" | ||
time_zone = "America/New_York" | ||
depends_on = [google_project_iam_member.agent_create] | ||
} | ||
|
||
resource "google_dialogflow_entity_type" "foobar" { | ||
depends_on = [google_dialogflow_agent.agent] | ||
project = google_project.agent_project.project_id | ||
display_name = "tf-test-entity2-%{random_suffix}" | ||
kind = "KIND_LIST" | ||
enable_fuzzy_extraction = false | ||
entities { | ||
value = "value1" | ||
synonyms = ["value1"] | ||
} | ||
} | ||
`, context) | ||
} |