Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion internal/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import (
"github.com/ory/terraform-provider-orynetwork/internal/provider"
)

// Projects with names starting with this prefix are automatically purged by the e2e cleanup job.
// DO NOT CHANGE THIS PREFIX - it must match the pattern in cloud/backoffice/backoffice/x/patterns.go
const TestProjectNamePrefix = "ory-cy-e2e-da2f162d-af61-42dd-90dc-e3fcfa7c84a0"

// TestProject holds information about a test project created for acceptance tests.
type TestProject struct {
ID string
Expand Down Expand Up @@ -152,7 +156,7 @@ func createSharedProject(t *testing.T) {
return
}

projectName := fmt.Sprintf("tf-acc-test-%d", time.Now().UnixNano())
projectName := fmt.Sprintf("%s-tf-%d", TestProjectNamePrefix, time.Now().UnixNano())
t.Logf("Creating test project: %s (environment: prod)", projectName)

// Create as "prod" environment to support all features including organizations
Expand Down
14 changes: 11 additions & 3 deletions internal/resources/project/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"

Expand All @@ -27,16 +28,17 @@ func testAccPreCheck(t *testing.T) {
// WARNING: This test creates and deletes a real Ory project.
// Only run this test if you have quota available and understand the implications.
func TestAccProjectResource_basic(t *testing.T) {
projectName := testProjectName("basic")
acctest.RunTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories(),
Steps: []resource.TestStep{
// Create and Read
{
Config: testAccProjectResourceConfig("tf-test-project", "dev"),
Config: testAccProjectResourceConfig(projectName, "dev"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("ory_project.test", "id"),
resource.TestCheckResourceAttr("ory_project.test", "name", "tf-test-project"),
resource.TestCheckResourceAttr("ory_project.test", "name", projectName),
resource.TestCheckResourceAttr("ory_project.test", "environment", "dev"),
resource.TestCheckResourceAttrSet("ory_project.test", "slug"),
resource.TestCheckResourceAttr("ory_project.test", "state", "running"),
Expand All @@ -54,12 +56,13 @@ func TestAccProjectResource_basic(t *testing.T) {

// TestAccProjectResource_prodEnvironment tests creating a production project.
func TestAccProjectResource_prodEnvironment(t *testing.T) {
projectName := testProjectName("prod")
acctest.RunTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories(),
Steps: []resource.TestStep{
{
Config: testAccProjectResourceConfig("tf-test-prod-project", "prod"),
Config: testAccProjectResourceConfig(projectName, "prod"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("ory_project.test", "id"),
resource.TestCheckResourceAttr("ory_project.test", "environment", "prod"),
Expand All @@ -69,6 +72,11 @@ func TestAccProjectResource_prodEnvironment(t *testing.T) {
})
}

// testProjectName generates a project name with the e2e prefix for hard deletion support.
func testProjectName(suffix string) string {
return fmt.Sprintf("%s-tf-%s-%d", acctest.TestProjectNamePrefix, suffix, time.Now().UnixNano())
}

func testAccProjectResourceConfig(name, environment string) string {
return fmt.Sprintf(`
provider "ory" {}
Expand Down
7 changes: 6 additions & 1 deletion scripts/run-acceptance-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ parse_curl_response() {
# Configuration
CONSOLE_API_URL="${ORY_CONSOLE_API_URL:-https://api.console.ory.sh}"
PROJECT_API_URL="${ORY_PROJECT_API_URL:-https://%s.projects.oryapis.com}"
PROJECT_NAME="tf-acc-test-$(date +%s)"

# Magic prefix that triggers hard deletion in the Ory Cloud backend.
# Projects with names starting with this prefix are automatically purged by the e2e cleanup job.
# DO NOT CHANGE THIS PREFIX - it must match the pattern in cloud/backoffice/backoffice/x/patterns.go
PROJECT_NAME_PREFIX="ory-cy-e2e-da2f162d-af61-42dd-90dc-e3fcfa7c84a0"
PROJECT_NAME="${PROJECT_NAME_PREFIX}-tf-$(date +%s)"

# Validate required environment variables
if [[ -z "${ORY_WORKSPACE_API_KEY:-}" ]]; then
Expand Down