Skip to content

Commit

Permalink
CDPCP-13608 Modify dw acceptance tests
Browse files Browse the repository at this point in the history
Use the proper settings provided by the jenkins infra to run the dw acceptance
tests as part of release testing.
  • Loading branch information
tevesz committed Dec 19, 2024
1 parent 93e5f30 commit 3b81ba3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
19 changes: 11 additions & 8 deletions cdpacctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,27 @@ provider "cdp" {
}

type AwsProvider struct {
profile string
region string
accessKeyID string
secretAccessKey string
region string
}

func NewAwsProvider(profile, region string) *AwsProvider {
func NewAwsProvider(accessKeyID, secretAccessKey, region string) *AwsProvider {
return &AwsProvider{
profile: profile,
region: region,
accessKeyID: accessKeyID,
secretAccessKey: secretAccessKey,
region: region,
}
}

func TestAccAwsProviderConfig(p *AwsProvider) string {
return fmt.Sprintf(`
provider "aws" {
profile = %[1]q
region = %[2]q
access_key = %[1]q
secret_key = %[2]q
region = %[3]q
}
`, p.profile, p.region)
`, p.accessKeyID, p.secretAccessKey, p.region)
}

// CheckCrn Checks whether the value is set and is a properly formatted CRN
Expand Down
24 changes: 14 additions & 10 deletions resources/dw/resource_dw_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ import (
)

const (
AwsProfile = "ACCEPTANCETEST_AWS_PROFILE"
AwsAccessKeyID = "ACCEPTANCETEST_AWS_ACCESS_KEY_ID"
AwsSecretAccessKey = "ACCEPTANCETEST_AWS_SECRET_ACCESS_KEY"
AwsXAccRoleArn = "ACCEPTANCETEST_AWS_X_ACC_ROLE_ARN"
AwsRegion = "ACCEPTANCETEST_AWS_REGION"
AwsPublicKeyId = "ACCEPTANCETEST_AWS_PUBLIC_KEY_ID"
AwsPublicKeyID = "ACCEPTANCETEST_AWS_PUBLIC_KEY_ID"
AwsInstanceProfile = "ACCEPTANCETEST_AWS_INSTANCE_PROFILE"
AwsStorageLocationBase = "ACCEPTANCETEST_AWS_STORAGE_LOCATION_BASE"
AwsVpcId = "ACCEPTANCETEST_AWS_VPC_ID"
Expand Down Expand Up @@ -64,17 +65,20 @@ type awsDataLakeTestParameters struct {

func AwsDataLakePreCheck(t *testing.T) {
errMsg := "AWS CDW Terraform acceptance testing requires environment variable %s to be set"
if _, ok := os.LookupEnv(AwsProfile); !ok {
t.Fatalf(errMsg, AwsProfile)
if _, ok := os.LookupEnv(AwsAccessKeyID); !ok {
t.Fatalf(errMsg, AwsAccessKeyID)
}
if _, ok := os.LookupEnv(AwsSecretAccessKey); !ok {
t.Fatalf(errMsg, AwsSecretAccessKey)
}
if _, ok := os.LookupEnv(AwsXAccRoleArn); !ok {
t.Fatalf(errMsg, AwsXAccRoleArn)
}
if _, ok := os.LookupEnv(AwsRegion); !ok {
t.Fatalf(errMsg, AwsRegion)
}
if _, ok := os.LookupEnv(AwsPublicKeyId); !ok {
t.Fatalf(errMsg, AwsPublicKeyId)
if _, ok := os.LookupEnv(AwsPublicKeyID); !ok {
t.Fatalf(errMsg, AwsPublicKeyID)
}
if _, ok := os.LookupEnv(AwsInstanceProfile); !ok {
t.Fatalf(errMsg, AwsInstanceProfile)
Expand Down Expand Up @@ -103,8 +107,8 @@ func AwsDataLakePreCheck(t *testing.T) {
}

func PreCheck(t *testing.T) {
if _, ok := os.LookupEnv(AwsProfile); !ok {
t.Skipf("Terraform acceptance testing requires environment variable %s to be set", AwsProfile)
if _, ok := os.LookupEnv(AwsSecretAccessKey); !ok {
t.Skipf("Terraform acceptance testing requires environment variable %s to be set", AwsSecretAccessKey)
}

if os.Getenv(cdp.CdpProfileEnvVar) == "" && os.Getenv(cdp.CdpAccessKeyIdEnvVar) == "" {
Expand All @@ -121,15 +125,15 @@ func PreCheck(t *testing.T) {
func TestAccDwCluster_Basic(t *testing.T) {
PreCheck(t)
credName := acctest.RandomWithPrefix(cdpacctest.ResourcePrefix)
awsProvider := cdpacctest.NewAwsProvider(os.Getenv(AwsProfile), os.Getenv(AwsRegion))
awsProvider := cdpacctest.NewAwsProvider(os.Getenv(AwsAccessKeyID), os.Getenv(AwsSecretAccessKey), os.Getenv(AwsRegion))
accountParams := cdpacctest.NewAwsAccountCredentials(cdpacctest.RandomShortWithPrefix(cdpacctest.ResourcePrefix)).
WithAccountID(t).
WithExternalID(t).
WithPolicy(t)
envParams := awsEnvironmentTestParameters{
Name: cdpacctest.RandomShortWithPrefix(cdpacctest.ResourcePrefix),
Region: os.Getenv(AwsRegion),
PublicKeyId: os.Getenv(AwsPublicKeyId),
PublicKeyId: os.Getenv(AwsPublicKeyID),
InstanceProfile: os.Getenv(AwsInstanceProfile),
StorageLocationBase: os.Getenv(AwsStorageLocationBase),
VpcId: os.Getenv(AwsVpcId),
Expand Down

0 comments on commit 3b81ba3

Please sign in to comment.