Skip to content

Commit

Permalink
CDPCP-11067 Fix resource name in aws cred and iam acc test (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
daszabo authored Jun 5, 2024
1 parent 780f3d6 commit 2662f65
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 54 deletions.
56 changes: 3 additions & 53 deletions resources/environments/resource_aws_credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package environments_test
import (
"context"
"fmt"
"os"
"testing"

"github.com/cloudera/terraform-provider-cdp/cdp-sdk-go/gen/environments/models"
Expand Down Expand Up @@ -41,9 +42,7 @@ func TestAccAwsCredential_basic(t *testing.T) {
{
Config: utils.Concat(
cdpacctest.TestAccCdpProviderConfig(),
cdpacctest.TestAccAwsProviderConfig(),
testAccAwsCrossAccountRoleConfig(rName),
testAccAwsCredentialConfig(rName, "aws_iam_role.cdp_cross_account_role.arn")),
testAccAwsCredentialConfig(rName, os.Getenv(AwsXAccRoleArn))),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", rName),
resource.TestCheckResourceAttr(resourceName, "credential_name", rName),
Expand Down Expand Up @@ -83,9 +82,7 @@ func TestAccAwsCredential_withDescription(t *testing.T) {
{
Config: utils.Concat(
cdpacctest.TestAccCdpProviderConfig(),
cdpacctest.TestAccAwsProviderConfig(),
testAccAwsCrossAccountRoleConfig(rName),
testAccAwsCredentialConfigWithDescription(rName, "aws_iam_role.cdp_cross_account_role.arn", rName)),
testAccAwsCredentialConfigWithDescription(rName, os.Getenv(AwsXAccRoleArn), rName)),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "id", rName),
resource.TestCheckResourceAttr(resourceName, "credential_name", rName),
Expand Down Expand Up @@ -128,53 +125,6 @@ resource "cdp_environments_aws_credential" "test" {
`, rName, roleArn, description)
}

func testAccAwsCrossAccountRoleConfig(rName string) string {
return fmt.Sprintf(`
data "cdp_environments_aws_credential_prerequisites" "credential_prerequisites" {}
# TODO: Replace this with minimal policy?
data "http" "cdp_cross_account_account_policy_doc" {
url = "https://raw.githubusercontent.com/hortonworks/cloudbreak/master/cloud-aws-common/src/main/resources/definitions/aws-cb-policy.json"
}
data "aws_iam_policy_document" "cdp_cross_account_assume_role_policy_doc" {
version = "2012-10-17"
statement {
actions = ["sts:AssumeRole"]
effect = "Allow"
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${data.cdp_environments_aws_credential_prerequisites.credential_prerequisites.account_id}:root"]
}
condition {
test = "StringEquals"
variable = "sts:ExternalId"
values = ["${data.cdp_environments_aws_credential_prerequisites.credential_prerequisites.external_id}"]
}
}
}
resource "aws_iam_policy" "cdp_cross_account_policy" {
name = %[1]q
policy = data.http.cdp_cross_account_account_policy_doc.response_body
}
resource "aws_iam_role" "cdp_cross_account_role" {
name = %[1]q
assume_role_policy = data.aws_iam_policy_document.cdp_cross_account_assume_role_policy_doc.json
}
resource "aws_iam_role_policy_attachment" "cdp_cross_account_policy_attachment" {
role = aws_iam_role.cdp_cross_account_role.name
policy_arn = aws_iam_policy.cdp_cross_account_policy.arn
}
`, rName)
}

// testAccCheckAwsCredentialExists queries the API and retrieves the matching AwsCredential via the passed in pointer.
func testAccCheckAwsCredentialExists(resourceName string, credential *models.Credential) resource.TestCheckFunc {
return func(s *terraform.State) error {
Expand Down
6 changes: 5 additions & 1 deletion resources/iam/resource_machine_user_group_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ func TestAccIamMachineUserGroupAssignment_basic(t *testing.T) {

func testAccIamMachineUserGroupAssignmentConfig(rName string, grName string) string {
return fmt.Sprintf(`
resource "cdp_iam_group" "test_group" {
group_name = %[2]q
}
resource "cdp_iam_machine_user_group_assignment" "test" {
machine_user = %[1]q
group = %[2]q
group = cdp_iam_group.test_group.group_name
}
`, rName, grName)
}
Expand Down

0 comments on commit 2662f65

Please sign in to comment.