terraform-provider: add input validation (#2744)

* terraform-provider: add validation for `constellation_image`

* terraform-provider: add validation for `constellation_cluster`

* image: accept short path versions

* terraform-provider: correct error statement

Co-authored-by: Daniel Weiße <66256922+daniel-weisse@users.noreply.github.com>

* terraform-provider: remove superfluous log statements

* terraform-provider: fix error assertion casing

* terraform-provider: remove superfluous semver check

* Update terraform-provider-constellation/internal/provider/shared_attributes.go

Co-authored-by: Adrian Stobbe <stobbe.adrian@gmail.com>

---------

Co-authored-by: Daniel Weiße <66256922+daniel-weisse@users.noreply.github.com>
Co-authored-by: Adrian Stobbe <stobbe.adrian@gmail.com>
This commit is contained in:
Moritz Sanft 2023-12-20 15:56:48 +01:00 committed by GitHub
parent db65f5116d
commit 82e2875927
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 472 additions and 34 deletions

View file

@ -42,7 +42,6 @@ func TestAccImageDataSource(t *testing.T) {
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
PreCheck: bazelPreCheck,
Steps: []resource.TestStep{
// Read testing
{
Config: testingConfig + `
data "constellation_image" "test" {
@ -61,7 +60,6 @@ func TestAccImageDataSource(t *testing.T) {
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
PreCheck: bazelPreCheck,
Steps: []resource.TestStep{
// Read testing
{
Config: testingConfig + `
data "constellation_image" "test" {
@ -78,7 +76,6 @@ func TestAccImageDataSource(t *testing.T) {
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
PreCheck: bazelPreCheck,
Steps: []resource.TestStep{
// Read testing
{
Config: testingConfig + `
data "constellation_image" "test" {
@ -96,7 +93,6 @@ func TestAccImageDataSource(t *testing.T) {
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
PreCheck: bazelPreCheck,
Steps: []resource.TestStep{
// Read testing
{
Config: testingConfig + `
data "constellation_image" "test" {
@ -115,7 +111,6 @@ func TestAccImageDataSource(t *testing.T) {
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
PreCheck: bazelPreCheck,
Steps: []resource.TestStep{
// Read testing
{
Config: testingConfig + `
data "constellation_image" "test" {
@ -132,7 +127,6 @@ func TestAccImageDataSource(t *testing.T) {
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
PreCheck: bazelPreCheck,
Steps: []resource.TestStep{
// Read testing
{
Config: testingConfig + `
data "constellation_image" "test" {
@ -149,7 +143,6 @@ func TestAccImageDataSource(t *testing.T) {
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
PreCheck: bazelPreCheck,
Steps: []resource.TestStep{
// Read testing
{
Config: testingConfig + `
data "constellation_image" "test" {
@ -162,6 +155,22 @@ func TestAccImageDataSource(t *testing.T) {
},
},
},
"invalid version": {
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
PreCheck: bazelPreCheck,
Steps: []resource.TestStep{
{
Config: testingConfig + `
data "constellation_image" "test" {
version = "xxx"
attestation_variant = "azure-sev-snp"
csp = "azure"
}
`,
ExpectError: regexp.MustCompile(".*Invalid Version.*"),
},
},
},
}
for name, tc := range testCases {