@@ -20,7 +20,6 @@ import (
2020 "testing"
2121
2222 "github.com/hashicorp/terraform-plugin-testing/helper/resource"
23-
2423 "github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
2524 "github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar"
2625)
@@ -29,13 +28,16 @@ func TestAccGKEHub2ScopeRBACRoleBinding_gkehubScopeRbacRoleBindingBasicExample_u
2928 t .Parallel ()
3029
3130 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 ),
3435 }
3536
3637 acctest .VcrTest (t , resource.TestCase {
3738 PreCheck : func () { acctest .AccTestPreCheck (t ) },
3839 ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
40+ CheckDestroy : testAccCheckGKEHub2ScopeRBACRoleBindingDestroyProducer (t ),
3941 Steps : []resource.TestStep {
4042 {
4143 Config : testAccGKEHub2ScopeRBACRoleBinding_gkehubScopeRbacRoleBindingBasicExample_basic (context ),
@@ -67,15 +69,14 @@ resource "google_gke_hub_scope" "scoperbacrolebinding" {
6769
6870resource "google_gke_hub_scope_rbac_role_binding" "scoperbacrolebinding" {
6971 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
71737274 role {
7375 predefined_role = "ADMIN"
7476 }
7577 labels = {
7678 key = "value"
7779 }
78- depends_on = [google_gke_hub_scope.scoperbacrolebinding]
7980}
8081` , context )
8182}
@@ -88,15 +89,141 @@ resource "google_gke_hub_scope" "scoperbacrolebinding" {
8889
8990resource "google_gke_hub_scope_rbac_role_binding" "scoperbacrolebinding" {
9091 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
92939394 role {
9495 predefined_role = "VIEW"
9596 }
9697 labels = {
9798 key = "updated_value"
9899 }
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
100227}
101228` , context )
102229}
0 commit comments