Skip to content

Commit 7f3d13d

Browse files
stevenyang72BBBmau
authored andcommitted
Add mode, inline cert iss & trust config to workload identity pool (GoogleCloudPlatform#13814)
1 parent 5fcbe15 commit 7f3d13d

File tree

1 file changed

+239
-0
lines changed

1 file changed

+239
-0
lines changed
Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
package iambeta_test
2+
3+
import (
4+
"fmt"
5+
{{if ne $.TargetVersionName "ga" -}}
6+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
7+
{{- end }}
8+
"github.com/hashicorp/terraform-provider-google/google/acctest"
9+
"testing"
10+
11+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
12+
)
13+
14+
func TestAccIAMBetaWorkloadIdentityPool_full(t *testing.T) {
15+
t.Parallel()
16+
17+
randomSuffix := acctest.RandString(t, 10)
18+
19+
acctest.VcrTest(t, resource.TestCase{
20+
PreCheck: func() { acctest.AccTestPreCheck(t) },
21+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
22+
CheckDestroy: testAccCheckIAMBetaWorkloadIdentityPoolDestroyProducer(t),
23+
Steps: []resource.TestStep{
24+
{
25+
Config: testAccIAMBetaWorkloadIdentityPool_full(randomSuffix),
26+
},
27+
{
28+
ResourceName: "google_iam_workload_identity_pool.my_pool",
29+
ImportState: true,
30+
ImportStateVerify: true,
31+
},
32+
{
33+
Config: testAccIAMBetaWorkloadIdentityPool_update(randomSuffix),
34+
},
35+
{
36+
ResourceName: "google_iam_workload_identity_pool.my_pool",
37+
ImportState: true,
38+
ImportStateVerify: true,
39+
},
40+
},
41+
})
42+
}
43+
44+
func TestAccIAMBetaWorkloadIdentityPool_minimal(t *testing.T) {
45+
t.Parallel()
46+
47+
randomSuffix := acctest.RandString(t, 10)
48+
49+
acctest.VcrTest(t, resource.TestCase{
50+
PreCheck: func() { acctest.AccTestPreCheck(t) },
51+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
52+
CheckDestroy: testAccCheckIAMBetaWorkloadIdentityPoolDestroyProducer(t),
53+
Steps: []resource.TestStep{
54+
{
55+
Config: testAccIAMBetaWorkloadIdentityPool_minimal(randomSuffix),
56+
},
57+
{
58+
ResourceName: "google_iam_workload_identity_pool.my_pool",
59+
ImportState: true,
60+
ImportStateVerify: true,
61+
},
62+
{
63+
Config: testAccIAMBetaWorkloadIdentityPool_update(randomSuffix),
64+
},
65+
{
66+
ResourceName: "google_iam_workload_identity_pool.my_pool",
67+
ImportState: true,
68+
ImportStateVerify: true,
69+
},
70+
},
71+
})
72+
}
73+
74+
{{if ne $.TargetVersionName "ga" -}}
75+
func TestAccIAMBetaWorkloadIdentityPool_beta_update(t *testing.T) {
76+
t.Parallel()
77+
78+
randomSuffix := acctest.RandString(t, 10)
79+
80+
acctest.VcrTest(t, resource.TestCase{
81+
PreCheck: func() { acctest.AccTestPreCheck(t) },
82+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
83+
CheckDestroy: testAccCheckIAMBetaWorkloadIdentityPoolDestroyProducer(t),
84+
Steps: []resource.TestStep{
85+
{
86+
Config: testAccIAMBetaWorkloadIdentityPool_beta_full(randomSuffix),
87+
},
88+
{
89+
ResourceName: "google_iam_workload_identity_pool.my_pool",
90+
ImportState: true,
91+
ImportStateVerify: true,
92+
},
93+
{
94+
Config: testAccIAMBetaWorkloadIdentityPool_beta_update(randomSuffix),
95+
ConfigPlanChecks: resource.ConfigPlanChecks{
96+
PreApply: []plancheck.PlanCheck{
97+
plancheck.ExpectResourceAction("google_iam_workload_identity_pool.my_pool", plancheck.ResourceActionUpdate),
98+
},
99+
},
100+
},
101+
{
102+
ResourceName: "google_iam_workload_identity_pool.my_pool",
103+
ImportState: true,
104+
ImportStateVerify: true,
105+
},
106+
{
107+
Config: testAccIAMBetaWorkloadIdentityPool_beta_minimum(randomSuffix),
108+
ConfigPlanChecks: resource.ConfigPlanChecks{
109+
PreApply: []plancheck.PlanCheck{
110+
plancheck.ExpectResourceAction("google_iam_workload_identity_pool.my_pool", plancheck.ResourceActionUpdate),
111+
},
112+
},
113+
},
114+
{
115+
ResourceName: "google_iam_workload_identity_pool.my_pool",
116+
ImportState: true,
117+
ImportStateVerify: true,
118+
},
119+
},
120+
})
121+
}
122+
{{- end }}
123+
124+
func testAccIAMBetaWorkloadIdentityPool_full(suffix string) string {
125+
return fmt.Sprintf(`
126+
resource "google_iam_workload_identity_pool" "my_pool" {
127+
workload_identity_pool_id = "my-pool-%s"
128+
display_name = "Name of pool"
129+
description = "Identity pool for automated test"
130+
disabled = true
131+
}
132+
`, suffix)
133+
}
134+
135+
func testAccIAMBetaWorkloadIdentityPool_minimal(suffix string) string {
136+
return fmt.Sprintf(`
137+
resource "google_iam_workload_identity_pool" "my_pool" {
138+
workload_identity_pool_id = "my-pool-%s"
139+
}
140+
`, suffix)
141+
}
142+
143+
func testAccIAMBetaWorkloadIdentityPool_update(suffix string) string {
144+
return fmt.Sprintf(`
145+
resource "google_iam_workload_identity_pool" "my_pool" {
146+
workload_identity_pool_id = "my-pool-%s"
147+
display_name = "Updated name of pool"
148+
description = "Updated description"
149+
disabled = false
150+
}
151+
`, suffix)
152+
}
153+
154+
{{if ne $.TargetVersionName "ga" -}}
155+
func testAccIAMBetaWorkloadIdentityPool_beta_full(suffix string) string {
156+
return fmt.Sprintf(`
157+
resource "google_iam_workload_identity_pool" "my_pool" {
158+
provider = google-beta
159+
160+
workload_identity_pool_id = "my-pool-%s"
161+
display_name = "Name of the pool"
162+
description = "Identity pool operates in TRUST_DOMAIN mode"
163+
disabled = true
164+
mode = "TRUST_DOMAIN"
165+
inline_certificate_issuance_config {
166+
ca_pools = {
167+
"us-central1" : "projects/project-bar/locations/us-central1/caPools/ca-pool-bar"
168+
"asia-east2" : "projects/project-foo/locations/asia-east2/caPools/ca-pool-foo"
169+
}
170+
lifetime = "86400s"
171+
rotation_window_percentage = 50
172+
key_algorithm = "ECDSA_P256"
173+
}
174+
inline_trust_config {
175+
additional_trust_bundles {
176+
trust_domain = "ca-pool-foo.global.project-foo.workload.id.goog"
177+
trust_anchors {
178+
pem_certificate = file("test-fixtures/trust_anchor_1.pem")
179+
}
180+
trust_anchors {
181+
pem_certificate = file("test-fixtures/trust_anchor_2.pem")
182+
}
183+
}
184+
additional_trust_bundles {
185+
trust_domain = "ca-pool-bar.global.project-bar.workload.id.goog"
186+
trust_anchors {
187+
pem_certificate = file("test-fixtures/trust_anchor_3.pem")
188+
}
189+
trust_anchors {
190+
pem_certificate = file("test-fixtures/trust_anchor_4.pem")
191+
}
192+
}
193+
}
194+
}
195+
`, suffix)
196+
}
197+
198+
func testAccIAMBetaWorkloadIdentityPool_beta_update(suffix string) string {
199+
return fmt.Sprintf(`
200+
resource "google_iam_workload_identity_pool" "my_pool" {
201+
provider = google-beta
202+
203+
workload_identity_pool_id = "my-pool-%s"
204+
display_name = "Updated name of the pool"
205+
description = "Updated identity pool operates in TRUST_DOMAIN mode"
206+
disabled = false
207+
mode = "TRUST_DOMAIN"
208+
inline_certificate_issuance_config {
209+
ca_pools = {
210+
"us-central2" : "projects/project-bar/locations/us-central2/caPools/ca-pool-bar"
211+
"asia-east1" : "projects/project-foo/locations/asia-east1/caPools/ca-pool-foo"
212+
}
213+
lifetime = "36000s"
214+
rotation_window_percentage = 75
215+
key_algorithm = "RSA_4096"
216+
}
217+
inline_trust_config {
218+
additional_trust_bundles {
219+
trust_domain = "ca-pool-baz.global.project-baz.workload.id.goog"
220+
trust_anchors {
221+
pem_certificate = file("test-fixtures/trust_anchor_updated.pem")
222+
}
223+
}
224+
}
225+
}
226+
`, suffix)
227+
}
228+
229+
func testAccIAMBetaWorkloadIdentityPool_beta_minimum(suffix string) string {
230+
return fmt.Sprintf(`
231+
resource "google_iam_workload_identity_pool" "my_pool" {
232+
provider = google-beta
233+
234+
workload_identity_pool_id = "my-pool-%s"
235+
mode = "TRUST_DOMAIN"
236+
}
237+
`, suffix)
238+
}
239+
{{- end }}

0 commit comments

Comments
 (0)