Skip to content

Commit 8070c45

Browse files
publicca: fixup mac_key (#16361) (#26099)
[upstream:c2acc215da681dce7c0fb5046336af3e96f35dde] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent b57aaf4 commit 8070c45

File tree

6 files changed

+102
-99
lines changed

6 files changed

+102
-99
lines changed

.changelog/16361.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
publicca: fixed `mac_key` not set in `google_public_ca_external_account_key`
3+
```

google/services/publicca/resource_public_ca_external_account_key.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,11 @@ func resourcePublicCAExternalAccountKeyCreate(d *schema.ResourceData, meta inter
206206
if err != nil {
207207
return fmt.Errorf("Error creating ExternalAccountKey: %s", err)
208208
}
209-
if err := d.Set("name", flattenPublicCAExternalAccountKeyName(res["name"], d, config)); err != nil {
210-
return fmt.Errorf(`Error setting computed identity field "name": %s`, err)
211-
}
212-
if err := d.Set("key_id", flattenPublicCAExternalAccountKeyKeyId(res["keyId"], d, config)); err != nil {
213-
return fmt.Errorf(`Error setting computed identity field "key_id": %s`, err)
214-
}
215-
if err := d.Set("b64_mac_key", flattenPublicCAExternalAccountKeyB64MacKey(res["b64MacKey"], d, config)); err != nil {
216-
return fmt.Errorf(`Error setting computed identity field "b64_mac_key": %s`, err)
217-
}
218-
if err := d.Set("b64url_mac_key", flattenPublicCAExternalAccountKeyB64urlMacKey(res["b64MacKey"], d, config)); err != nil {
219-
return fmt.Errorf(`Error setting computed identity field "b64url_mac_key": %s`, err)
209+
// Set computed resource properties from create API response so that they're available on the subsequent Read
210+
// call.
211+
err = resourcePublicCAExternalAccountKeyPostCreateSetComputedFields(d, meta, res)
212+
if err != nil {
213+
return fmt.Errorf("setting computed ID format fields: %w", err)
220214
}
221215

222216
// Store the ID now
@@ -226,6 +220,18 @@ func resourcePublicCAExternalAccountKeyCreate(d *schema.ResourceData, meta inter
226220
}
227221
d.SetId(id)
228222

223+
if err := d.Set("b64_mac_key", flattenPublicCAExternalAccountKeyB64MacKey(res["b64MacKey"], d, config)); err != nil {
224+
return fmt.Errorf("Error reading ExternalAccountKey: %s", err)
225+
}
226+
227+
if err := d.Set("b64url_mac_key", flattenPublicCAExternalAccountKeyB64urlMacKey(res["b64MacKey"], d, config)); err != nil {
228+
return fmt.Errorf("Error reading ExternalAccountKey: %s", err)
229+
}
230+
231+
if err := d.Set("mac_key", flattenPublicCAExternalAccountKeyMacKey(res["b64MacKey"], d, config)); err != nil {
232+
return fmt.Errorf("Error reading ExternalAccountKey: %s", err)
233+
}
234+
229235
log.Printf("[DEBUG] Finished creating ExternalAccountKey %q: %#v", d.Id(), res)
230236

231237
return resourcePublicCAExternalAccountKeyRead(d, meta)

google/services/publicca/resource_public_ca_external_account_key_generated_meta.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ api_version: v1
66
api_resource_type_kind: ExternalAccountKey
77
fields:
88
- api_field: b64MacKey
9-
- api_field: b64urlMacKey
9+
- api_field: b64MacKey
10+
field: b64url_mac_key
1011
- api_field: keyId
1112
- field: location
1213
provider_only: true
13-
- api_field: MacKey
14+
- api_field: b64MacKey
15+
field: mac_key
1416
- api_field: name

google/services/publicca/resource_public_ca_external_account_key_generated_test.go

Lines changed: 0 additions & 78 deletions
This file was deleted.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
// ----------------------------------------------------------------------------
4+
//
5+
// *** AUTO GENERATED CODE *** Type: Handwritten ***
6+
//
7+
// ----------------------------------------------------------------------------
8+
//
9+
// This code is generated by Magic Modules using the following:
10+
//
11+
// Source file: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services/publicca/resource_public_ca_external_account_key_test.go
12+
//
13+
// DO NOT EDIT this file directly. Any changes made to this file will be
14+
// overwritten during the next generation cycle.
15+
//
16+
// ----------------------------------------------------------------------------
17+
package publicca_test
18+
19+
import (
20+
"encoding/base64"
21+
"testing"
22+
23+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
24+
25+
"github.com/hashicorp/terraform-provider-google/google/acctest"
26+
"github.com/hashicorp/terraform-provider-google/google/envvar"
27+
)
28+
29+
func TestAccPublicCAExternalAccountKey_publicCaExternalAccountKey(t *testing.T) {
30+
t.Parallel()
31+
32+
context := map[string]interface{}{
33+
"project": envvar.GetTestProjectFromEnv(),
34+
}
35+
36+
acctest.VcrTest(t, resource.TestCase{
37+
PreCheck: func() { acctest.AccTestPreCheck(t) },
38+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
39+
Steps: []resource.TestStep{
40+
{
41+
Config: testAccPublicCAExternalAccountKey_publicCaExternalAccountKey(context),
42+
Check: resource.ComposeAggregateTestCheckFunc(
43+
resource.TestCheckResourceAttrSet("google_public_ca_external_account_key.prod", "b64_mac_key"),
44+
resource.TestCheckResourceAttrSet("google_public_ca_external_account_key.prod", "b64url_mac_key"),
45+
resource.TestCheckResourceAttrSet("google_public_ca_external_account_key.prod", "mac_key"),
46+
resource.TestCheckResourceAttrWith("google_public_ca_external_account_key.prod", "b64_mac_key", func(value string) error {
47+
b64key, err := base64.URLEncoding.DecodeString(value)
48+
if err != nil {
49+
return err
50+
}
51+
return tryBase64DecodeKey(string(b64key))
52+
}),
53+
resource.TestCheckResourceAttrWith("google_public_ca_external_account_key.prod", "b64url_mac_key", func(value string) error {
54+
b64key, err := base64.RawURLEncoding.DecodeString(value)
55+
if err != nil {
56+
return err
57+
}
58+
return tryBase64DecodeKey(string(b64key))
59+
}),
60+
resource.TestCheckResourceAttrWith("google_public_ca_external_account_key.prod", "mac_key", tryBase64DecodeKey),
61+
),
62+
},
63+
},
64+
})
65+
}
66+
67+
func tryBase64DecodeKey(value string) error {
68+
_, err := base64.RawURLEncoding.DecodeString(value)
69+
return err
70+
}
71+
72+
func testAccPublicCAExternalAccountKey_publicCaExternalAccountKey(context map[string]interface{}) string {
73+
return acctest.Nprintf(`
74+
resource "google_public_ca_external_account_key" "prod" {
75+
project = "%{project}"
76+
}
77+
`, context)
78+
}

google/verify/validation.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,6 @@ func ValidateBase64String(i interface{}, val string) ([]string, []error) {
305305
return nil, nil
306306
}
307307

308-
func ValidateBase64URLString(i interface{}, val string) ([]string, []error) {
309-
_, err := base64.RawURLEncoding.DecodeString(i.(string))
310-
if err != nil {
311-
return nil, []error{fmt.Errorf("could not decode %q as a valid base64URL value.", val)}
312-
}
313-
return nil, nil
314-
}
315-
316308
// StringNotInSlice returns a SchemaValidateFunc which tests if the provided value
317309
// is of type string and that it matches none of the element in the invalid slice.
318310
// if ignorecase is true, case is ignored.

0 commit comments

Comments
 (0)