diff --git a/internal/service/platform/connector/secretManagers/aws_secret_manager_test.go b/internal/service/platform/connector/secretManagers/aws_secret_manager_test.go index ce5a93014..c5fad8ce8 100644 --- a/internal/service/platform/connector/secretManagers/aws_secret_manager_test.go +++ b/internal/service/platform/connector/secretManagers/aws_secret_manager_test.go @@ -123,7 +123,7 @@ func TestOrgResourceConnectorAwsSM_inherit(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "description", "test"), resource.TestCheckResourceAttr(resourceName, "tags.#", "1"), resource.TestCheckResourceAttr(resourceName, "delegate_selectors.#", "1"), - resource.TestCheckResourceAttr(resourceName, "default", "true"), + resource.TestCheckResourceAttr(resourceName, "default", "false"), resource.TestCheckResourceAttr(resourceName, "secret_name_prefix", "test"), resource.TestCheckResourceAttr(resourceName, "credentials.0.inherit_from_delegate", "true"), ), @@ -137,7 +137,7 @@ func TestOrgResourceConnectorAwsSM_inherit(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "description", "test"), resource.TestCheckResourceAttr(resourceName, "tags.#", "1"), resource.TestCheckResourceAttr(resourceName, "delegate_selectors.#", "1"), - resource.TestCheckResourceAttr(resourceName, "default", "true"), + resource.TestCheckResourceAttr(resourceName, "default", "false"), resource.TestCheckResourceAttr(resourceName, "secret_name_prefix", "test"), resource.TestCheckResourceAttr(resourceName, "credentials.0.inherit_from_delegate", "true"), ), @@ -512,7 +512,7 @@ func testOrgResourceConnectorAwsSM_inherit(id string, name string) string { secret_name_prefix = "test" region = "us-east-1" delegate_selectors = ["harness-delegate"] - default = true + default = false credentials { inherit_from_delegate = true } diff --git a/internal/service/platform/connector/secretManagers/gcp_secret_manager_data_source_test.go b/internal/service/platform/connector/secretManagers/gcp_secret_manager_data_source_test.go index 5615e9442..78210641e 100644 --- a/internal/service/platform/connector/secretManagers/gcp_secret_manager_data_source_test.go +++ b/internal/service/platform/connector/secretManagers/gcp_secret_manager_data_source_test.go @@ -10,7 +10,6 @@ import ( ) func TestAccDataSourceConnectorGcpSm(t *testing.T) { - t.Skip() var ( name = fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(4)) @@ -39,7 +38,6 @@ func TestAccDataSourceConnectorGcpSm(t *testing.T) { }) } func TestAccDataSourceConnectorGcpSmProjectLevel(t *testing.T) { - t.Skip() var ( name = fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(4)) gcpName = fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) @@ -68,7 +66,6 @@ func TestAccDataSourceConnectorGcpSmProjectLevel(t *testing.T) { }) } func TestAccDataSourceConnectorGcpSmOrgLevel(t *testing.T) { - t.Skip() var ( name = fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(4)) connectorName = fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) @@ -126,7 +123,6 @@ func TestAccDataSourceConnectorGcpSmDefault(t *testing.T) { }) } func TestAccDataSourceConnectorGcpSmDefaultProjectLevel(t *testing.T) { - t.Skip() var ( name = fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(4)) gcpName = fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) @@ -191,7 +187,7 @@ func testAccDataSourceConnectorGcpSM(id string, name string) string { name = "%[1]s" description = "test" tags = ["foo:bar"] - secret_manager_identifier = "azureSecretManager" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" } @@ -259,7 +255,7 @@ func testAccDataSourceConnectorGcpSMProjectLevel(id string, name string, gcpName org_id= harness_platform_organization.test.id project_id=harness_platform_project.test.id tags = ["foo:bar"] - secret_manager_identifier = "%[1]s" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" depends_on = [time_sleep.wait_5_seconds] @@ -328,7 +324,7 @@ func testAccDataSourceConnectorGcpSMOrgLevel(id string, name string) string { description = "test" org_id= harness_platform_organization.test.id tags = ["foo:bar"] - secret_manager_identifier = "%[1]s" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" depends_on = [time_sleep.wait_5_seconds] @@ -369,7 +365,7 @@ func testAccDataSourceConnectorGcpSMDefault(id string, name string) string { name = "%[1]s" description = "test" tags = ["foo:bar"] - secret_manager_identifier = "azureSecretManager" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" } @@ -438,7 +434,7 @@ func testAccDataSourceConnectorGcpSMDefaultProjectLevel(id string, gcpname strin org_id= harness_platform_organization.test.id project_id=harness_platform_project.test.id tags = ["foo:bar"] - secret_manager_identifier = "%[1]s" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" depends_on = [time_sleep.wait_5_seconds] @@ -507,7 +503,7 @@ func testAccDataSourceConnectorGcpSMDefaultOrgLevel(id string, gcpname string) s description = "test" org_id= harness_platform_organization.test.id tags = ["foo:bar"] - secret_manager_identifier = "%[1]s" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" depends_on = [time_sleep.wait_5_seconds] diff --git a/internal/service/platform/connector/secretManagers/gcp_secret_manager_test.go b/internal/service/platform/connector/secretManagers/gcp_secret_manager_test.go index adb7de6c5..e4169560b 100644 --- a/internal/service/platform/connector/secretManagers/gcp_secret_manager_test.go +++ b/internal/service/platform/connector/secretManagers/gcp_secret_manager_test.go @@ -10,7 +10,6 @@ import ( ) func TestAccResourceConnectorGcpSM(t *testing.T) { - t.Skip() id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) name := id @@ -59,7 +58,6 @@ func TestAccResourceConnectorGcpSM(t *testing.T) { } func TestProjectResourceConnectorGcpSM(t *testing.T) { - t.Skip() id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) connectorName := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(10)) @@ -312,7 +310,7 @@ func testAccResourceConnectorGcpSM(id string, name string) string { name = "%[1]s" description = "test" tags = ["foo:bar"] - secret_manager_identifier = "azureSecretManager" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" } @@ -378,7 +376,7 @@ func testProjectResourceConnectorGcpSM(id string, name string, connectorName str org_id= harness_platform_organization.test.id project_id=harness_platform_project.test.id tags = ["foo:bar"] - secret_manager_identifier = "%[3]s" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" depends_on = [time_sleep.wait_5_seconds] @@ -442,7 +440,7 @@ func testOrgResourceConnectorGcpSM(id string, name string, connectorName string) description = "test" org_id= harness_platform_organization.test.id tags = ["foo:bar"] - secret_manager_identifier = "%[3]s" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" depends_on = [time_sleep.wait_5_seconds] @@ -478,7 +476,7 @@ func testAccResourceConnectorGcpSMDefault(id string, name string) string { name = "%[1]s" description = "test" tags = ["foo:bar"] - secret_manager_identifier = "azureSecretManager" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" } @@ -544,7 +542,7 @@ func testProjectResourceConnectorGcpSMDefault(id string, name string, connectorN org_id= harness_platform_organization.test.id project_id=harness_platform_project.test.id tags = ["foo:bar"] - secret_manager_identifier = "%[3]s" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" depends_on = [time_sleep.wait_5_seconds] @@ -607,7 +605,7 @@ func testOrgResourceConnectorGcpSMDefault(id string, name string, connectorName description = "test" org_id= harness_platform_organization.test.id tags = ["foo:bar"] - secret_manager_identifier = "%[3]s" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" depends_on = [time_sleep.wait_5_seconds] diff --git a/internal/service/platform/connector/secretManagers/secretManagers.go b/internal/service/platform/connector/secretManagers/secretManagers.go index 3c81458d8..5d07e2ec7 100644 --- a/internal/service/platform/connector/secretManagers/secretManagers.go +++ b/internal/service/platform/connector/secretManagers/secretManagers.go @@ -3,14 +3,13 @@ package secretManagers import ( "context" "fmt" - "net/http" - "github.com/antihax/optional" "github.com/harness/harness-go-sdk/harness/nextgen" "github.com/harness/terraform-provider-harness/helpers" "github.com/harness/terraform-provider-harness/internal" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "net/http" ) type ReadConnectorData func(*schema.ResourceData, *nextgen.ConnectorInfo) error diff --git a/internal/service/platform/connector/secretManagers/vault_data_source_test.go b/internal/service/platform/connector/secretManagers/vault_data_source_test.go index 75431b2c4..1cdeea771 100644 --- a/internal/service/platform/connector/secretManagers/vault_data_source_test.go +++ b/internal/service/platform/connector/secretManagers/vault_data_source_test.go @@ -663,7 +663,7 @@ func testAccDataSourceConnectorVault_VaultAgent(name string) string { description = "test" tags = ["foo:bar"] - secret_manager_identifier = "azureSecretManager" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" } @@ -749,7 +749,7 @@ func testAccDataSourceConnectorVault_VaultAgentProjectLevel(name string, connect tags = ["foo:bar"] org_id= harness_platform_organization.test.id project_id=harness_platform_project.test.id - secret_manager_identifier = "%[2]s" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" depends_on = [time_sleep.wait_5_seconds] @@ -833,7 +833,7 @@ func testAccDataSourceConnectorVault_VaultAgentOrgLevel(name string, connectorNa description = "test" tags = ["foo:bar"] org_id = harness_platform_organization.test.id - secret_manager_identifier = "%[2]s" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" depends_on = [time_sleep.wait_2_seconds] @@ -890,7 +890,7 @@ func testAccDataSourceConnectorVault_k8sAuth(name string) string { description = "test" tags = ["foo:bar"] - secret_manager_identifier = "azureSecretManager" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" } @@ -978,7 +978,7 @@ func testAccDataSourceConnectorVault_k8sAuthProjectLevel(name string, connectorN tags = ["foo:bar"] org_id= harness_platform_organization.test.id project_id=harness_platform_project.test.id - secret_manager_identifier = "%[2]s" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" depends_on = [time_sleep.wait_5_seconds] @@ -1064,7 +1064,7 @@ func testAccDataSourceConnectorVault_k8sAuthOrgLevel(name string, connectorName description = "test" tags = ["foo:bar"] org_id= harness_platform_organization.test.id - secret_manager_identifier = "%[2]s" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" depends_on = [time_sleep.wait_4_seconds] diff --git a/internal/service/platform/connector/secretManagers/vault_test.go b/internal/service/platform/connector/secretManagers/vault_test.go index 4826ca340..a91c27b8a 100644 --- a/internal/service/platform/connector/secretManagers/vault_test.go +++ b/internal/service/platform/connector/secretManagers/vault_test.go @@ -584,7 +584,7 @@ func TestProjectResourceConnectorVault_AppRole(t *testing.T) { name := id updatedName := fmt.Sprintf("%s_updated", name) resourceName := "harness_platform_connector_vault.test" - vault_sercet := os.Getenv("HARNESS_TEST_VAULT_SECRET") + vaultSecret := os.Getenv("HARNESS_TEST_VAULT_SECRET") resource.UnitTest(t, resource.TestCase{ PreCheck: func() { acctest.TestAccPreCheck(t) }, @@ -595,7 +595,7 @@ func TestProjectResourceConnectorVault_AppRole(t *testing.T) { CheckDestroy: testAccConnectorDestroy(resourceName), Steps: []resource.TestStep{ { - Config: testProjectResourceConnectorVault_app_role(id, name, vault_sercet), + Config: testProjectResourceConnectorVault_app_role(id, name, vaultSecret), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "id", id), resource.TestCheckResourceAttr(resourceName, "identifier", id), @@ -611,7 +611,7 @@ func TestProjectResourceConnectorVault_AppRole(t *testing.T) { ), }, { - Config: testProjectResourceConnectorVault_app_role(id, updatedName, vault_sercet), + Config: testProjectResourceConnectorVault_app_role(id, updatedName, vaultSecret), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "id", id), resource.TestCheckResourceAttr(resourceName, "identifier", id), @@ -1060,6 +1060,12 @@ func testAccResourceConnectorVault_app_role(id string, name string, vault_secret value_type = "Inline" value = "%[3]s" } + + resource "time_sleep" "wait_4_seconds" { + depends_on = [harness_platform_secret_text.test] + destroy_duration = "4s" + } + resource "harness_platform_connector_vault" "test" { identifier = "%[1]s" @@ -1083,15 +1089,11 @@ func testAccResourceConnectorVault_app_role(id string, name string, vault_secret delegate_selectors = ["harness-delegate"] vault_url = "https://vaultqa.harness.io" - depends_on = [time_sleep.wait_8_seconds] - } - - resource "time_sleep" "wait_8_seconds" { - depends_on = [harness_platform_secret_text.test] - create_duration = "8s" + depends_on = [time_sleep.wait_4_seconds] } `, id, name, vault_secret) } + func testProjectResourceConnectorVault_app_role(id string, name string, vault_secret string) string { return fmt.Sprintf(` resource "harness_platform_organization" "test" { @@ -1230,7 +1232,7 @@ func testAccResourceConnectorVault_k8s_auth(id string, name string) string { description = "test" tags = ["foo:bar"] - secret_manager_identifier = "azureSecretManager" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" } @@ -1314,7 +1316,7 @@ func testProjectResourceConnectorVault_k8s_auth(id string, name string, connecto tags = ["foo:bar"] org_id= harness_platform_organization.test.id project_id=harness_platform_project.test.id - secret_manager_identifier = "%[3]s" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" depends_on = [time_sleep.wait_8_seconds_2] @@ -1394,7 +1396,7 @@ func testOrgResourceConnectorVault_k8s_auth(id string, name string, connectorNam description = "test" tags = ["foo:bar"] org_id= harness_platform_organization.test.id - secret_manager_identifier = "%[3]s" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" depends_on = [time_sleep.wait_8_seconds_2] @@ -1449,7 +1451,7 @@ func testAccResourceConnectorVault_vault_agent(id string, name string) string { description = "test" tags = ["foo:bar"] - secret_manager_identifier = "azureSecretManager" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" } @@ -1531,7 +1533,7 @@ func testProjectResourceConnectorVault_vault_agent(id string, name string, conne tags = ["foo:bar"] org_id= harness_platform_organization.test.id project_id=harness_platform_project.test.id - secret_manager_identifier = "%[3]s" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" depends_on = [time_sleep.wait_8_seconds_2] @@ -1609,7 +1611,7 @@ func testOrgResourceConnectorVault_vault_agent(id string, name string, connector description = "test" tags = ["foo:bar"] org_id = harness_platform_organization.test.id - secret_manager_identifier = "%[3]s" + secret_manager_identifier = "harnessSecretManager" value_type = "Reference" value = "secret" depends_on = [time_sleep.wait_8_seconds_2] diff --git a/internal/service/platform/user/data_source_user_test.go b/internal/service/platform/user/data_source_user_test.go index 8ee418f2b..a6c50757a 100644 --- a/internal/service/platform/user/data_source_user_test.go +++ b/internal/service/platform/user/data_source_user_test.go @@ -2,6 +2,9 @@ package user_test import ( "fmt" + "log" + "net/url" + "os" "strings" "testing" @@ -10,7 +13,44 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) +func fetchEnvironmentFromEndpoint(endpoint string) (string, error) { + + parsedURL, err := url.Parse(endpoint) + if err != nil { + return "", fmt.Errorf("failed to parse endpoint URL: %w", err) + } + + hostParts := strings.Split(parsedURL.Hostname(), ".") + if len(hostParts) < 2 { + return "", fmt.Errorf("unexpected URL format: %s", parsedURL.Hostname()) + } + + env := hostParts[0] + + log.Printf("Fetched environment: %s", env) + + return env, nil +} + func TestAccDataSourceUserProjectLevel(t *testing.T) { + endpoint := os.Getenv("HARNESS_ENDPOINT") + + if endpoint == "" { + t.Fatal("HARNESS_ENDPOINT environment variable is not set") + } + + env, err := fetchEnvironmentFromEndpoint(endpoint) + if err != nil { + t.Fatalf("Error fetching environment: %v", err) + } + + log.Printf("Environment fetched from endpoint: %s", env) + + if !strings.EqualFold(env, "QA") { + log.Printf("Skipping test as the environment is not QA (found: %s)", env) + t.Skip("Skipping test because environment is not QA") + } + id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(6)) name := id email := strings.ToLower(id) + "@harness.io" @@ -34,6 +74,24 @@ func TestAccDataSourceUserProjectLevel(t *testing.T) { } func TestAccDataSourceUserAccountLevel(t *testing.T) { + endpoint := os.Getenv("HARNESS_ENDPOINT") + + if endpoint == "" { + t.Fatal("HARNESS_ENDPOINT environment variable is not set") + } + + env, err := fetchEnvironmentFromEndpoint(endpoint) + if err != nil { + t.Fatalf("Error fetching environment: %v", err) + } + + log.Printf("Environment fetched from endpoint: %s", env) + + if !strings.EqualFold(env, "QA") { + log.Printf("Skipping test as the environment is not QA (found: %s)", env) + t.Skip("Skipping test because environment is not QA") + } + id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(6)) name := id email := strings.ToLower(id) + "@harness.io" @@ -57,6 +115,24 @@ func TestAccDataSourceUserAccountLevel(t *testing.T) { } func TestAccDataSourceUserOrgLevel(t *testing.T) { + endpoint := os.Getenv("HARNESS_ENDPOINT") + + if endpoint == "" { + t.Fatal("HARNESS_ENDPOINT environment variable is not set") + } + + env, err := fetchEnvironmentFromEndpoint(endpoint) + if err != nil { + t.Fatalf("Error fetching environment: %v", err) + } + + log.Printf("Environment fetched from endpoint: %s", env) + + if !strings.EqualFold(env, "QA") { + log.Printf("Skipping test as the environment is not QA (found: %s)", env) + t.Skip("Skipping test because environment is not QA") + } + id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(6)) name := id email := strings.ToLower(id) + "@harness.io" diff --git a/internal/service/platform/user/resource_user_test.go b/internal/service/platform/user/resource_user_test.go index 79ea6e1e8..3d41ade37 100644 --- a/internal/service/platform/user/resource_user_test.go +++ b/internal/service/platform/user/resource_user_test.go @@ -2,6 +2,8 @@ package user_test import ( "fmt" + "log" + "os" "strings" "testing" @@ -15,6 +17,24 @@ import ( ) func TestAccResourceUserProjectLevel(t *testing.T) { + endpoint := os.Getenv("HARNESS_ENDPOINT") + + if endpoint == "" { + t.Fatal("HARNESS_ENDPOINT environment variable is not set") + } + + env, err := fetchEnvironmentFromEndpoint(endpoint) + if err != nil { + t.Fatalf("Error fetching environment: %v", err) + } + + log.Printf("Environment fetched from endpoint: %s", env) + + if !strings.EqualFold(env, "QA") { + log.Printf("Skipping test as the environment is not QA (found: %s)", env) + t.Skip("Skipping test because environment is not QA") + } + id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) name := id email := strings.ToLower(id) + "@harness.io" @@ -44,6 +64,24 @@ func TestAccResourceUserProjectLevel(t *testing.T) { } func TestAccResourceUserAccountLevel(t *testing.T) { + endpoint := os.Getenv("HARNESS_ENDPOINT") + + if endpoint == "" { + t.Fatal("HARNESS_ENDPOINT environment variable is not set") + } + + env, err := fetchEnvironmentFromEndpoint(endpoint) + if err != nil { + t.Fatalf("Error fetching environment: %v", err) + } + + log.Printf("Environment fetched from endpoint: %s", env) + + if !strings.EqualFold(env, "QA") { + log.Printf("Skipping test as the environment is not QA (found: %s)", env) + t.Skip("Skipping test because environment is not QA") + } + id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) name := id email := strings.ToLower(id) + "@harness.io" @@ -72,6 +110,24 @@ func TestAccResourceUserAccountLevel(t *testing.T) { } func TestAccResourceUserOrgLevel(t *testing.T) { + endpoint := os.Getenv("HARNESS_ENDPOINT") + + if endpoint == "" { + t.Fatal("HARNESS_ENDPOINT environment variable is not set") + } + + env, err := fetchEnvironmentFromEndpoint(endpoint) + if err != nil { + t.Fatalf("Error fetching environment: %v", err) + } + + log.Printf("Environment fetched from endpoint: %s", env) + + if !strings.EqualFold(env, "QA") { + log.Printf("Skipping test as the environment is not QA (found: %s)", env) + t.Skip("Skipping test because environment is not QA") + } + id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) name := id email := strings.ToLower(id) + "@harness.io" @@ -100,6 +156,24 @@ func TestAccResourceUserOrgLevel(t *testing.T) { } func TestAccResourceUser_DeleteUnderlyingResourceProjectLevel(t *testing.T) { + endpoint := os.Getenv("HARNESS_ENDPOINT") + + if endpoint == "" { + t.Fatal("HARNESS_ENDPOINT environment variable is not set") + } + + env, err := fetchEnvironmentFromEndpoint(endpoint) + if err != nil { + t.Fatalf("Error fetching environment: %v", err) + } + + log.Printf("Environment fetched from endpoint: %s", env) + + if !strings.EqualFold(env, "QA") { + log.Printf("Skipping test as the environment is not QA (found: %s)", env) + t.Skip("Skipping test because environment is not QA") + } + id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) name := id email := strings.ToLower(id) + "@harness.io" @@ -136,6 +210,24 @@ func TestAccResourceUser_DeleteUnderlyingResourceProjectLevel(t *testing.T) { } func TestAccResourceUser_DeleteUnderlyingResourceAccountLevel(t *testing.T) { + endpoint := os.Getenv("HARNESS_ENDPOINT") + + if endpoint == "" { + t.Fatal("HARNESS_ENDPOINT environment variable is not set") + } + + env, err := fetchEnvironmentFromEndpoint(endpoint) + if err != nil { + t.Fatalf("Error fetching environment: %v", err) + } + + log.Printf("Environment fetched from endpoint: %s", env) + + if !strings.EqualFold(env, "QA") { + log.Printf("Skipping test as the environment is not QA (found: %s)", env) + t.Skip("Skipping test because environment is not QA") + } + id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) name := id email := strings.ToLower(id) + "@harness.io" @@ -168,6 +260,24 @@ func TestAccResourceUser_DeleteUnderlyingResourceAccountLevel(t *testing.T) { } func TestAccResourceUser_DeleteUnderlyingResourceOrgLevel(t *testing.T) { + endpoint := os.Getenv("HARNESS_ENDPOINT") + + if endpoint == "" { + t.Fatal("HARNESS_ENDPOINT environment variable is not set") + } + + env, err := fetchEnvironmentFromEndpoint(endpoint) + if err != nil { + t.Fatalf("Error fetching environment: %v", err) + } + + log.Printf("Environment fetched from endpoint: %s", env) + + if !strings.EqualFold(env, "QA") { + log.Printf("Skipping test as the environment is not QA (found: %s)", env) + t.Skip("Skipping test because environment is not QA") + } + id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) name := id email := strings.ToLower(id) + "@harness.io" @@ -203,6 +313,24 @@ func TestAccResourceUser_DeleteUnderlyingResourceOrgLevel(t *testing.T) { // New test case for user group updates func TestAccResourceUser_UpdateUserGroups(t *testing.T) { + endpoint := os.Getenv("HARNESS_ENDPOINT") + + if endpoint == "" { + t.Fatal("HARNESS_ENDPOINT environment variable is not set") + } + + env, err := fetchEnvironmentFromEndpoint(endpoint) + if err != nil { + t.Fatalf("Error fetching environment: %v", err) + } + + log.Printf("Environment fetched from endpoint: %s", env) + + if !strings.EqualFold(env, "QA") { + log.Printf("Skipping test as the environment is not QA (found: %s)", env) + t.Skip("Skipping test because environment is not QA") + } + id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) name := id email := strings.ToLower(id) + "@harness.io" diff --git a/internal/service/platform/usergroup/usergroup_test.go b/internal/service/platform/usergroup/usergroup_test.go index 365fa020c..052e745da 100644 --- a/internal/service/platform/usergroup/usergroup_test.go +++ b/internal/service/platform/usergroup/usergroup_test.go @@ -2,6 +2,10 @@ package usergroup_test import ( "fmt" + "log" + "net/url" + "os" + "strings" "testing" "time" @@ -15,6 +19,25 @@ import ( "github.com/stretchr/testify/require" ) +func fetchEnvironmentFromEndpoint(endpoint string) (string, error) { + + parsedURL, err := url.Parse(endpoint) + if err != nil { + return "", fmt.Errorf("failed to parse endpoint URL: %w", err) + } + + hostParts := strings.Split(parsedURL.Hostname(), ".") + if len(hostParts) < 2 { + return "", fmt.Errorf("unexpected URL format: %s", parsedURL.Hostname()) + } + + env := hostParts[0] + + log.Printf("Fetched environment: %s", env) + + return env, nil +} + func TestAccResourceUserGroup(t *testing.T) { id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) @@ -127,6 +150,23 @@ func TestOrgResourceUserGroup(t *testing.T) { } func TestAccResourceUserGroup_emails(t *testing.T) { + endpoint := os.Getenv("HARNESS_ENDPOINT") + + if endpoint == "" { + t.Fatal("HARNESS_ENDPOINT environment variable is not set") + } + + env, err := fetchEnvironmentFromEndpoint(endpoint) + if err != nil { + t.Fatalf("Error fetching environment: %v", err) + } + + log.Printf("Environment fetched from endpoint: %s", env) + + if !strings.EqualFold(env, "QA") { + log.Printf("Skipping test as the environment is not QA (found: %s)", env) + t.Skip("Skipping test because environment is not QA") + } id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) name := id @@ -144,7 +184,7 @@ func TestAccResourceUserGroup_emails(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "id", id), resource.TestCheckResourceAttr(resourceName, "name", name), resource.TestCheckResourceAttr(resourceName, "user_emails.#", "1"), - //resource.TestCheckResourceAttr(resourceName, "user_emails.0", "admin_delegate@harnessioprivate.testinator.com"), + //resource.TestCheckResourceAttr(resourceName, "user_emails.0", "admin_pl@harnessioprivate.testinator.com"), //resource.TestCheckResourceAttr(resourceName, "user_emails.1", "vikas.maddukuri@harness.io"), //resource.TestCheckResourceAttr(resourceName, "user_emails.2", "arkajyoti.mukherjee@harness.io"), //resource.TestCheckResourceAttr(resourceName, "user_emails.3", "mankrit.singh@harness.io"), @@ -156,7 +196,7 @@ func TestAccResourceUserGroup_emails(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "id", id), resource.TestCheckResourceAttr(resourceName, "name", updatedName), resource.TestCheckResourceAttr(resourceName, "user_emails.#", "1"), - //resource.TestCheckResourceAttr(resourceName, "user_emails.0", "admin_delegate@harnessioprivate.testinator.com"), + //resource.TestCheckResourceAttr(resourceName, "user_emails.0", "admin_pl@harnessioprivate.testinator.com"), //resource.TestCheckResourceAttr(resourceName, "user_emails.1", "vikas.maddukuri@harness.io"), //resource.TestCheckResourceAttr(resourceName, "user_emails.2", "arkajyoti.mukherjee@harness.io"), //resource.TestCheckResourceAttr(resourceName, "user_emails.3", "mankrit.singh@harness.io"), @@ -222,6 +262,23 @@ func TestAccResourceUserGroup_userIds(t *testing.T) { } func TestProjectResourceUserGroup_emails(t *testing.T) { + endpoint := os.Getenv("HARNESS_ENDPOINT") + + if endpoint == "" { + t.Fatal("HARNESS_ENDPOINT environment variable is not set") + } + + env, err := fetchEnvironmentFromEndpoint(endpoint) + if err != nil { + t.Fatalf("Error fetching environment: %v", err) + } + + log.Printf("Environment fetched from endpoint: %s", env) + + if !strings.EqualFold(env, "QA") { + log.Printf("Skipping test as the environment is not QA (found: %s)", env) + t.Skip("Skipping test because environment is not QA") + } id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) name := id @@ -239,7 +296,7 @@ func TestProjectResourceUserGroup_emails(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "id", id), resource.TestCheckResourceAttr(resourceName, "name", name), resource.TestCheckResourceAttr(resourceName, "user_emails.#", "1"), - resource.TestCheckResourceAttr(resourceName, "user_emails.0", "admin_delegate@harnessioprivate.testinator.com"), + resource.TestCheckResourceAttr(resourceName, "user_emails.0", "admin_pl@harnessioprivate.testinator.com"), ), }, { @@ -248,7 +305,7 @@ func TestProjectResourceUserGroup_emails(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "id", id), resource.TestCheckResourceAttr(resourceName, "name", updatedName), resource.TestCheckResourceAttr(resourceName, "user_emails.#", "1"), - resource.TestCheckResourceAttr(resourceName, "user_emails.0", "admin_delegate@harnessioprivate.testinator.com"), + resource.TestCheckResourceAttr(resourceName, "user_emails.0", "admin_pl@harnessioprivate.testinator.com"), ), }, { @@ -264,6 +321,24 @@ func TestProjectResourceUserGroup_emails(t *testing.T) { func TestOrgResourceUserGroup_emails(t *testing.T) { + endpoint := os.Getenv("HARNESS_ENDPOINT") + + if endpoint == "" { + t.Fatal("HARNESS_ENDPOINT environment variable is not set") + } + + env, err := fetchEnvironmentFromEndpoint(endpoint) + if err != nil { + t.Fatalf("Error fetching environment: %v", err) + } + + log.Printf("Environment fetched from endpoint: %s", env) + + if !strings.EqualFold(env, "QA") { + log.Printf("Skipping test as the environment is not QA (found: %s)", env) + t.Skip("Skipping test because environment is not QA") + } + id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) name := id updatedName := fmt.Sprintf("%s_updated", name) @@ -280,7 +355,7 @@ func TestOrgResourceUserGroup_emails(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "id", id), resource.TestCheckResourceAttr(resourceName, "name", name), resource.TestCheckResourceAttr(resourceName, "user_emails.#", "1"), - resource.TestCheckResourceAttr(resourceName, "user_emails.0", "admin_delegate@harnessioprivate.testinator.com"), + resource.TestCheckResourceAttr(resourceName, "user_emails.0", "admin_pl@harnessioprivate.testinator.com"), ), }, { @@ -289,7 +364,7 @@ func TestOrgResourceUserGroup_emails(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "id", id), resource.TestCheckResourceAttr(resourceName, "name", updatedName), resource.TestCheckResourceAttr(resourceName, "user_emails.#", "1"), - resource.TestCheckResourceAttr(resourceName, "user_emails.0", "admin_delegate@harnessioprivate.testinator.com"), + resource.TestCheckResourceAttr(resourceName, "user_emails.0", "admin_pl@harnessioprivate.testinator.com"), ), }, { @@ -502,7 +577,7 @@ func testAccResourceUserGroup_emails(id string, name string) string { name = "%[2]s" linked_sso_id = "linked_sso_id" externally_managed = false - user_emails = ["admin_delegate@harnessioprivate.testinator.com"] + user_emails = ["admin_pl@harnessioprivate.testinator.com"] notification_configs { type = "SLACK" slack_webhook_url = "https://google.com" @@ -584,7 +659,7 @@ func testProjectResourceUserGroup_emails(id string, name string) string { project_id = harness_platform_project.test.id linked_sso_id = "linked_sso_id" externally_managed = false - user_emails = ["admin_delegate@harnessioprivate.testinator.com"] + user_emails = ["admin_pl@harnessioprivate.testinator.com"] notification_configs { type = "SLACK" slack_webhook_url = "https://google.com" @@ -624,7 +699,7 @@ func testOrgResourceUserGroup_emails(id string, name string) string { org_id = harness_platform_organization.test.id linked_sso_id = "linked_sso_id" externally_managed = false - user_emails = ["admin_delegate@harnessioprivate.testinator.com"] + user_emails = ["admin_pl@harnessioprivate.testinator.com"] notification_configs { type = "SLACK" slack_webhook_url = "https://google.com"