@@ -643,6 +643,50 @@ func TestAccDataflowFlexTemplateJob_enableStreamingEngine(t *testing.T) {
643
643
})
644
644
}
645
645
646
+ func TestAccDataflowFlexTemplateJob_workerPoolsFallback(t *testing.T) {
647
+ acctest.SkipIfVcr(t)
648
+ t.Parallel()
649
+
650
+ context1 := map[string]interface{}{
651
+ "random_id": acctest.RandString(t, 10),
652
+ "max_workers": 2,
653
+ "num_workers": 1,
654
+ "machine_type": `"n1-standard-1"`,
655
+ }
656
+
657
+ context2 := map[string]interface{}{
658
+ "random_id": context1["random_id"],
659
+ "max_workers": 3,
660
+ "num_workers": 2,
661
+ "machine_type": `"n1-standard-1"`,
662
+ }
663
+
664
+ resource.Test(t, resource.TestCase{
665
+ PreCheck: func() { acctest.AccTestPreCheck(t) },
666
+ ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
667
+ CheckDestroy: testAccCheckDataflowJobDestroyProducer(t),
668
+ Steps: []resource.TestStep{
669
+ {
670
+ Config: testAccDataflowFlexTemplateJob_workerPoolFallback(context1),
671
+ Check: resource.ComposeTestCheckFunc(
672
+ testAccDataflowFlexJobExists(t, "google_dataflow_flex_template_job.flex_job", false),
673
+ resource.TestCheckResourceAttr("google_dataflow_flex_template_job.flex_job", "num_workers", "1"),
674
+ resource.TestCheckResourceAttr("google_dataflow_flex_template_job.flex_job", "max_workers", "2"),
675
+ ),
676
+ },
677
+ {
678
+ Config: testAccDataflowFlexTemplateJob_workerPoolFallback(context2),
679
+ Check: resource.ComposeTestCheckFunc(
680
+ testAccDataflowFlexJobExists(t, "google_dataflow_flex_template_job.flex_job", true),
681
+ resource.TestCheckResourceAttr("google_dataflow_flex_template_job.flex_job", "num_workers", "2"),
682
+ resource.TestCheckResourceAttr("google_dataflow_flex_template_job.flex_job", "max_workers", "3"),
683
+ ),
684
+ },
685
+ },
686
+ })
687
+ }
688
+
689
+
646
690
func testAccDataflowFlexTemplateJobHasNetwork(t *testing.T, res, expected string, wait bool) resource.TestCheckFunc {
647
691
return func(s *terraform.State) error {
648
692
instanceTmpl, err := testAccDataflowFlexTemplateGetGeneratedInstanceTemplate(t, s, res)
@@ -2042,4 +2086,72 @@ resource "google_dataflow_flex_template_job" "flex_job" {
2042
2086
}
2043
2087
`, topicName, bucket, job)
2044
2088
}
2089
+
2090
+ func testAccDataflowFlexTemplateJob_workerPoolFallback(context map[string]interface{}) string {
2091
+ return acctest.Nprintf(`
2092
+ resource "google_pubsub_topic" "example" {
2093
+ name = "tf-test-topic-%{random_id}"
2094
+ }
2095
+
2096
+ data "google_storage_bucket_object" "flex_template" {
2097
+ name = "latest/flex/Streaming_Data_Generator"
2098
+ bucket = "dataflow-templates"
2099
+ }
2100
+
2101
+ resource "google_storage_bucket" "bucket" {
2102
+ name = "tf-test-bucket-%{random_id}"
2103
+ location = "US-CENTRAL1"
2104
+ force_destroy = true
2105
+ uniform_bucket_level_access = true
2106
+ }
2107
+
2108
+ resource "google_storage_bucket_object" "schema" {
2109
+ name = "schema-%{random_id}.json"
2110
+ bucket = google_storage_bucket.bucket.name
2111
+ content = <<EOF
2112
+ {
2113
+ "eventId": "{{"{{"}}uuid(){{"}}"}}",
2114
+ "eventTimestamp": {{"{{"}}timestamp(){{"}}"}},
2115
+ "ipv4": "{{"{{"}}ipv4(){{"}}"}}",
2116
+ "ipv6": "{{"{{"}}ipv6(){{"}}"}}",
2117
+ "country": "{{"{{"}}country(){{"}}"}}",
2118
+ "username": "{{"{{"}}username(){{"}}"}}",
2119
+ "quest": "{{"{{"}}random("A Break In the Ice", "Ghosts of Perdition", "Survive the Low Road"){{"}}"}}",
2120
+ "score": {{"{{"}}integer(100, 10000){{"}}"}},
2121
+ "completed": {{"{{"}}bool(){{"}}"}}
2122
+ }
2123
+ EOF
2124
+ }
2125
+
2126
+ resource "google_compute_network" "test-network" {
2127
+ name = "tf-test-network-%{random_id}"
2128
+ auto_create_subnetworks = false
2129
+ }
2130
+
2131
+ resource "google_compute_subnetwork" "test-subnetwork" {
2132
+ name = "tf-test-subnetwork-%{random_id}"
2133
+ ip_cidr_range = "192.168.0.0/24"
2134
+ region = "us-central1"
2135
+ network = google_compute_network.test-network.id
2136
+ }
2137
+
2138
+ resource "google_dataflow_flex_template_job" "flex_job" {
2139
+ name = "tf-test-flex-job-%{random_id}"
2140
+ container_spec_gcs_path = "gs://${data.google_storage_bucket_object.flex_template.bucket}/${data.google_storage_bucket_object.flex_template.name}"
2141
+ on_delete = "cancel"
2142
+ parameters = {
2143
+ schemaLocation = "gs://${google_storage_bucket_object.schema.bucket}/schema-%{random_id}.json"
2144
+ qps = "1"
2145
+ topic = google_pubsub_topic.example.id
2146
+ }
2147
+
2148
+ max_workers = %{max_workers}
2149
+ num_workers = %{num_workers}
2150
+ machine_type = %{machine_type}
2151
+ network = google_compute_network.test-network.name
2152
+ subnetwork = google_compute_subnetwork.test-subnetwork.self_link
2153
+ }
2154
+ `, context)
2155
+ }
2156
+
2045
2157
{{- end }}
0 commit comments