-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move checking for unmanaged config secrets from the read to the update
- Loading branch information
Showing
9 changed files
with
925 additions
and
645 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package connection | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/go-cty/cty" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCheckForUnmanagedConfigurationSecrets(t *testing.T) { | ||
var testCases = []struct { | ||
name string | ||
givenConfigFromTF map[string]string | ||
givenConfigFromAPI map[string]string | ||
expectedDiagnostics diag.Diagnostics | ||
}{ | ||
{ | ||
name: "custom database has no configuration", | ||
givenConfigFromTF: map[string]string{}, | ||
givenConfigFromAPI: map[string]string{}, | ||
expectedDiagnostics: diag.Diagnostics(nil), | ||
}, | ||
{ | ||
name: "custom database has no unmanaged configuration", | ||
givenConfigFromTF: map[string]string{ | ||
"foo": "bar", | ||
}, | ||
givenConfigFromAPI: map[string]string{ | ||
"foo": "bar", | ||
}, | ||
expectedDiagnostics: diag.Diagnostics(nil), | ||
}, | ||
{ | ||
name: "custom database has unmanaged configuration", | ||
givenConfigFromTF: map[string]string{ | ||
"foo": "bar", | ||
}, | ||
givenConfigFromAPI: map[string]string{ | ||
"foo": "bar", | ||
"anotherFoo": "anotherBar", | ||
}, | ||
expectedDiagnostics: diag.Diagnostics{ | ||
diag.Diagnostic{ | ||
Severity: diag.Error, | ||
Summary: "Unmanaged Configuration Secret", | ||
Detail: "Detected a configuration secret not managed through terraform: \"anotherFoo\". If you proceed, this configuration secret will get deleted. It is required to add this configuration secret to your custom database settings to prevent unintentionally destructive results.", | ||
AttributePath: cty.Path{cty.GetAttrStep{Name: "options.configuration"}}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
t.Run(testCase.name, func(t *testing.T) { | ||
actualDiagnostics := checkForUnmanagedConfigurationSecrets( | ||
testCase.givenConfigFromTF, | ||
testCase.givenConfigFromAPI, | ||
) | ||
|
||
assert.Equal(t, testCase.expectedDiagnostics, actualDiagnostics) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.