@@ -20,7 +20,6 @@ import (
20
20
"testing"
21
21
22
22
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
23
-
24
23
"github.com/hashicorp/terraform-provider-google/google/acctest"
25
24
"github.com/hashicorp/terraform-provider-google/google/envvar"
26
25
)
@@ -29,13 +28,16 @@ func TestAccGKEHub2ScopeRBACRoleBinding_gkehubScopeRbacRoleBindingBasicExample_u
29
28
t .Parallel ()
30
29
31
30
context := map [string ]interface {}{
32
- "project" : envvar .GetTestProjectFromEnv (),
33
- "random_suffix" : acctest .RandString (t , 10 ),
31
+ "project" : envvar .GetTestProjectFromEnv (),
32
+ "random_suffix" : acctest .RandString (t , 10 ),
33
+ "org_id" : envvar .GetTestOrgFromEnv (t ),
34
+ "billing_account" : envvar .GetTestBillingAccountFromEnv (t ),
34
35
}
35
36
36
37
acctest .VcrTest (t , resource.TestCase {
37
38
PreCheck : func () { acctest .AccTestPreCheck (t ) },
38
39
ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
40
+ CheckDestroy : testAccCheckGKEHub2ScopeRBACRoleBindingDestroyProducer (t ),
39
41
Steps : []resource.TestStep {
40
42
{
41
43
Config : testAccGKEHub2ScopeRBACRoleBinding_gkehubScopeRbacRoleBindingBasicExample_basic (context ),
@@ -67,15 +69,14 @@ resource "google_gke_hub_scope" "scoperbacrolebinding" {
67
69
68
70
resource "google_gke_hub_scope_rbac_role_binding" "scoperbacrolebinding" {
69
71
scope_rbac_role_binding_id = "tf-test-scope-rbac-role-binding%{random_suffix}"
70
- scope_id = "tf-test-scope%{random_suffix}"
72
+ scope_id = google_gke_hub_scope.scoperbacrolebinding.scope_id
71
73
72
74
role {
73
75
predefined_role = "ADMIN"
74
76
}
75
77
labels = {
76
78
key = "value"
77
79
}
78
- depends_on = [google_gke_hub_scope.scoperbacrolebinding]
79
80
}
80
81
` , context )
81
82
}
@@ -88,15 +89,141 @@ resource "google_gke_hub_scope" "scoperbacrolebinding" {
88
89
89
90
resource "google_gke_hub_scope_rbac_role_binding" "scoperbacrolebinding" {
90
91
scope_rbac_role_binding_id = "tf-test-scope-rbac-role-binding%{random_suffix}"
91
- scope_id = "tf-test-scope%{random_suffix}"
92
+ scope_id = google_gke_hub_scope.scoperbacrolebinding.scope_id
92
93
93
94
role {
94
95
predefined_role = "VIEW"
95
96
}
96
97
labels = {
97
98
key = "updated_value"
98
99
}
99
- depends_on = [google_gke_hub_scope.scoperbacrolebinding]
100
+ }
101
+ ` , context )
102
+ }
103
+
104
+ func TestAccGKEHub2ScopeRBACRoleBinding_gkehubScopeRbacCustomRoleBindingBasicExample_update (t * testing.T ) {
105
+ // VCR fails to handle batched project services
106
+ acctest .SkipIfVcr (t )
107
+ t .Parallel ()
108
+
109
+ context := map [string ]interface {}{
110
+ "project" : envvar .GetTestProjectFromEnv (),
111
+ "random_suffix" : acctest .RandString (t , 10 ),
112
+ "org_id" : envvar .GetTestOrgFromEnv (t ),
113
+ "billing_account" : envvar .GetTestBillingAccountFromEnv (t ),
114
+ }
115
+
116
+ acctest .VcrTest (t , resource.TestCase {
117
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
118
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
119
+ CheckDestroy : testAccCheckGKEHub2ScopeRBACRoleBindingDestroyProducer (t ),
120
+ Steps : []resource.TestStep {
121
+ {
122
+ Config : testAccGKEHub2ScopeRBACRoleBinding_gkehubScopeRbacCustomRoleBindingBasicExample_basic (context ),
123
+ },
124
+ {
125
+ ResourceName : "google_gke_hub_scope_rbac_role_binding.scope_rbac_custom_role_binding" ,
126
+ ImportState : true ,
127
+ ImportStateVerify : true ,
128
+ ImportStateVerifyIgnore : []string {"labels" , "scope_id" , "scope_rbac_role_binding_id" , "terraform_labels" },
129
+ },
130
+ {
131
+ Config : testAccGKEHub2ScopeRBACRoleBinding_gkehubScopeRbacCustomRoleBindingBasicExample_update (context ),
132
+ },
133
+ {
134
+ ResourceName : "google_gke_hub_scope_rbac_role_binding.scope_rbac_custom_role_binding" ,
135
+ ImportState : true ,
136
+ ImportStateVerify : true ,
137
+ ImportStateVerifyIgnore : []string {"scope_rbac_role_binding_id" , "scope_id" , "labels" , "terraform_labels" },
138
+ },
139
+ },
140
+ })
141
+ }
142
+
143
+ func testAccGKEHub2ScopeRBACRoleBinding_gkehubScopeRbacCustomRoleBindingBasicExample_basic (context map [string ]interface {}) string {
144
+ return gkeHubRRBActuationProjectSetupForGA (context ) + acctest .Nprintf (`
145
+ resource "google_gke_hub_scope" "scope" {
146
+ scope_id = "tf-test-scope%{random_suffix}"
147
+ depends_on = [google_project_service.anthos, google_project_service.gkehub]
148
+ }
149
+
150
+ resource "google_gke_hub_feature" "rbacrolebindingactuation" {
151
+ name = "rbacrolebindingactuation"
152
+ location = "global"
153
+ spec {
154
+ rbacrolebindingactuation {
155
+ allowed_custom_roles = ["my-custom-role", "my-custom-role-2"]
156
+ }
157
+ }
158
+ depends_on = [google_project_service.anthos, google_project_service.gkehub]
159
+ }
160
+
161
+ resource "google_gke_hub_scope_rbac_role_binding" "scope_rbac_custom_role_binding" {
162
+ scope_rbac_role_binding_id = "tf-test-scope-rbac-role-binding%{random_suffix}"
163
+ scope_id = google_gke_hub_scope.scope.scope_id
164
+
165
+ role {
166
+ custom_role = "my-custom-role"
167
+ }
168
+ labels = {
169
+ key = "value"
170
+ }
171
+ depends_on = [google_gke_hub_feature.rbacrolebindingactuation]
172
+ }
173
+ ` , context )
174
+ }
175
+
176
+ func testAccGKEHub2ScopeRBACRoleBinding_gkehubScopeRbacCustomRoleBindingBasicExample_update (context map [string ]interface {}) string {
177
+ return gkeHubRRBActuationProjectSetupForGA (context ) + acctest .Nprintf (`
178
+ resource "google_gke_hub_scope" "scope" {
179
+ scope_id = "tf-test-scope%{random_suffix}"
180
+ }
181
+
182
+ resource "google_gke_hub_feature" "rbacrolebindingactuation" {
183
+ name = "rbacrolebindingactuation"
184
+ location = "global"
185
+ spec {
186
+ rbacrolebindingactuation {
187
+ allowed_custom_roles = ["my-custom-role", "my-custom-role-2"]
188
+ }
189
+ }
190
+ depends_on = [google_project_service.anthos, google_project_service.gkehub]
191
+ }
192
+
193
+ resource "google_gke_hub_scope_rbac_role_binding" "scope_rbac_custom_role_binding" {
194
+ scope_rbac_role_binding_id = "tf-test-scope-rbac-role-binding%{random_suffix}"
195
+ scope_id = google_gke_hub_scope.scope.scope_id
196
+
197
+ role {
198
+ custom_role = "my-custom-role-2"
199
+ }
200
+ labels = {
201
+ key = "value"
202
+ }
203
+ depends_on = [google_gke_hub_feature.rbacrolebindingactuation]
204
+ }
205
+ ` , context )
206
+ }
207
+
208
+ func gkeHubRRBActuationProjectSetupForGA (context map [string ]interface {}) string {
209
+ return acctest .Nprintf (`
210
+ resource "google_project" "project" {
211
+ name = "tf-test-gkehub%{random_suffix}"
212
+ project_id = "tf-test-gkehub%{random_suffix}"
213
+ org_id = "%{org_id}"
214
+ billing_account = "%{billing_account}"
215
+ deletion_policy = "DELETE"
216
+ }
217
+
218
+ resource "google_project_service" "anthos" {
219
+ project = google_project.project.project_id
220
+ service = "anthos.googleapis.com"
221
+ }
222
+
223
+ resource "google_project_service" "gkehub" {
224
+ project = google_project.project.project_id
225
+ service = "gkehub.googleapis.com"
226
+ disable_on_destroy = false
100
227
}
101
228
` , context )
102
229
}
0 commit comments