1515package google
1616
1717import (
18+ "bytes"
1819 "fmt"
1920 "log"
2021 "reflect"
@@ -25,6 +26,30 @@ import (
2526 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
2627)
2728
29+ var accessApprovalCloudProductMapping = map [string ]string {
30+ "appengine.googleapis.com" : "App Engine" ,
31+ "bigquery.googleapis.com" : "BigQuery" ,
32+ "bigtable.googleapis.com" : "Cloud Bigtable" ,
33+ "cloudkms.googleapis.com" : "Cloud Key Management Service" ,
34+ "compute.googleapis.com" : "Compute Engine" ,
35+ "dataflow.googleapis.com" : "Cloud Dataflow" ,
36+ "iam.googleapis.com" : "Cloud Identity and Access Management" ,
37+ "pubsub.googleapis.com" : "Cloud Pub/Sub" ,
38+ "storage.googleapis.com" : "Cloud Storage" ,
39+ }
40+
41+ func accessApprovalEnrolledServicesHash (v interface {}) int {
42+ var buf bytes.Buffer
43+ m := v .(map [string ]interface {})
44+ cp := m ["cloud_product" ].(string )
45+ if n , ok := accessApprovalCloudProductMapping [cp ]; ok {
46+ cp = n
47+ }
48+ buf .WriteString (fmt .Sprintf ("%s-" , strings .ToLower (cp ))) // ToLower just in case
49+ buf .WriteString (fmt .Sprintf ("%s-" , strings .ToLower (m ["enrollment_level" ].(string ))))
50+ return hashcode (buf .String ())
51+ }
52+
2853func resourceAccessApprovalFolderSettings () * schema.Resource {
2954 return & schema.Resource {
3055 Create : resourceAccessApprovalFolderSettingsCreate ,
@@ -52,7 +77,7 @@ to have explicit approval. Enrollment can only be done on an all or nothing basi
5277
5378A maximum of 10 enrolled services will be enforced, to be expanded as the set of supported services is expanded.` ,
5479 Elem : accessapprovalFolderSettingsEnrolledServicesSchema (),
55- // Default schema.HashSchema is used.
80+ Set : accessApprovalEnrolledServicesHash ,
5681 },
5782 "folder_id" : {
5883 Type : schema .TypeString ,
@@ -94,16 +119,29 @@ func accessapprovalFolderSettingsEnrolledServicesSchema() *schema.Resource {
94119 Type : schema .TypeString ,
95120 Required : true ,
96121 Description : `The product for which Access Approval will be enrolled. Allowed values are listed (case-sensitive):
97- all
98- appengine.googleapis.com
99- bigquery.googleapis.com
100- bigtable.googleapis.com
101- cloudkms.googleapis.com
102- compute.googleapis.com
103- dataflow.googleapis.com
104- iam.googleapis.com
105- pubsub.googleapis.com
106- storage.googleapis.com` ,
122+ * all
123+ * App Engine
124+ * BigQuery
125+ * Cloud Bigtable
126+ * Cloud Key Management Service
127+ * Compute Engine
128+ * Cloud Dataflow
129+ * Cloud Identity and Access Management
130+ * Cloud Pub/Sub
131+ * Cloud Storage
132+ * Persistent Disk
133+
134+ Note: These values are supported as input, but considered a legacy format:
135+ * all
136+ * appengine.googleapis.com
137+ * bigquery.googleapis.com
138+ * bigtable.googleapis.com
139+ * cloudkms.googleapis.com
140+ * compute.googleapis.com
141+ * dataflow.googleapis.com
142+ * iam.googleapis.com
143+ * pubsub.googleapis.com
144+ * storage.googleapis.com` ,
107145 },
108146 "enrollment_level" : {
109147 Type : schema .TypeString ,
@@ -363,7 +401,7 @@ func flattenAccessApprovalFolderSettingsEnrolledServices(v interface{}, d *schem
363401 return v
364402 }
365403 l := v .([]interface {})
366- transformed := schema .NewSet (schema . HashResource ( accessapprovalFolderSettingsEnrolledServicesSchema ()) , []interface {}{})
404+ transformed := schema .NewSet (accessApprovalEnrolledServicesHash , []interface {}{})
367405 for _ , raw := range l {
368406 original := raw .(map [string ]interface {})
369407 if len (original ) < 1 {
0 commit comments