Skip to content

Commit 81a26f8

Browse files
authored
EphemeralWriteOnly: add secretAccessKeyWo (#12967)
1 parent a04dfc3 commit 81a26f8

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

mmv1/products/bigquerydatatransfer/Config.yaml

+22-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ custom_code:
4141
post_create: 'templates/terraform/post_create/set_computed_name.tmpl'
4242
pre_update: 'templates/terraform/pre_update/bigquerydatatransfer_config.tmpl'
4343
custom_import: 'templates/terraform/custom_import/bigquery_data_transfer_self_link_as_name_set_location.go.tmpl'
44+
raw_resource_config_validation: 'templates/terraform/validation/bigquery_data_transfer_config.go.tmpl'
4445
custom_diff:
4546
- 'sensitiveParamCustomizeDiff'
4647
- 'paramsCustomizeDiff'
@@ -210,6 +211,12 @@ properties:
210211
**NOTE** : If you are attempting to update a parameter that cannot be updated (due to api limitations) [please force recreation of the resource](https://www.terraform.io/cli/state/taint#forcing-re-creation-of-resources).
211212
required: true
212213
custom_flatten: 'templates/terraform/custom_flatten/json_to_string_map.go.tmpl'
214+
215+
- name: 'sensitiveParamsWoVersion'
216+
type: Integer
217+
immutable: true
218+
description: |
219+
The version of the sensitive params - used to trigger updates of the write-only params
213220
- name: 'sensitiveParams'
214221
type: NestedObject
215222
description: |
@@ -226,6 +233,19 @@ properties:
226233
type: String
227234
description: |
228235
The Secret Access Key of the AWS account transferring data from.
229-
230-
required: true
231236
sensitive: true
237+
at_least_one_of:
238+
- 'sensitive_params.0.secretAccessKey'
239+
- 'sensitive_params.0.secretAccessKeyWo'
240+
conflicts:
241+
- 'sensitive_params.0.secretAccessKeyWo'
242+
- name: 'secretAccessKeyWo' # Wo is convention for write-only properties
243+
type: String
244+
description: |
245+
The Secret Access Key of the AWS account transferring data from.
246+
write_only: true
247+
at_least_one_of:
248+
- 'sensitive_params.0.secretAccessKeyWo'
249+
- 'sensitive_params.0.secretAccessKey'
250+
conflicts:
251+
- 'sensitive_params.0.secretAccessKey'

mmv1/templates/terraform/constants/bigquery_data_transfer.go.tmpl

+11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var sensitiveParams = []string{"secret_access_key"}
2+
var sensitiveWoParams = []string{"secret_access_key_wo"}
23

34
func sensitiveParamCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v interface{}) error {
45
for _, sp := range sensitiveParams {
@@ -8,6 +9,16 @@ func sensitiveParamCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, v
89
return fmt.Errorf("Sensitive param [%s] cannot be set in both `params` and the `sensitive_params` block.", sp)
910
}
1011
}
12+
13+
{{- if ne $.Compiler "terraformgoogleconversion-codegen" }}
14+
for _, sp := range sensitiveWoParams {
15+
mapLabel := diff.Get("params." + sp[:len(sp)-3]).(string)
16+
authLabel, _ := diff.GetRawConfigAt(cty.GetAttrPath("sensitive_params").IndexInt(0).GetAttr(sp))
17+
if mapLabel != "" && authLabel.AsString() != "" {
18+
return fmt.Errorf("Sensitive param [%s] cannot be set in both `params` and the `sensitive_params` block.", sp)
19+
}
20+
}
21+
{{- end }}
1122
return nil
1223
}
1324

mmv1/templates/terraform/encoders/bigquery_data_transfer.go.tmpl

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ for _, sp := range sensitiveParams {
3939
params[sp] = auth.(string)
4040
}
4141
}
42+
{{- if ne $.Compiler "terraformgoogleconversion-codegen" }}
43+
for _, sp := range sensitiveWoParams {
44+
if auth, _ := d.GetRawConfigAt(cty.GetAttrPath("sensitive_params").IndexInt(0).GetAttr(sp)); !auth.IsNull() && auth.Type().Equals(cty.String) {
45+
sp = sp[:len(sp)-3] // _wo is convention for write-only params and are removed here
46+
params[sp] = auth.AsString()
47+
}
48+
}
49+
{{- end }}
4250

4351
obj["params"] = params
4452

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
validation.PreferWriteOnlyAttribute(cty.GetAttrPath("sensitive_params").IndexInt(0).GetAttr("secret_access_key"),cty.GetAttrPath("sensitive_params").IndexInt(0).GetAttr("secret_access_key_wo"))

0 commit comments

Comments
 (0)