@@ -69,6 +69,40 @@ func TestAccPubsubTopic_cmek(t *testing.T) {
69
69
})
70
70
}
71
71
72
+ func TestAccPubsubTopic_schema (t * testing.T ) {
73
+ t .Parallel ()
74
+
75
+ schema1 := fmt .Sprintf ("tf-test-schema-%s" , RandString (t , 10 ))
76
+ schema2 := fmt .Sprintf ("tf-test-schema-%s" , RandString (t , 10 ))
77
+ topic := fmt .Sprintf ("tf-test-topic-%s" , RandString (t , 10 ))
78
+
79
+ VcrTest (t , resource.TestCase {
80
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
81
+ ProtoV5ProviderFactories : ProtoV5ProviderFactories (t ),
82
+ CheckDestroy : testAccCheckPubsubTopicDestroyProducer (t ),
83
+ Steps : []resource.TestStep {
84
+ {
85
+ Config : testAccPubsubTopic_updateWithSchema (topic , schema1 ),
86
+ },
87
+ {
88
+ ResourceName : "google_pubsub_topic.bar" ,
89
+ ImportStateId : topic ,
90
+ ImportState : true ,
91
+ ImportStateVerify : true ,
92
+ },
93
+ {
94
+ Config : testAccPubsubTopic_updateWithNewSchema (topic , schema2 ),
95
+ },
96
+ {
97
+ ResourceName : "google_pubsub_topic.bar" ,
98
+ ImportStateId : topic ,
99
+ ImportState : true ,
100
+ ImportStateVerify : true ,
101
+ },
102
+ },
103
+ })
104
+ }
105
+
72
106
func testAccPubsubTopic_update (topic , key , value string ) string {
73
107
return fmt .Sprintf (`
74
108
resource "google_pubsub_topic" "foo" {
@@ -105,3 +139,39 @@ resource "google_pubsub_topic" "topic" {
105
139
}
106
140
` , topicName , kmsKey )
107
141
}
142
+
143
+ func testAccPubsubTopic_updateWithSchema (topic , schema string ) string {
144
+ return fmt .Sprintf (`
145
+ resource "google_pubsub_schema" "foo" {
146
+ name = "%s"
147
+ type = "PROTOCOL_BUFFER"
148
+ definition = "syntax = \"proto3\";\nmessage Results {\nstring f1 = 1;\n}"
149
+ }
150
+
151
+ resource "google_pubsub_topic" "bar" {
152
+ name = "%s"
153
+ schema_settings {
154
+ schema = google_pubsub_schema.foo.id
155
+ encoding = "BINARY"
156
+ }
157
+ }
158
+ ` , schema , topic )
159
+ }
160
+
161
+ func testAccPubsubTopic_updateWithNewSchema (topic , schema string ) string {
162
+ return fmt .Sprintf (`
163
+ resource "google_pubsub_schema" "foo" {
164
+ name = "%s"
165
+ type = "PROTOCOL_BUFFER"
166
+ definition = "syntax = \"proto3\";\nmessage Results {\nstring f1 = 1;\n}"
167
+ }
168
+
169
+ resource "google_pubsub_topic" "bar" {
170
+ name = "%s"
171
+ schema_settings {
172
+ schema = google_pubsub_schema.foo.id
173
+ encoding = "JSON"
174
+ }
175
+ }
176
+ ` , schema , topic )
177
+ }
0 commit comments