@@ -259,6 +259,39 @@ func TestAccDataflowJob_streamUpdate(t *testing.T) {
259259 })
260260}
261261
262+ func TestAccDataflowJob_virtualUpdate (t * testing.T ) {
263+ // Dataflow responses include serialized java classes and bash commands
264+ // This makes body comparison infeasible
265+ skipIfVcr (t )
266+ t .Parallel ()
267+
268+ suffix := randString (t , 10 )
269+
270+ // If the update is virtual-only, the ID should remain the same after updating.
271+ var id string
272+ vcrTest (t , resource.TestCase {
273+ PreCheck : func () { testAccPreCheck (t ) },
274+ Providers : testAccProviders ,
275+ CheckDestroy : testAccCheckDataflowJobDestroyProducer (t ),
276+ Steps : []resource.TestStep {
277+ {
278+ Config : testAccDataflowJob_virtualUpdate (suffix , "drain" ),
279+ Check : resource .ComposeTestCheckFunc (
280+ testAccDataflowJobExists (t , "google_dataflow_job.pubsub_stream" ),
281+ testAccDataflowSetId (t , "google_dataflow_job.pubsub_stream" , & id ),
282+ ),
283+ },
284+ {
285+ Config : testAccDataflowJob_virtualUpdate (suffix , "cancel" ),
286+ Check : resource .ComposeTestCheckFunc (
287+ testAccDataflowCheckId (t , "google_dataflow_job.pubsub_stream" , & id ),
288+ resource .TestCheckResourceAttr ("google_dataflow_job.pubsub_stream" , "on_delete" , "cancel" ),
289+ ),
290+ },
291+ },
292+ })
293+ }
294+
262295func testAccCheckDataflowJobDestroyProducer (t * testing.T ) func (s * terraform.State ) error {
263296 return func (s * terraform.State ) error {
264297 for _ , rs := range s .RootModule ().Resources {
@@ -323,6 +356,32 @@ func testAccDataflowJobExists(t *testing.T, resource string) resource.TestCheckF
323356 }
324357}
325358
359+ func testAccDataflowSetId (t * testing.T , resource string , id * string ) resource.TestCheckFunc {
360+ return func (s * terraform.State ) error {
361+ rs , ok := s .RootModule ().Resources [resource ]
362+ if ! ok {
363+ return fmt .Errorf ("resource %q not in state" , resource )
364+ }
365+
366+ * id = rs .Primary .ID
367+ return nil
368+ }
369+ }
370+
371+ func testAccDataflowCheckId (t * testing.T , resource string , id * string ) resource.TestCheckFunc {
372+ return func (s * terraform.State ) error {
373+ rs , ok := s .RootModule ().Resources [resource ]
374+ if ! ok {
375+ return fmt .Errorf ("resource %q not in state" , resource )
376+ }
377+
378+ if rs .Primary .ID != * id {
379+ return fmt .Errorf ("ID did not match. Expected %s, received %s" , * id , rs .Primary .ID )
380+ }
381+ return nil
382+ }
383+ }
384+
326385func testAccDataflowJobHasNetwork (t * testing.T , res , expected string ) resource.TestCheckFunc {
327386 return func (s * terraform.State ) error {
328387 instanceTmpl , err := testAccDataflowJobGetGeneratedInstanceTemplate (t , s , res )
@@ -772,3 +831,25 @@ resource "google_dataflow_job" "pubsub_stream" {
772831}
773832 ` , suffix , suffix , suffix , suffix , testDataflowJobTemplateTextToPubsub , tempLocation )
774833}
834+
835+ func testAccDataflowJob_virtualUpdate (suffix , onDelete string ) string {
836+ return fmt .Sprintf (`
837+ resource "google_pubsub_topic" "topic" {
838+ name = "tf-test-dataflow-job-%s"
839+ }
840+ resource "google_storage_bucket" "bucket" {
841+ name = "tf-test-bucket-%s"
842+ force_destroy = true
843+ }
844+ resource "google_dataflow_job" "pubsub_stream" {
845+ name = "tf-test-dataflow-job-%s"
846+ template_gcs_path = "%s"
847+ temp_gcs_location = google_storage_bucket.bucket.url
848+ parameters = {
849+ inputFilePattern = "${google_storage_bucket.bucket.url}/*.json"
850+ outputTopic = google_pubsub_topic.topic.id
851+ }
852+ on_delete = "%s"
853+ }
854+ ` , suffix , suffix , suffix , testDataflowJobTemplateTextToPubsub , onDelete )
855+ }
0 commit comments