Skip to content

Commit

Permalink
Fixed HttpCodec Check (#781)
Browse files Browse the repository at this point in the history
* changed httpMethod to httpCodec

* added changelog

* added start of test

* remove unit test from resource_vault_cluster

* added e2e test

* added e2e test to check if error is correct

* updated changelog

---------

Co-authored-by: manish-hashicorp <[email protected]>
  • Loading branch information
jaireddjawed and manish-hashicorp authored Apr 4, 2024
1 parent fc4b59a commit 6798bdd
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/781.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
Fixed an issue that caused a HTTP audit-log streaming config to fail with allowed values for http_codec are only "JSON" or "NDJSON"
```
2 changes: 1 addition & 1 deletion internal/providersdkv2/resource_vault_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1587,7 +1587,7 @@ func getValidObservabilityConfig(config map[string]interface{}) (*vaultmodels.Ha
invalidProviderConfigError = diag.Errorf("http configuration is invalid: allowed values for http_method are only \"POST\", \"PUT\", or \"PATCH\"")
}

if strings.ToUpper(httpMethod) != "JSON" && strings.ToUpper(httpMethod) != "NDJSON" {
if strings.ToUpper(httpCodec) != "JSON" && strings.ToUpper(httpCodec) != "NDJSON" {
invalidProviderConfigError = diag.Errorf("http configuration is invalid: allowed values for http_codec are only \"JSON\" or \"NDJSON\"")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,80 @@ func performanceReplicationSteps(t *testing.T, in *inputT) []resource.TestStep {
resource.TestCheckResourceAttrSet(primaryVaultResourceName, "created_at"),
),
},
{
// add an http audit log provider
Config: testConfig(setTestAccPerformanceReplicationE2E(t, `
resource "hcp_vault_cluster" "c1" {
cluster_id = "{{ .VaultClusterName }}"
hvn_id = hcp_hvn.hvn1.hvn_id
tier = "{{ .Tier }}"
public_endpoint = true
audit_log_config {
http_endpoint = "https://http-input-splunkcloud.com"
http_codec = "INVALID"
http_method = "POST"
}
}
`, in)),
Check: resource.ComposeTestCheckFunc(
testAccCheckVaultClusterExists(primaryVaultResourceName),
resource.TestCheckResourceAttr(primaryVaultResourceName, "cluster_id", in.VaultClusterName),
resource.TestCheckResourceAttr(primaryVaultResourceName, "hvn_id", in.HvnName),
resource.TestCheckResourceAttr(primaryVaultResourceName, "tier", in.Tier),
resource.TestCheckResourceAttr(primaryVaultResourceName, "cloud_provider", in.CloudProvider),
resource.TestCheckResourceAttr(primaryVaultResourceName, "region", in.Region),
resource.TestCheckResourceAttr(primaryVaultResourceName, "public_endpoint", "true"),
resource.TestCheckResourceAttr(primaryVaultResourceName, "namespace", "admin"),
resource.TestCheckResourceAttrSet(primaryVaultResourceName, "vault_version"),
resource.TestCheckResourceAttrSet(primaryVaultResourceName, "organization_id"),
resource.TestCheckResourceAttrSet(primaryVaultResourceName, "project_id"),
resource.TestCheckResourceAttrSet(primaryVaultResourceName, "vault_public_endpoint_url"),
resource.TestCheckResourceAttrSet(primaryVaultResourceName, "self_link"),
resource.TestCheckResourceAttrSet(primaryVaultResourceName, "vault_private_endpoint_url"),
testAccCheckFullURL(primaryVaultResourceName, "vault_private_endpoint_url", ""),
resource.TestCheckResourceAttrSet(primaryVaultResourceName, "created_at"),
resource.TestCheckResourceAttrSet(primaryVaultResourceName, "audit_log_config.0.http_endpoint"),
resource.TestCheckResourceAttr(primaryVaultResourceName, "audit_log_config.0.http_method", "POST"),
),
ExpectError: regexp.MustCompile(`http configuration is invalid: allowed values for http_codec are only \"JSON\" or \"NDJSON\"`),
},
{
// add an http audit log provider
Config: testConfig(setTestAccPerformanceReplicationE2E(t, `
resource "hcp_vault_cluster" "c1" {
cluster_id = "{{ .VaultClusterName }}"
hvn_id = hcp_hvn.hvn1.hvn_id
tier = "{{ .Tier }}"
public_endpoint = true
audit_log_config {
http_endpoint = "https://http-input-splunkcloud.com"
http_codec = "JSON"
http_method = "POST"
}
}
`, in)),
Check: resource.ComposeTestCheckFunc(
testAccCheckVaultClusterExists(primaryVaultResourceName),
resource.TestCheckResourceAttr(primaryVaultResourceName, "cluster_id", in.VaultClusterName),
resource.TestCheckResourceAttr(primaryVaultResourceName, "hvn_id", in.HvnName),
resource.TestCheckResourceAttr(primaryVaultResourceName, "tier", in.Tier),
resource.TestCheckResourceAttr(primaryVaultResourceName, "cloud_provider", in.CloudProvider),
resource.TestCheckResourceAttr(primaryVaultResourceName, "region", in.Region),
resource.TestCheckResourceAttr(primaryVaultResourceName, "public_endpoint", "true"),
resource.TestCheckResourceAttr(primaryVaultResourceName, "namespace", "admin"),
resource.TestCheckResourceAttrSet(primaryVaultResourceName, "vault_version"),
resource.TestCheckResourceAttrSet(primaryVaultResourceName, "organization_id"),
resource.TestCheckResourceAttrSet(primaryVaultResourceName, "project_id"),
resource.TestCheckResourceAttrSet(primaryVaultResourceName, "vault_public_endpoint_url"),
resource.TestCheckResourceAttrSet(primaryVaultResourceName, "self_link"),
resource.TestCheckResourceAttrSet(primaryVaultResourceName, "vault_private_endpoint_url"),
testAccCheckFullURL(primaryVaultResourceName, "vault_private_endpoint_url", ""),
resource.TestCheckResourceAttrSet(primaryVaultResourceName, "created_at"),
resource.TestCheckResourceAttrSet(primaryVaultResourceName, "audit_log_config.0.http_endpoint"),
resource.TestCheckResourceAttr(primaryVaultResourceName, "audit_log_config.0.http_codec", "JSON"),
resource.TestCheckResourceAttr(primaryVaultResourceName, "audit_log_config.0.http_method", "POST"),
),
},
{
// secondary cluster creation failed as tier doesn't match the tier of primary
Config: testConfig(setTestAccPerformanceReplicationE2E(t, `
Expand Down

0 comments on commit 6798bdd

Please sign in to comment.