Skip to content

Commit

Permalink
Create resources in specified projects
Browse files Browse the repository at this point in the history
  • Loading branch information
delores-hashicorp committed Apr 22, 2024
1 parent aef3fdc commit f625c5f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package vaultsecrets_test

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand All @@ -14,21 +13,24 @@ import (

func TestAccVaultSecretsResourceApp(t *testing.T) {
testAppName := generateRandomSlug()
projectID := os.Getenv("HCP_PROJECT_ID")
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`
resource "hcp_project" "example" {
name = "example-project"
description = "My new project!"
}
resource "hcp_vault_secrets_app" "example" {
app_name = %q
description = "Acceptance test run"
project_id = %q
}`, testAppName, projectID),
project_id = hcp_project.example.resource_id
}`, testAppName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("hcp_vault_secrets_app.example", "app_name", testAppName),
resource.TestCheckResourceAttr("hcp_vault_secrets_app.example", "description", "Acceptance test run"),
resource.TestCheckResourceAttr("hcp_vault_secrets_app.example", "project_id", projectID),
resource.TestCheckResourceAttrSet("hcp_vault_secrets_app.example", "project_id"),
),
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package vaultsecrets_test

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand All @@ -15,7 +14,6 @@ import (
func TestAccVaultSecretsResourceSecret(t *testing.T) {
testAppName1 := generateRandomSlug()
testAppName2 := generateRandomSlug()
projectID := os.Getenv("HCP_PROJECT_ID")
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Steps: []resource.TestStep{
Expand All @@ -37,20 +35,29 @@ func TestAccVaultSecretsResourceSecret(t *testing.T) {
),
},
{
PreConfig: func() {
createTestApp(t, testAppName2)
},
Config: fmt.Sprintf(`
resource "hcp_vault_secrets_secret" "example" {
resource "hcp_project" "example" {
name = "example-project"
description = "My new project!"
}
resource "hcp_vault_secrets_app" "example" {
app_name = %q
description = "Acceptance test run"
project_id = hcp_project.example.resource_id
}
resource "hcp_vault_secrets_secret" "example" {
app_name = hcp_vault_secrets_app.example.app_name
secret_name = "test_secret"
secret_value = "super secret"
project_id = hcp_project.example.resource_id
}`, testAppName2),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("hcp_vault_secrets_secret.example", "app_name", testAppName2),
resource.TestCheckResourceAttr("hcp_vault_secrets_secret.example", "secret_name", "test_secret"),
resource.TestCheckResourceAttr("hcp_vault_secrets_secret.example", "secret_value", "super secret"),
resource.TestCheckResourceAttr("hcp_vault_secrets_secret.example", "project_id", projectID),
resource.TestCheckResourceAttrSet("hcp_vault_secrets_secret.example", "project_id"),
),
},
},
Expand Down

0 comments on commit f625c5f

Please sign in to comment.