Skip to content

Commit 801fff2

Browse files
Add new resource ProjectKajPolicyConfig (#15257) (#10850)
[upstream:2013c8378a37463a88867ef5f9c874025101e896] Signed-off-by: Modular Magician <[email protected]>
1 parent 2c7462e commit 801fff2

7 files changed

+747
-2
lines changed

.changelog/15257.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
`google_kms_project_kaj_policy_config`
3+
```

google-beta/provider/provider_mmv1_resources.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,9 +616,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
616616
}
617617

618618
// Resources
619-
// Generated resources: 714
619+
// Generated resources: 715
620620
// Generated IAM resources: 348
621-
// Total generated resources: 1062
621+
// Total generated resources: 1063
622622
var generatedResources = map[string]*schema.Resource{
623623
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
624624
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
@@ -1351,6 +1351,7 @@ var generatedResources = map[string]*schema.Resource{
13511351
"google_kms_key_ring": kms.ResourceKMSKeyRing(),
13521352
"google_kms_key_ring_import_job": kms.ResourceKMSKeyRingImportJob(),
13531353
"google_kms_organization_kaj_policy_config": kms.ResourceKMSOrganizationKajPolicyConfig(),
1354+
"google_kms_project_kaj_policy_config": kms.ResourceKMSProjectKajPolicyConfig(),
13541355
"google_kms_secret_ciphertext": kms.ResourceKMSSecretCiphertext(),
13551356
"google_logging_folder_settings": logging.ResourceLoggingFolderSettings(),
13561357
"google_logging_linked_dataset": logging.ResourceLoggingLinkedDataset(),
Lines changed: 337 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,337 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
// ----------------------------------------------------------------------------
5+
//
6+
// *** AUTO GENERATED CODE *** Type: MMv1 ***
7+
//
8+
// ----------------------------------------------------------------------------
9+
//
10+
// This code is generated by Magic Modules using the following:
11+
//
12+
// Configuration: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/products/kms/ProjectKajPolicyConfig.yaml
13+
// Template: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/templates/terraform/resource.go.tmpl
14+
//
15+
// DO NOT EDIT this file directly. Any changes made to this file will be
16+
// overwritten during the next generation cycle.
17+
//
18+
// ----------------------------------------------------------------------------
19+
20+
package kms
21+
22+
import (
23+
"fmt"
24+
"log"
25+
"net/http"
26+
"reflect"
27+
"time"
28+
29+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
30+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
31+
32+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
33+
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
34+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/verify"
35+
)
36+
37+
func ResourceKMSProjectKajPolicyConfig() *schema.Resource {
38+
return &schema.Resource{
39+
Create: resourceKMSProjectKajPolicyConfigCreate,
40+
Read: resourceKMSProjectKajPolicyConfigRead,
41+
Update: resourceKMSProjectKajPolicyConfigUpdate,
42+
Delete: resourceKMSProjectKajPolicyConfigDelete,
43+
44+
Importer: &schema.ResourceImporter{
45+
State: resourceKMSProjectKajPolicyConfigImport,
46+
},
47+
48+
Timeouts: &schema.ResourceTimeout{
49+
Create: schema.DefaultTimeout(20 * time.Minute),
50+
Update: schema.DefaultTimeout(20 * time.Minute),
51+
Delete: schema.DefaultTimeout(20 * time.Minute),
52+
},
53+
54+
CustomizeDiff: customdiff.All(
55+
tpgresource.DefaultProviderProject,
56+
),
57+
58+
Schema: map[string]*schema.Schema{
59+
"default_key_access_justification_policy": {
60+
Type: schema.TypeList,
61+
Optional: true,
62+
Description: `The default key access justification policy used when a CryptoKey is
63+
created in this project. This is only used when a Key Access Justifications
64+
policy is not provided in the CreateCryptoKeyRequest.`,
65+
MaxItems: 1,
66+
Elem: &schema.Resource{
67+
Schema: map[string]*schema.Schema{
68+
"allowed_access_reasons": {
69+
Type: schema.TypeList,
70+
Optional: true,
71+
Description: `A KeyAccessJustificationsPolicy specifies zero or more allowed
72+
AccessReason values for encrypt, decrypt, and sign operations on a
73+
CryptoKey. Possible values: ["CUSTOMER_INITIATED_SUPPORT", "GOOGLE_INITIATED_SERVICE", "THIRD_PARTY_DATA_REQUEST", "GOOGLE_INITIATED_REVIEW", "CUSTOMER_INITIATED_ACCESS", "GOOGLE_INITIATED_SYSTEM_OPERATION", "REASON_NOT_EXPECTED", "MODIFIED_CUSTOMER_INITIATED_ACCESS", "MODIFIED_GOOGLE_INITIATED_SYSTEM_OPERATION", "GOOGLE_RESPONSE_TO_PRODUCTION_ALERT", "CUSTOMER_AUTHORIZED_WORKFLOW_SERVICING"]`,
74+
Elem: &schema.Schema{
75+
Type: schema.TypeString,
76+
ValidateFunc: verify.ValidateEnum([]string{"CUSTOMER_INITIATED_SUPPORT", "GOOGLE_INITIATED_SERVICE", "THIRD_PARTY_DATA_REQUEST", "GOOGLE_INITIATED_REVIEW", "CUSTOMER_INITIATED_ACCESS", "GOOGLE_INITIATED_SYSTEM_OPERATION", "REASON_NOT_EXPECTED", "MODIFIED_CUSTOMER_INITIATED_ACCESS", "MODIFIED_GOOGLE_INITIATED_SYSTEM_OPERATION", "GOOGLE_RESPONSE_TO_PRODUCTION_ALERT", "CUSTOMER_AUTHORIZED_WORKFLOW_SERVICING"}),
77+
},
78+
},
79+
},
80+
},
81+
},
82+
"project": {
83+
Type: schema.TypeString,
84+
Optional: true,
85+
Computed: true,
86+
ForceNew: true,
87+
},
88+
},
89+
UseJSONNumber: true,
90+
}
91+
}
92+
93+
func resourceKMSProjectKajPolicyConfigCreate(d *schema.ResourceData, meta interface{}) error {
94+
config := meta.(*transport_tpg.Config)
95+
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
96+
if err != nil {
97+
return err
98+
}
99+
100+
obj := make(map[string]interface{})
101+
defaultKeyAccessJustificationPolicyProp, err := expandKMSProjectKajPolicyConfigDefaultKeyAccessJustificationPolicy(d.Get("default_key_access_justification_policy"), d, config)
102+
if err != nil {
103+
return err
104+
} else if v, ok := d.GetOkExists("default_key_access_justification_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(defaultKeyAccessJustificationPolicyProp)) && (ok || !reflect.DeepEqual(v, defaultKeyAccessJustificationPolicyProp)) {
105+
obj["defaultKeyAccessJustificationPolicy"] = defaultKeyAccessJustificationPolicyProp
106+
}
107+
108+
url, err := tpgresource.ReplaceVars(d, config, "{{KMSBasePath}}projects/{{project}}/kajPolicyConfig?updateMask=defaultKeyAccessJustificationPolicy")
109+
if err != nil {
110+
return err
111+
}
112+
113+
log.Printf("[DEBUG] Creating new ProjectKajPolicyConfig: %#v", obj)
114+
billingProject := ""
115+
116+
project, err := tpgresource.GetProject(d, config)
117+
if err != nil {
118+
return fmt.Errorf("Error fetching project for ProjectKajPolicyConfig: %s", err)
119+
}
120+
billingProject = project
121+
122+
// err == nil indicates that the billing_project value was found
123+
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
124+
billingProject = bp
125+
}
126+
127+
headers := make(http.Header)
128+
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
129+
Config: config,
130+
Method: "PATCH",
131+
Project: billingProject,
132+
RawURL: url,
133+
UserAgent: userAgent,
134+
Body: obj,
135+
Timeout: d.Timeout(schema.TimeoutCreate),
136+
Headers: headers,
137+
})
138+
if err != nil {
139+
return fmt.Errorf("Error creating ProjectKajPolicyConfig: %s", err)
140+
}
141+
142+
// Store the ID now
143+
id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/kajPolicyConfig")
144+
if err != nil {
145+
return fmt.Errorf("Error constructing id: %s", err)
146+
}
147+
d.SetId(id)
148+
149+
// This is useful if the resource in question doesn't have a perfectly consistent API
150+
// That is, the Operation for Create might return before the Get operation shows the
151+
// completed state of the resource.
152+
time.Sleep(1 * time.Minute)
153+
154+
log.Printf("[DEBUG] Finished creating ProjectKajPolicyConfig %q: %#v", d.Id(), res)
155+
156+
return resourceKMSProjectKajPolicyConfigRead(d, meta)
157+
}
158+
159+
func resourceKMSProjectKajPolicyConfigRead(d *schema.ResourceData, meta interface{}) error {
160+
config := meta.(*transport_tpg.Config)
161+
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
162+
if err != nil {
163+
return err
164+
}
165+
166+
url, err := tpgresource.ReplaceVars(d, config, "{{KMSBasePath}}projects/{{project}}/kajPolicyConfig")
167+
if err != nil {
168+
return err
169+
}
170+
171+
billingProject := ""
172+
173+
project, err := tpgresource.GetProject(d, config)
174+
if err != nil {
175+
return fmt.Errorf("Error fetching project for ProjectKajPolicyConfig: %s", err)
176+
}
177+
billingProject = project
178+
179+
// err == nil indicates that the billing_project value was found
180+
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
181+
billingProject = bp
182+
}
183+
184+
headers := make(http.Header)
185+
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
186+
Config: config,
187+
Method: "GET",
188+
Project: billingProject,
189+
RawURL: url,
190+
UserAgent: userAgent,
191+
Headers: headers,
192+
})
193+
if err != nil {
194+
return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("KMSProjectKajPolicyConfig %q", d.Id()))
195+
}
196+
197+
if err := d.Set("project", project); err != nil {
198+
return fmt.Errorf("Error reading ProjectKajPolicyConfig: %s", err)
199+
}
200+
201+
if err := d.Set("default_key_access_justification_policy", flattenKMSProjectKajPolicyConfigDefaultKeyAccessJustificationPolicy(res["defaultKeyAccessJustificationPolicy"], d, config)); err != nil {
202+
return fmt.Errorf("Error reading ProjectKajPolicyConfig: %s", err)
203+
}
204+
205+
return nil
206+
}
207+
208+
func resourceKMSProjectKajPolicyConfigUpdate(d *schema.ResourceData, meta interface{}) error {
209+
config := meta.(*transport_tpg.Config)
210+
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
211+
if err != nil {
212+
return err
213+
}
214+
215+
billingProject := ""
216+
217+
project, err := tpgresource.GetProject(d, config)
218+
if err != nil {
219+
return fmt.Errorf("Error fetching project for ProjectKajPolicyConfig: %s", err)
220+
}
221+
billingProject = project
222+
223+
obj := make(map[string]interface{})
224+
defaultKeyAccessJustificationPolicyProp, err := expandKMSProjectKajPolicyConfigDefaultKeyAccessJustificationPolicy(d.Get("default_key_access_justification_policy"), d, config)
225+
if err != nil {
226+
return err
227+
} else if v, ok := d.GetOkExists("default_key_access_justification_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, defaultKeyAccessJustificationPolicyProp)) {
228+
obj["defaultKeyAccessJustificationPolicy"] = defaultKeyAccessJustificationPolicyProp
229+
}
230+
231+
url, err := tpgresource.ReplaceVars(d, config, "{{KMSBasePath}}projects/{{project}}/kajPolicyConfig?updateMask=defaultKeyAccessJustificationPolicy")
232+
if err != nil {
233+
return err
234+
}
235+
236+
log.Printf("[DEBUG] Updating ProjectKajPolicyConfig %q: %#v", d.Id(), obj)
237+
headers := make(http.Header)
238+
239+
// err == nil indicates that the billing_project value was found
240+
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
241+
billingProject = bp
242+
}
243+
244+
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
245+
Config: config,
246+
Method: "PATCH",
247+
Project: billingProject,
248+
RawURL: url,
249+
UserAgent: userAgent,
250+
Body: obj,
251+
Timeout: d.Timeout(schema.TimeoutUpdate),
252+
Headers: headers,
253+
})
254+
255+
if err != nil {
256+
return fmt.Errorf("Error updating ProjectKajPolicyConfig %q: %s", d.Id(), err)
257+
} else {
258+
log.Printf("[DEBUG] Finished updating ProjectKajPolicyConfig %q: %#v", d.Id(), res)
259+
}
260+
261+
// This is useful if the resource in question doesn't have a perfectly consistent API
262+
// That is, the Operation for Create might return before the Get operation shows the
263+
// completed state of the resource.
264+
time.Sleep(1 * time.Minute)
265+
return resourceKMSProjectKajPolicyConfigRead(d, meta)
266+
}
267+
268+
func resourceKMSProjectKajPolicyConfigDelete(d *schema.ResourceData, meta interface{}) error {
269+
log.Printf("[WARNING] KMS ProjectKajPolicyConfig resources"+
270+
" cannot be deleted from Google Cloud. The resource %s will be removed from Terraform"+
271+
" state, but will still be present on Google Cloud.", d.Id())
272+
d.SetId("")
273+
274+
return nil
275+
}
276+
277+
func resourceKMSProjectKajPolicyConfigImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
278+
config := meta.(*transport_tpg.Config)
279+
if err := tpgresource.ParseImportId([]string{
280+
"^projects/(?P<project>[^/]+)/kajPolicyConfig$",
281+
"^(?P<project>[^/]+)$",
282+
}, d, config); err != nil {
283+
return nil, err
284+
}
285+
286+
// Replace import id for the resource id
287+
id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/kajPolicyConfig")
288+
if err != nil {
289+
return nil, fmt.Errorf("Error constructing id: %s", err)
290+
}
291+
d.SetId(id)
292+
293+
return []*schema.ResourceData{d}, nil
294+
}
295+
296+
func flattenKMSProjectKajPolicyConfigDefaultKeyAccessJustificationPolicy(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
297+
if v == nil {
298+
return nil
299+
}
300+
original := v.(map[string]interface{})
301+
if len(original) == 0 {
302+
return nil
303+
}
304+
transformed := make(map[string]interface{})
305+
transformed["allowed_access_reasons"] =
306+
flattenKMSProjectKajPolicyConfigDefaultKeyAccessJustificationPolicyAllowedAccessReasons(original["allowedAccessReasons"], d, config)
307+
return []interface{}{transformed}
308+
}
309+
func flattenKMSProjectKajPolicyConfigDefaultKeyAccessJustificationPolicyAllowedAccessReasons(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
310+
return v
311+
}
312+
313+
func expandKMSProjectKajPolicyConfigDefaultKeyAccessJustificationPolicy(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
314+
if v == nil {
315+
return nil, nil
316+
}
317+
l := v.([]interface{})
318+
if len(l) == 0 || l[0] == nil {
319+
return nil, nil
320+
}
321+
raw := l[0]
322+
original := raw.(map[string]interface{})
323+
transformed := make(map[string]interface{})
324+
325+
transformedAllowedAccessReasons, err := expandKMSProjectKajPolicyConfigDefaultKeyAccessJustificationPolicyAllowedAccessReasons(original["allowed_access_reasons"], d, config)
326+
if err != nil {
327+
return nil, err
328+
} else if val := reflect.ValueOf(transformedAllowedAccessReasons); val.IsValid() && !tpgresource.IsEmptyValue(val) {
329+
transformed["allowedAccessReasons"] = transformedAllowedAccessReasons
330+
}
331+
332+
return transformed, nil
333+
}
334+
335+
func expandKMSProjectKajPolicyConfigDefaultKeyAccessJustificationPolicyAllowedAccessReasons(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
336+
return v, nil
337+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
resource: 'google_kms_project_kaj_policy_config'
2+
generation_type: 'mmv1'
3+
source_file: 'products/kms/ProjectKajPolicyConfig.yaml'
4+
api_service_name: 'cloudkms.googleapis.com'
5+
api_version: 'v1'
6+
api_resource_type_kind: 'KeyAccessJustificationsPolicyConfig'
7+
api_variant_patterns:
8+
- 'projects/{{project}}/kajPolicyConfig'
9+
fields:
10+
- field: 'default_key_access_justification_policy.allowed_access_reasons'

0 commit comments

Comments
 (0)