@@ -56,6 +56,20 @@ func TestAccBigtableTableIamBinding(t *testing.T) {
5656 ImportState : true ,
5757 ImportStateVerify : true ,
5858 },
59+ {
60+ // // Test IAM Binding - Update instance to instance_name
61+ Config : testAccBigtableTableIamBinding_basicUpdateName (instance , cluster , account , role ),
62+ Check : resource .ComposeTestCheckFunc (
63+ resource .TestCheckResourceAttr (
64+ "google_bigtable_table_iam_binding.binding" , "role" , role ),
65+ ),
66+ },
67+ {
68+ ResourceName : "google_bigtable_table_iam_binding.binding" ,
69+ ImportStateId : importId ,
70+ ImportState : true ,
71+ ImportStateVerify : true ,
72+ },
5973 {
6074 // Test IAM Binding update
6175 Config : testAccBigtableTableIamBinding_update (instance , cluster , account , role ),
@@ -107,6 +121,38 @@ func TestAccBigtableTableIamMember(t *testing.T) {
107121 ImportState : true ,
108122 ImportStateVerify : true ,
109123 },
124+ {
125+ // Test IAM Binding - Update instance to instance_name
126+ Config : testAccBigtableTableIamMember_updateName (instance , cluster , account , role ),
127+ Check : resource .ComposeTestCheckFunc (
128+ resource .TestCheckResourceAttr (
129+ "google_bigtable_table_iam_member.member" , "role" , role ),
130+ resource .TestCheckResourceAttr (
131+ "google_bigtable_table_iam_member.member" , "member" , "serviceAccount:" + envvar .ServiceAccountCanonicalEmail (account )),
132+ ),
133+ },
134+ {
135+ ResourceName : "google_bigtable_table_iam_member.member" ,
136+ ImportStateId : importId ,
137+ ImportState : true ,
138+ ImportStateVerify : true ,
139+ },
140+ {
141+ // Test IAM Binding - Update instance_name to instance
142+ Config : testAccBigtableTableIamMember (instance , cluster , account , role ),
143+ Check : resource .ComposeTestCheckFunc (
144+ resource .TestCheckResourceAttr (
145+ "google_bigtable_table_iam_member.member" , "role" , role ),
146+ resource .TestCheckResourceAttr (
147+ "google_bigtable_table_iam_member.member" , "member" , "serviceAccount:" + envvar .ServiceAccountCanonicalEmail (account )),
148+ ),
149+ },
150+ {
151+ ResourceName : "google_bigtable_table_iam_member.member" ,
152+ ImportStateId : importId ,
153+ ImportState : true ,
154+ ImportStateVerify : true ,
155+ },
110156 },
111157 })
112158}
@@ -139,6 +185,28 @@ func TestAccBigtableTableIamPolicy(t *testing.T) {
139185 ImportState : true ,
140186 ImportStateVerify : true ,
141187 },
188+ {
189+ // Test IAM Binding - Update instance to instance_name
190+ Config : testAccBigtableTableIamPolicy_updateName (instance , cluster , account , role ),
191+ Check : resource .TestCheckResourceAttrSet ("data.google_bigtable_table_iam_policy.policy" , "policy_data" ),
192+ },
193+ {
194+ ResourceName : "google_bigtable_table_iam_policy.policy" ,
195+ ImportStateId : importId ,
196+ ImportState : true ,
197+ ImportStateVerify : true ,
198+ },
199+ {
200+ // Test IAM Binding - Update instance_name to instance
201+ Config : testAccBigtableTableIamPolicy (instance , cluster , account , role ),
202+ Check : resource .TestCheckResourceAttrSet ("data.google_bigtable_table_iam_policy.policy" , "policy_data" ),
203+ },
204+ {
205+ ResourceName : "google_bigtable_table_iam_policy.policy" ,
206+ ImportStateId : importId ,
207+ ImportState : true ,
208+ ImportStateVerify : true ,
209+ },
142210 },
143211 })
144212}
@@ -166,6 +234,29 @@ resource "google_bigtable_table_iam_binding" "binding" {
166234` , instance , cluster , cluster , account , account , role )
167235}
168236
237+ func testAccBigtableTableIamBinding_basicUpdateName (instance , cluster , account , role string ) string {
238+ return fmt .Sprintf (testBigtableTableIam + `
239+ resource "google_service_account" "test-account1" {
240+ account_id = "%s-1"
241+ display_name = "Bigtable Table IAM Testing Account"
242+ }
243+
244+ resource "google_service_account" "test-account2" {
245+ account_id = "%s-2"
246+ display_name = "Bigtable Table Iam Testing Account"
247+ }
248+
249+ resource "google_bigtable_table_iam_binding" "binding" {
250+ instance_name = google_bigtable_instance.instance.name
251+ table = google_bigtable_table.table.name
252+ role = "%s"
253+ members = [
254+ "serviceAccount:${google_service_account.test-account1.email}",
255+ ]
256+ }
257+ ` , instance , cluster , cluster , account , account , role )
258+ }
259+
169260func testAccBigtableTableIamBinding_update (instance , cluster , account , role string ) string {
170261 return fmt .Sprintf (testBigtableTableIam + `
171262resource "google_service_account" "test-account1" {
@@ -206,6 +297,22 @@ resource "google_bigtable_table_iam_member" "member" {
206297` , instance , cluster , cluster , account , role )
207298}
208299
300+ func testAccBigtableTableIamMember_updateName (instance , cluster , account , role string ) string {
301+ return fmt .Sprintf (testBigtableTableIam + `
302+ resource "google_service_account" "test-account" {
303+ account_id = "%s"
304+ display_name = "Bigtable Table IAM Testing Account"
305+ }
306+
307+ resource "google_bigtable_table_iam_member" "member" {
308+ instance_name = google_bigtable_instance.instance.name
309+ table = google_bigtable_table.table.name
310+ role = "%s"
311+ member = "serviceAccount:${google_service_account.test-account.email}"
312+ }
313+ ` , instance , cluster , cluster , account , role )
314+ }
315+
209316func testAccBigtableTableIamPolicy (instance , cluster , account , role string ) string {
210317 return fmt .Sprintf (testBigtableTableIam + `
211318resource "google_service_account" "test-account" {
@@ -226,6 +333,34 @@ resource "google_bigtable_table_iam_policy" "policy" {
226333 policy_data = data.google_iam_policy.policy.policy_data
227334}
228335
336+ data "google_bigtable_table_iam_policy" "policy" {
337+ instance_name = google_bigtable_instance.instance.name
338+ table = google_bigtable_table.table.name
339+ }
340+
341+ ` , instance , cluster , cluster , account , role )
342+ }
343+
344+ func testAccBigtableTableIamPolicy_updateName (instance , cluster , account , role string ) string {
345+ return fmt .Sprintf (testBigtableTableIam + `
346+ resource "google_service_account" "test-account" {
347+ account_id = "%s"
348+ display_name = "Bigtable Table IAM Testing Account"
349+ }
350+
351+ data "google_iam_policy" "policy" {
352+ binding {
353+ role = "%s"
354+ members = ["serviceAccount:${google_service_account.test-account.email}"]
355+ }
356+ }
357+
358+ resource "google_bigtable_table_iam_policy" "policy" {
359+ instance_name = google_bigtable_instance.instance.name
360+ table = google_bigtable_table.table.name
361+ policy_data = data.google_iam_policy.policy.policy_data
362+ }
363+
229364data "google_bigtable_table_iam_policy" "policy" {
230365 instance = google_bigtable_instance.instance.name
231366 table = google_bigtable_table.table.name
0 commit comments