Skip to content

Commit 37d2ab3

Browse files
Marked Runtime config fields as sensitive (#4234) (#2717)
* added marked field as sensitive Co-authored-by: upodroid <[email protected]> * clean up deadcode Co-authored-by: upodroid <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: upodroid <[email protected]>
1 parent 17f9966 commit 37d2ab3

File tree

3 files changed

+15
-75
lines changed

3 files changed

+15
-75
lines changed

.changelog/4234.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
runtimeconfig: marked value and text fields in `google_runtimeconfig_variable` resource as sensitive
3+
```

google-beta/resource_runtimeconfig_variable.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,17 @@ func resourceRuntimeconfigVariable() *schema.Resource {
4343
},
4444

4545
"value": {
46-
Type: schema.TypeString,
47-
Optional: true,
48-
ConflictsWith: []string{"text"},
46+
Type: schema.TypeString,
47+
Optional: true,
48+
Sensitive: true,
49+
ExactlyOneOf: []string{"text", "value"},
4950
},
5051

5152
"text": {
52-
Type: schema.TypeString,
53-
Optional: true,
54-
ConflictsWith: []string{"value"},
53+
Type: schema.TypeString,
54+
Optional: true,
55+
Sensitive: true,
56+
ExactlyOneOf: []string{"text", "value"},
5557
},
5658

5759
"update_time": {
@@ -188,13 +190,9 @@ func resourceRuntimeconfigVariableParseFullName(fullName string) (project, confi
188190
// newRuntimeconfigVariableFromResourceData builds a new runtimeconfig.Variable struct from the data stored in a
189191
// schema.ResourceData. Also returns the full name of the parent. Returns nil, "", err upon error.
190192
func newRuntimeconfigVariableFromResourceData(d *schema.ResourceData, project string) (variable *runtimeconfig.Variable, parent string, err error) {
191-
// Validate that both text and value are not set
192-
text, textSet := d.GetOk("text")
193-
value, valueSet := d.GetOk("value")
194193

195-
if !textSet && !valueSet {
196-
return nil, "", fmt.Errorf("You must specify one of value or text.")
197-
}
194+
text := d.Get("text")
195+
value := d.Get("value")
198196

199197
// TODO(selmanj) here we assume it's a simple name, not a full name. Should probably support full name as well
200198
parent = d.Get("parent").(string)
@@ -206,7 +204,7 @@ func newRuntimeconfigVariableFromResourceData(d *schema.ResourceData, project st
206204
Name: fullName,
207205
}
208206

209-
if textSet {
207+
if text != "" {
210208
variable.Text = text.(string)
211209
} else {
212210
variable.Value = value.(string)

google-beta/resource_runtimeconfig_variable_test.go

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ package google
22

33
import (
44
"fmt"
5-
"regexp"
65
"testing"
76
"time"
87

98
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
109
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
11-
"google.golang.org/api/runtimeconfig/v1beta1"
10+
runtimeconfig "google.golang.org/api/runtimeconfig/v1beta1"
1211
)
1312

1413
func TestAccRuntimeconfigVariable_basic(t *testing.T) {
@@ -107,38 +106,6 @@ func TestAccRuntimeconfigVariable_basicValue(t *testing.T) {
107106
})
108107
}
109108

110-
func TestAccRuntimeconfigVariable_errorsOnBothValueAndText(t *testing.T) {
111-
// Unit test, no HTTP interactions
112-
skipIfVcr(t)
113-
t.Parallel()
114-
115-
vcrTest(t, resource.TestCase{
116-
PreCheck: func() { testAccPreCheck(t) },
117-
Providers: testAccProviders,
118-
Steps: []resource.TestStep{
119-
{
120-
Config: testAccRuntimeconfigVariable_invalidBothTextValue(randString(t, 10)),
121-
ExpectError: regexp.MustCompile("conflicts with"),
122-
},
123-
},
124-
})
125-
}
126-
127-
func TestAccRuntimeconfigVariable_errorsOnMissingValueAndText(t *testing.T) {
128-
t.Parallel()
129-
130-
vcrTest(t, resource.TestCase{
131-
PreCheck: func() { testAccPreCheck(t) },
132-
Providers: testAccProviders,
133-
Steps: []resource.TestStep{
134-
{
135-
Config: testAccRuntimeconfigVariable_invalidMissingTextValue(randString(t, 10)),
136-
ExpectError: regexp.MustCompile("You must specify one of value or text"),
137-
},
138-
},
139-
})
140-
}
141-
142109
func testAccCheckRuntimeconfigVariableExists(t *testing.T, resourceName string, variable *runtimeconfig.Variable) resource.TestCheckFunc {
143110
return func(s *terraform.State) error {
144111
rs, ok := s.RootModule().Resources[resourceName]
@@ -268,31 +235,3 @@ resource "google_runtimeconfig_variable" "foobar" {
268235
}
269236
`, suffix, name, value)
270237
}
271-
272-
func testAccRuntimeconfigVariable_invalidBothTextValue(suffix string) string {
273-
return fmt.Sprintf(`
274-
resource "google_runtimeconfig_config" "foobar" {
275-
name = "some-config-%s"
276-
}
277-
278-
resource "google_runtimeconfig_variable" "foobar" {
279-
parent = google_runtimeconfig_config.foobar.name
280-
name = "%s"
281-
text = "here's my value"
282-
value = "Zm9vYmFyCg=="
283-
}
284-
`, suffix, suffix)
285-
}
286-
287-
func testAccRuntimeconfigVariable_invalidMissingTextValue(suffix string) string {
288-
return fmt.Sprintf(`
289-
resource "google_runtimeconfig_config" "foobar" {
290-
name = "some-config-%s"
291-
}
292-
293-
resource "google_runtimeconfig_variable" "foobar" {
294-
parent = google_runtimeconfig_config.foobar.name
295-
name = "my-variable-namespace/%s"
296-
}
297-
`, suffix, suffix)
298-
}

0 commit comments

Comments
 (0)