1717package modelarmor_test
1818
1919import (
20- "bytes"
2120 "fmt"
2221 "testing"
23- "text/template"
2422
2523 "github.com/hashicorp/terraform-plugin-testing/helper/resource"
2624 "github.com/hashicorp/terraform-plugin-testing/plancheck"
2725
2826 "github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
2927)
3028
31- // Helper function to expand a template
32- func expandTemplate (tmplStr string , data map [string ]interface {}) (string , error ) {
33- tmpl , err := template .New ("config" ).Parse (tmplStr )
34- if err != nil {
35- return "" , err
36- }
37- var buf bytes.Buffer
38- err = tmpl .Execute (& buf , data )
39- if err != nil {
40- return "" , err
41- }
42- return buf .String (), nil
43- }
44-
4529func TestAccModelArmorTemplate_basic (t * testing.T ) {
4630 t .Parallel ()
4731
@@ -58,13 +42,7 @@ func TestAccModelArmorTemplate_basic(t *testing.T) {
5842 CheckDestroy : testAccCheckModelArmorTemplateDestroyProducer (t ),
5943 Steps : []resource.TestStep {
6044 {
61- Config : func () string {
62- cfg , err := testAccModelArmorTemplate_basic_config (basicContext )
63- if err != nil {
64- t .Fatalf ("Failed to expand basic config template: %v" , err )
65- }
66- return cfg
67- }(),
45+ Config : testAccModelArmorTemplate_basic_config (basicContext ),
6846 },
6947 {
7048 ResourceName : "google_model_armor_template.template-basic" ,
@@ -75,19 +53,18 @@ func TestAccModelArmorTemplate_basic(t *testing.T) {
7553 })
7654}
7755
78- func testAccModelArmorTemplate_basic_config (context map [string ]interface {}) ( string , error ) {
79- const basic_template = `
56+ func testAccModelArmorTemplate_basic_config (context map [string ]interface {}) string {
57+ return acctest . Nprintf ( `
8058resource "google_model_armor_template" "template-basic" {
81- location = "{{. location} }"
82- template_id = "{{. templateId} }"
59+ location = "%{ location}"
60+ template_id = "%{ templateId}"
8361 filter_config {
8462
8563 }
8664 template_metadata {
8765
8866 }
89- }`
90- return expandTemplate (basic_template , context )
67+ }` , context )
9168}
9269
9370func TestAccModelArmorTemplate_update (t * testing.T ) {
@@ -96,6 +73,7 @@ func TestAccModelArmorTemplate_update(t *testing.T) {
9673 templateId := fmt .Sprintf ("modelarmor-test-update-%s" , acctest .RandString (t , 5 ))
9774
9875 context := map [string ]interface {}{
76+ "location" : "us-central1" ,
9977 "templateId" : templateId ,
10078 }
10179
@@ -134,7 +112,7 @@ func TestAccModelArmorTemplate_update(t *testing.T) {
134112func testAccModelArmorTemplate_initial (context map [string ]interface {}) string {
135113 return acctest .Nprintf (`
136114 resource "google_model_armor_template" "test-resource" {
137- location = "us-central1 "
115+ location = "%{location} "
138116 template_id = "%{templateId}"
139117 labels = {
140118 "test-label" = "env-testing-initial"
0 commit comments