Skip to content

Commit

Permalink
Merge pull request #41257 from hashicorp/f-flex_simplify_write_only
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsonaj authored Feb 6, 2025
2 parents 631d4eb + 0e4e4f3 commit 81fb49e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
6 changes: 3 additions & 3 deletions internal/flex/write_only.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ type writeOnlyAttrGetter interface {
}

// GetWriteOnlyStringValue returns the string value of the write-only attribute from the config.
func GetWriteOnlyStringValue(d writeOnlyAttrGetter, path cty.Path, attrType cty.Type) (string, diag.Diagnostics) {
valueWO, diags := GetWriteOnlyValue(d, path, attrType)
func GetWriteOnlyStringValue(d writeOnlyAttrGetter, path cty.Path) (string, diag.Diagnostics) {
valueWO, diags := GetWriteOnlyValue(d, path, cty.String)
if diags.HasError() {
return "", diags
}

var value string
if attrType == cty.String && !valueWO.IsNull() {
if !valueWO.IsNull() {
value = valueWO.AsString()
}

Expand Down
5 changes: 1 addition & 4 deletions internal/flex/write_only_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,18 @@ func TestGetWriteOnlyStringValue(t *testing.T) {
testCases := map[string]struct {
input cty.Path
setPath cty.Path
inputType cty.Type
value cty.Value
expectedValue string
}{
"valid value": {
input: cty.GetAttrPath("test_path"),
setPath: cty.GetAttrPath("test_path"),
inputType: cty.String,
value: cty.StringVal("test_value"),
expectedValue: "test_value",
},
"value empty string": {
input: cty.GetAttrPath("test_path"),
setPath: cty.GetAttrPath("test_path"),
inputType: cty.String,
value: cty.StringVal(""),
expectedValue: "",
},
Expand All @@ -118,7 +115,7 @@ func TestGetWriteOnlyStringValue(t *testing.T) {
path: testCase.setPath,
value: testCase.value,
}
value, diags := flex.GetWriteOnlyStringValue(&m, testCase.input, testCase.inputType)
value, diags := flex.GetWriteOnlyStringValue(&m, testCase.input)

if diags.HasError() {
t.Fatalf("unexpected error: %v", diags)
Expand Down

0 comments on commit 81fb49e

Please sign in to comment.