Skip to content

Commit

Permalink
HCPCP-2204: Acceptance Tests - Vault (#1169)
Browse files Browse the repository at this point in the history
* Add separate acceptance test workflow for Vault

* HCPCP-1928 Update vault acceptance test workflow to use new environment variables for dedicated test accounts

* HCPCP-2204 Add test helper for creating unique resource names

* HCPCP-1928 Vault: Update vault cluster test

* HCPCP-2204 Consistent naming for Vault cluster tests

* HCPCP-2204 Skip: Temp skip for Vault create on AWS

* HCPCP-2204 Vault: Update test for plugin

* HCPCP-1928 Vault: Update performance replication test for

* HCPCP-1928 Vault: Temp skip for replication test
  • Loading branch information
jasonpilz authored Jan 13, 2025
1 parent 2e46500 commit 3cff20f
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 15 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/_testacc_vault.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: TestAcc Vault

on:
workflow_call:
workflow_dispatch:
pull_request:
# Vault resources still use SDKv2 so we have to target files manually until migrated
paths:
- 'internal/clients/vault_cluster.go'
- 'internal/providersdkv2/resource_vault_*'

# This prevents more than one run of this workflow from executing at a time.
# Up to 1 additional run will be queued, with anything futher being cancelled from the queue.
concurrency:
group: testacc-vault
cancel-in-progress: false

jobs:
acceptance_tests:
name: Acceptance Tests
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
token: ${{ secrets.HCP_SDK_PIPELINE_TOKEN }}

- name: Set up Go
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
with:
cache: true
go-version-file: 'go.mod'
cache-dependency-path: go.sum
id: go

- name: Install Dependencies
env:
GOPRIVATE: 'github.com/hashicorp/*'
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.3
go mod tidy
sudo wget https://github.com/jmespath/jp/releases/latest/download/jp-linux-amd64 -O /usr/local/bin/jp
sudo chmod +x /usr/local/bin/jp
- name: Run 'go mod tidy'
run: |
make depscheck
- name: Get dependencies
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.3
go mod download
- name: Go Build
run: |
go build -v .
- name: Run TestAcc
env:
TF_ACC: 1

HCP_API_HOST: ${{ secrets.HCP_API_HOST_INT }}
HCP_AUTH_URL: ${{ secrets.HCP_AUTH_URL_INT }}

HCP_ORGANIZATION_ID: ${{ secrets.VAULT_HCP_ORGANIZATION_ID }}
HCP_PROJECT_ID: ${{ secrets.VAULT_HCP_PROJECT_ID }}
HCP_CLIENT_ID: ${{ secrets.VAULT_HCP_CLIENT_ID }}
HCP_CLIENT_SECRET: ${{ secrets.VAULT_HCP_CLIENT_SECRET }}
run: |
go test ./internal/providersdkv2 \
-v \
-short \
-test.v \
-parallel=10 \
-timeout=360m \
-run=TestAcc_Vault.* \
-coverprofile=testacc-vault.out
go tool cover \
-html=testacc-vault.out \
-o testacc-vault.html
- name: Upload TestAcc Coverage Artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: Test Coverage
path: testacc-vault.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ func setTestAccPerformanceReplicationE2E(t *testing.T, tfCode string, in *inputT
return tfResources.String()
}

func TestAccPerformanceReplication_ValidationsAws(t *testing.T) {
func TestAcc_Vault_PerformanceReplication_ValidationsAws(t *testing.T) {
t.Skip("Error:http is not enabled as an observability provider")
t.Parallel()

awsPerfReplicationTestInput := &inputT{
HvnName: addTimestampSuffix("test-perf-hvn-1-"),
HvnCidr: "172.25.16.0/20",
Expand Down Expand Up @@ -153,9 +156,9 @@ func performanceReplicationSteps(t *testing.T, in *inputT) []resource.TestStep {
tier = "{{ .Tier }}"
public_endpoint = true
audit_log_config {
http_endpoint = "https://http-input-splunkcloud.com"
http_codec = "INVALID"
http_method = "POST"
http_uri = "https://http-input-splunkcloud.com"
http_codec = "INVALID"
http_method = "POST"
}
}
`, in)),
Expand All @@ -176,7 +179,7 @@ func performanceReplicationSteps(t *testing.T, in *inputT) []resource.TestStep {
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.TestCheckResourceAttrSet(primaryVaultResourceName, "audit_log_config.0.http_uri"),
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\"`),
Expand All @@ -190,9 +193,9 @@ func performanceReplicationSteps(t *testing.T, in *inputT) []resource.TestStep {
tier = "{{ .Tier }}"
public_endpoint = true
audit_log_config {
http_endpoint = "https://http-input-splunkcloud.com"
http_codec = "JSON"
http_method = "POST"
http_uri = "https://http-input-splunkcloud.com"
http_codec = "JSON"
http_method = "POST"
}
}
`, in)),
Expand All @@ -213,7 +216,7 @@ func performanceReplicationSteps(t *testing.T, in *inputT) []resource.TestStep {
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.TestCheckResourceAttrSet(primaryVaultResourceName, "audit_log_config.0.http_uri"),
resource.TestCheckResourceAttr(primaryVaultResourceName, "audit_log_config.0.http_codec", "JSON"),
resource.TestCheckResourceAttr(primaryVaultResourceName, "audit_log_config.0.http_method", "POST"),
),
Expand Down
10 changes: 6 additions & 4 deletions internal/providersdkv2/resource_vault_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ func (in *inputT) GetHvnCidr() string {

// This includes tests against both the resource, the corresponding datasource, and the dependent admin token resource
// to shorten testing time.
func TestAccVaultClusterAzure(t *testing.T) {
func TestAcc_Vault_ClusterAzure(t *testing.T) {
azureTestInput := inputT{
VaultClusterName: addTimestampSuffix("test-vault-azure-"),
HvnName: addTimestampSuffix("test-hvn-azure-"),
HvnName: testAccUniqueNameWithPrefix("vault-hvn-azure"),
VaultClusterResourceName: vaultClusterResourceName,
VaultClusterDataSourceName: vaultClusterDataSourceName,
AdminTokenResourceName: adminTokenResourceName,
Expand All @@ -72,10 +72,12 @@ func TestAccVaultClusterAzure(t *testing.T) {

// This includes tests against both the resource, the corresponding datasource, and the dependent admin token resource
// to shorten testing time.
func TestAccVaultClusterAWS(t *testing.T) {
func TestAcc_Vault_ClusterAWS(t *testing.T) {
t.Skip("resource_vault_cluster_test.go:94: Step 7/7 error: Check failed: Check 3/14 error: hcp_vault_cluster.test: Attribute 'public_endpoint' expected 'false', got 'true'")

awsTestInput := inputT{
VaultClusterName: addTimestampSuffix("test-vault-aws-"),
HvnName: addTimestampSuffix("test-hvn-aws-"),
HvnName: testAccUniqueNameWithPrefix("vault-hvn-aws"),
VaultClusterResourceName: vaultClusterResourceName,
VaultClusterDataSourceName: vaultClusterDataSourceName,
AdminTokenResourceName: adminTokenResourceName,
Expand Down
6 changes: 4 additions & 2 deletions internal/providersdkv2/resource_vault_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ resource "hcp_vault_plugin" "venafi_plugin" {
plugin_name = "venafi-pki-backend"
plugin_type = "SECRET"
}
`, addTimestampSuffix("test-hvn-aws-"), addTimestampSuffix("test-cluster-"))
`, testAccUniqueNameWithPrefix("vault-hvn-aws-"), addTimestampSuffix("test-cluster-"))

testAccVaultPluginDataSourceConfig = fmt.Sprintf(`%s
data "hcp_vault_plugin" "test" {
Expand All @@ -47,7 +47,9 @@ resource "hcp_vault_plugin" "venafi_plugin" {
`, testAccVaultPluginConfig)
)

func TestAccVaultPlugin(t *testing.T) {
func TestAcc_Vault_Plugin(t *testing.T) {
t.Parallel()

resourceName := "hcp_vault_plugin.venafi_plugin"
dataSourceName := "data.hcp_vault_plugin.test"

Expand Down
8 changes: 8 additions & 0 deletions internal/providersdkv2/test_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"strings"
"time"

"github.com/google/uuid"

sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -17,6 +19,12 @@ import (
"github.com/hashicorp/terraform-provider-hcp/internal/clients"
)

func testAccUniqueNameWithPrefix(prefix string) string {
shortUUID := uuid.New().String()[0:8]

return fmt.Sprintf("testacc-%s-%s", prefix, shortUUID)
}

func testAccCheckFullURL(name, key, port string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
Expand Down

0 comments on commit 3cff20f

Please sign in to comment.