@@ -368,6 +368,41 @@ func TestAccDataprocCluster_withMetadataAndTags(t *testing.T) {
368368 })
369369}
370370
371+ func TestAccDataprocCluster_withResourceManagerTags (t * testing.T ) {
372+ t .Parallel ()
373+
374+ var cluster dataproc.Cluster
375+ pid := envvar .GetTestProjectFromEnv ()
376+ projectNumber := envvar .GetTestProjectNumberFromEnv ()
377+ rnd := acctest .RandString (t , 10 )
378+ networkName := acctest .BootstrapSharedTestNetwork (t , "dataproc-cluster" )
379+ subnetworkName := acctest .BootstrapSubnet (t , "dataproc-cluster" , networkName )
380+ acctest .BootstrapFirewallForDataprocSharedNetwork (t , "dataproc-cluster" , networkName )
381+ // TODO: remove this IAM binding once tagUser permissions are present in Dataproc Service Agent role.
382+ acctest .BootstrapIamMembers (t , []acctest.IamMember {
383+ {
384+ Member :
fmt .
Sprintf (
"serviceAccount:service-%[email protected] " ,
projectNumber ),
385+ Role : "roles/resourcemanager.tagUser" ,
386+ },
387+ })
388+
389+ acctest .VcrTest (t , resource.TestCase {
390+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
391+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
392+ CheckDestroy : testAccCheckDataprocClusterDestroy (t ),
393+ Steps : []resource.TestStep {
394+ {
395+ Config : testAccDataprocCluster_withResourceManagerTags (pid , rnd , subnetworkName ),
396+ Check : resource .ComposeTestCheckFunc (
397+ testAccCheckDataprocClusterExists (t , "google_dataproc_cluster.basic" , & cluster ),
398+
399+ testAccCheckDataprocClusterResourceManagerTags (t , "google_dataproc_cluster.basic" ),
400+ ),
401+ },
402+ },
403+ })
404+ }
405+
371406func TestAccDataprocCluster_withMinNumInstances (t * testing.T ) {
372407 t .Parallel ()
373408
@@ -1538,6 +1573,40 @@ func testAccCheckDataprocClusterExists(t *testing.T, n string, cluster *dataproc
15381573 }
15391574}
15401575
1576+ func testAccCheckDataprocClusterResourceManagerTags (t * testing.T , n string ) resource.TestCheckFunc {
1577+ return func (s * terraform.State ) error {
1578+ rs , ok := s .RootModule ().Resources [n ]
1579+ if ! ok {
1580+ return fmt .Errorf ("Terraform resource Not found: %s" , n )
1581+ }
1582+
1583+ // Find the tags and validate key/value formats.
1584+ tagPrefix := "cluster_config.0.gce_cluster_config.0.resource_manager_tags."
1585+ keyRegex := regexp .MustCompile (`^tagKeys/` )
1586+ valueRegex := regexp .MustCompile (`^tagValues/` )
1587+
1588+ foundTags := 0
1589+ for attr , value := range rs .Primary .Attributes {
1590+ if strings .HasPrefix (attr , tagPrefix ) && ! strings .HasSuffix (attr , ".#" ) && ! strings .HasSuffix (attr , ".%" ) {
1591+ foundTags ++
1592+ key := strings .TrimPrefix (attr , tagPrefix )
1593+
1594+ if ! keyRegex .MatchString (key ) {
1595+ return fmt .Errorf ("resource manager tag key %q does not have expected prefix 'tagKeys/'" , key )
1596+ }
1597+ if ! valueRegex .MatchString (value ) {
1598+ return fmt .Errorf ("resource manager tag value %q for key %q does not have expected prefix 'tagValues/'" , value , key )
1599+ }
1600+ }
1601+ }
1602+
1603+ if foundTags != 2 {
1604+ return fmt .Errorf ("expected to find 2 resource manager tags, but found %d" , foundTags )
1605+ }
1606+
1607+ return nil
1608+ }
1609+ }
15411610func testAccCheckDataproc_missingZoneGlobalRegion1 (rnd string ) string {
15421611 return fmt .Sprintf (`
15431612resource "google_dataproc_cluster" "basic" {
@@ -1822,6 +1891,45 @@ resource "google_dataproc_cluster" "basic" {
18221891` , rnd , subnetworkName )
18231892}
18241893
1894+ func testAccDataprocCluster_withResourceManagerTags (pid , rnd , subnetworkName string ) string {
1895+ return fmt .Sprintf (`
1896+ resource "google_tags_tag_key" "tag_key" {
1897+ parent = "projects/%s"
1898+ short_name = "key-%s"
1899+ }
1900+
1901+ resource "google_tags_tag_value" "tag_value" {
1902+ parent = "tagKeys/${google_tags_tag_key.tag_key.name}"
1903+ short_name = "val-%s"
1904+ }
1905+
1906+ resource "google_tags_tag_key" "tag_key_2" {
1907+ parent = "projects/%s"
1908+ short_name = "key-2-%s"
1909+ }
1910+
1911+ resource "google_tags_tag_value" "tag_value_2" {
1912+ parent = "tagKeys/${google_tags_tag_key.tag_key_2.name}"
1913+ short_name = "val-2-%s"
1914+ }
1915+
1916+ resource "google_dataproc_cluster" "basic" {
1917+ name = "tf-test-dproc-%s"
1918+ region = "us-central1"
1919+
1920+ cluster_config {
1921+ gce_cluster_config {
1922+ subnetwork = "%s"
1923+ resource_manager_tags = {
1924+ "${google_tags_tag_key.tag_key.id}" = "${google_tags_tag_value.tag_value.id}",
1925+ "${google_tags_tag_key.tag_key_2.id}" = "${google_tags_tag_value.tag_value_2.id}"
1926+ }
1927+ }
1928+ }
1929+ }
1930+ ` , pid , rnd , rnd , pid , rnd , rnd , rnd , subnetworkName )
1931+ }
1932+
18251933func testAccDataprocCluster_withMinNumInstances (rnd , subnetworkName string ) string {
18261934 return fmt .Sprintf (`
18271935resource "google_dataproc_cluster" "with_min_num_instances" {
0 commit comments