Skip to content

Commit 4571896

Browse files
upgrade dcl to 1.81.0 (#14852) (#24001)
[upstream:51317520a2da56fd3aa2273e38be3d4b27b65a51] Signed-off-by: Modular Magician <[email protected]>
1 parent dbeef19 commit 4571896

File tree

6 files changed

+119
-22
lines changed

6 files changed

+119
-22
lines changed

.changelog/14852.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
apikeys: added `service_account_email` to `google_apikeys_key`
3+
```

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
cloud.google.com/go/auth v0.16.3
77
cloud.google.com/go/auth/oauth2adapt v0.2.8
88
cloud.google.com/go/bigtable v1.37.0
9-
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.80.0
9+
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.81.0
1010
github.com/apparentlymart/go-cidr v1.1.0
1111
github.com/davecgh/go-spew v1.1.1
1212
github.com/dnaeon/go-vcr v1.0.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
2424
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
2525
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.80.0 h1:ZpQrm5i+ppVxTQjp6lU2APyAejavB/d7G2gZNu2RxsU=
2626
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.80.0/go.mod h1:pL2Qt5HT+x6xrTd806oMiM3awW6kNIXB/iiuClz6m6k=
27+
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.81.0 h1:zTRBYNu7nk3TMbiRfkBcRNzw4cOeym0z1GduDYNyRyE=
28+
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.81.0/go.mod h1:pL2Qt5HT+x6xrTd806oMiM3awW6kNIXB/iiuClz6m6k=
2729
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
2830
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
2931
github.com/ProtonMail/go-crypto v1.1.6 h1:ZcV+Ropw6Qn0AX9brlQLAUXfqLBc7Bl+f/DmNxpLfdw=

google/services/apikeys/resource_apikeys_key.go

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ func ResourceApikeysKey() *schema.Resource {
8686
Elem: ApikeysKeyRestrictionsSchema(),
8787
},
8888

89+
"service_account_email": {
90+
Type: schema.TypeString,
91+
Optional: true,
92+
ForceNew: true,
93+
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
94+
Description: "The email of the service account the key is bound to. If this field is specified, the key is a service account bound key and auth enabled. See [Documentation](https://cloud.devsite.corp.google.com/docs/authentication/api-keys?#api-keys-bound-sa) for more details.",
95+
},
96+
8997
"key_string": {
9098
Type: schema.TypeString,
9199
Computed: true,
@@ -244,10 +252,11 @@ func resourceApikeysKeyCreate(d *schema.ResourceData, meta interface{}) error {
244252
}
245253

246254
obj := &apikeys.Key{
247-
Name: dcl.String(d.Get("name").(string)),
248-
DisplayName: dcl.String(d.Get("display_name").(string)),
249-
Project: dcl.String(project),
250-
Restrictions: expandApikeysKeyRestrictions(d.Get("restrictions")),
255+
Name: dcl.String(d.Get("name").(string)),
256+
DisplayName: dcl.String(d.Get("display_name").(string)),
257+
Project: dcl.String(project),
258+
Restrictions: expandApikeysKeyRestrictions(d.Get("restrictions")),
259+
ServiceAccountEmail: dcl.String(d.Get("service_account_email").(string)),
251260
}
252261

253262
id, err := obj.ID()
@@ -295,10 +304,11 @@ func resourceApikeysKeyRead(d *schema.ResourceData, meta interface{}) error {
295304
}
296305

297306
obj := &apikeys.Key{
298-
Name: dcl.String(d.Get("name").(string)),
299-
DisplayName: dcl.String(d.Get("display_name").(string)),
300-
Project: dcl.String(project),
301-
Restrictions: expandApikeysKeyRestrictions(d.Get("restrictions")),
307+
Name: dcl.String(d.Get("name").(string)),
308+
DisplayName: dcl.String(d.Get("display_name").(string)),
309+
Project: dcl.String(project),
310+
Restrictions: expandApikeysKeyRestrictions(d.Get("restrictions")),
311+
ServiceAccountEmail: dcl.String(d.Get("service_account_email").(string)),
302312
}
303313

304314
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
@@ -335,6 +345,9 @@ func resourceApikeysKeyRead(d *schema.ResourceData, meta interface{}) error {
335345
if err = d.Set("restrictions", flattenApikeysKeyRestrictions(res.Restrictions)); err != nil {
336346
return fmt.Errorf("error setting restrictions in state: %s", err)
337347
}
348+
if err = d.Set("service_account_email", res.ServiceAccountEmail); err != nil {
349+
return fmt.Errorf("error setting service_account_email in state: %s", err)
350+
}
338351
if err = d.Set("key_string", res.KeyString); err != nil {
339352
return fmt.Errorf("error setting key_string in state: %s", err)
340353
}
@@ -352,10 +365,11 @@ func resourceApikeysKeyUpdate(d *schema.ResourceData, meta interface{}) error {
352365
}
353366

354367
obj := &apikeys.Key{
355-
Name: dcl.String(d.Get("name").(string)),
356-
DisplayName: dcl.String(d.Get("display_name").(string)),
357-
Project: dcl.String(project),
358-
Restrictions: expandApikeysKeyRestrictions(d.Get("restrictions")),
368+
Name: dcl.String(d.Get("name").(string)),
369+
DisplayName: dcl.String(d.Get("display_name").(string)),
370+
Project: dcl.String(project),
371+
Restrictions: expandApikeysKeyRestrictions(d.Get("restrictions")),
372+
ServiceAccountEmail: dcl.String(d.Get("service_account_email").(string)),
359373
}
360374
directive := tpgdclresource.UpdateDirective
361375
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
@@ -398,10 +412,11 @@ func resourceApikeysKeyDelete(d *schema.ResourceData, meta interface{}) error {
398412
}
399413

400414
obj := &apikeys.Key{
401-
Name: dcl.String(d.Get("name").(string)),
402-
DisplayName: dcl.String(d.Get("display_name").(string)),
403-
Project: dcl.String(project),
404-
Restrictions: expandApikeysKeyRestrictions(d.Get("restrictions")),
415+
Name: dcl.String(d.Get("name").(string)),
416+
DisplayName: dcl.String(d.Get("display_name").(string)),
417+
Project: dcl.String(project),
418+
Restrictions: expandApikeysKeyRestrictions(d.Get("restrictions")),
419+
ServiceAccountEmail: dcl.String(d.Get("service_account_email").(string)),
405420
}
406421

407422
log.Printf("[DEBUG] Deleting Key %q", d.Id())

google/services/apikeys/resource_apikeys_key_generated_test.go

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,32 @@ func TestAccApikeysKey_ServerKey(t *testing.T) {
190190
},
191191
})
192192
}
193+
func TestAccApikeysKey_ServiceAccountKeyHandWritten(t *testing.T) {
194+
t.Parallel()
195+
196+
context := map[string]interface{}{
197+
"billing_acct": envvar.GetTestBillingAccountFromEnv(t),
198+
"org_id": envvar.GetTestOrgFromEnv(t),
199+
"project_name": envvar.GetTestProjectFromEnv(),
200+
"random_suffix": acctest.RandString(t, 10),
201+
}
202+
203+
acctest.VcrTest(t, resource.TestCase{
204+
PreCheck: func() { acctest.AccTestPreCheck(t) },
205+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
206+
CheckDestroy: testAccCheckApikeysKeyDestroyProducer(t),
207+
Steps: []resource.TestStep{
208+
{
209+
Config: testAccApikeysKey_ServiceAccountKeyHandWritten(context),
210+
},
211+
{
212+
ResourceName: "google_apikeys_key.primary",
213+
ImportState: true,
214+
ImportStateVerify: true,
215+
},
216+
},
217+
})
218+
}
193219

194220
func testAccApikeysKey_AndroidKey(context map[string]interface{}) string {
195221
return acctest.Nprintf(`
@@ -384,6 +410,30 @@ resource "google_apikeys_key" "primary" {
384410
`, context)
385411
}
386412

413+
func testAccApikeysKey_ServiceAccountKeyHandWritten(context map[string]interface{}) string {
414+
return acctest.Nprintf(`
415+
resource "google_apikeys_key" "primary" {
416+
name = "tf-test-key%{random_suffix}"
417+
display_name = "sample-key"
418+
project = google_project.project.project_id
419+
service_account_email = google_service_account.key_service_account.email
420+
}
421+
422+
resource "google_project" "project" {
423+
project_id = "tf-test-app%{random_suffix}"
424+
name = "tf-test-app%{random_suffix}"
425+
org_id = "%{org_id}"
426+
deletion_policy = "DELETE"
427+
}
428+
429+
resource "google_service_account" "key_service_account" {
430+
account_id = "tf-test-app%{random_suffix}"
431+
project = google_project.project.project_id
432+
display_name = "Test Service Account"
433+
}
434+
`, context)
435+
}
436+
387437
func testAccCheckApikeysKeyDestroyProducer(t *testing.T) func(s *terraform.State) error {
388438
return func(s *terraform.State) error {
389439
for name, rs := range s.RootModule().Resources {
@@ -402,11 +452,12 @@ func testAccCheckApikeysKeyDestroyProducer(t *testing.T) func(s *terraform.State
402452
}
403453

404454
obj := &apikeys.Key{
405-
Name: dcl.String(rs.Primary.Attributes["name"]),
406-
DisplayName: dcl.String(rs.Primary.Attributes["display_name"]),
407-
Project: dcl.StringOrNil(rs.Primary.Attributes["project"]),
408-
KeyString: dcl.StringOrNil(rs.Primary.Attributes["key_string"]),
409-
Uid: dcl.StringOrNil(rs.Primary.Attributes["uid"]),
455+
Name: dcl.String(rs.Primary.Attributes["name"]),
456+
DisplayName: dcl.String(rs.Primary.Attributes["display_name"]),
457+
Project: dcl.StringOrNil(rs.Primary.Attributes["project"]),
458+
ServiceAccountEmail: dcl.String(rs.Primary.Attributes["service_account_email"]),
459+
KeyString: dcl.StringOrNil(rs.Primary.Attributes["key_string"]),
460+
Uid: dcl.StringOrNil(rs.Primary.Attributes["uid"]),
410461
}
411462

412463
client := transport_tpg.NewDCLApikeysClient(config, config.UserAgent, billingProject, 0)

website/docs/r/apikeys_key.html.markdown

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,28 @@ resource "google_apikeys_key" "primary" {
118118
}
119119
120120
121+
```
122+
## Example Usage - service_account_key
123+
```hcl
124+
resource "google_apikeys_key" "primary" {
125+
name = "key"
126+
display_name = "sample-key"
127+
project = google_project.project.project_id
128+
service_account_email = google_service_account.key_service_account.email
129+
}
130+
131+
resource "google_project" "project" {
132+
project_id = "app"
133+
name = "app"
134+
org_id = "123456789"
135+
deletion_policy = "DELETE"
136+
}
137+
138+
resource "google_service_account" "key_service_account" {
139+
account_id = "app"
140+
project = google_project.project.project_id
141+
display_name = "Test Service Account"
142+
}
121143
```
122144

123145
## Argument Reference
@@ -144,6 +166,10 @@ The following arguments are supported:
144166
(Optional)
145167
Key restrictions.
146168

169+
* `service_account_email` -
170+
(Optional)
171+
The email of the service account the key is bound to. If this field is specified, the key is a service account bound key and auth enabled. See [Documentation](https://cloud.devsite.corp.google.com/docs/authentication/api-keys?#api-keys-bound-sa) for more details.
172+
147173

148174

149175
The `restrictions` block supports:

0 commit comments

Comments
 (0)