Skip to content

Commit

Permalink
clean up construction of tf string
Browse files Browse the repository at this point in the history
  • Loading branch information
helenfufu committed Nov 20, 2024
1 parent c2d1520 commit 05d47e4
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions vault/resource_aws_auth_backend_sts_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package vault
import (
"fmt"
"strconv"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
Expand Down Expand Up @@ -165,30 +166,27 @@ func testAccAWSAuthBackendSTSRoleCheck_attrs(backend, accountID, stsRole string)
}

func testAccAWSAuthBackendSTSRoleConfig_basic(backend, accountID, stsRole, externalID string) string {
roleResource := fmt.Sprintf(`
resource "vault_aws_auth_backend_sts_role" "role" {
backend = vault_auth_backend.aws.path
account_id = "%s"
sts_role = "%s"
}
`, accountID, stsRole)
backendResource := fmt.Sprintf(`
resource "vault_auth_backend" "aws" {
type = "aws"
path = "%s"
}`, backend)

roleResourceOptionalFields := ""
if externalID != "" {
roleResource = fmt.Sprintf(`
roleResourceOptionalFields += fmt.Sprintf(`
external_id = "%s"`, externalID)
}

roleResource := fmt.Sprintf(`
resource "vault_aws_auth_backend_sts_role" "role" {
backend = vault_auth_backend.aws.path
account_id = "%s"
sts_role = "%s"
external_id = "%s"
sts_role = "%s"%s
}
`, accountID, stsRole, externalID)
}
`, accountID, stsRole, roleResourceOptionalFields)

return fmt.Sprintf(`
resource "vault_auth_backend" "aws" {
type = "aws"
path = "%s"
}
%s
`, backend, roleResource)
resources := []string{backendResource, roleResource}

return strings.Join(resources, "\n")
}

0 comments on commit 05d47e4

Please sign in to comment.