Skip to content

Commit

Permalink
Elasticsearch: Use 'acctest.PreCheckIAMServiceLinkedRole' in 'testAcc…
Browse files Browse the repository at this point in the history
…PreCheckIAMServiceLinkedRole'.
  • Loading branch information
ewbankkit committed Aug 29, 2022
1 parent 2dceb28 commit a382aab
Showing 1 changed file with 1 addition and 31 deletions.
32 changes: 1 addition & 31 deletions internal/service/elasticsearch/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package elasticsearch_test
import (
"fmt"
"regexp"
"strings"
"testing"
"time"

Expand All @@ -12,7 +11,6 @@ import (
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider"
elasticsearch "github.com/aws/aws-sdk-go/service/elasticsearchservice"
"github.com/aws/aws-sdk-go/service/elb"
"github.com/aws/aws-sdk-go/service/iam"
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
Expand Down Expand Up @@ -1761,35 +1759,7 @@ func testAccGetValidStartAtTime(t *testing.T, timeUntilStart string) string {
}

func testAccPreCheckIAMServiceLinkedRole(t *testing.T) {
conn := acctest.Provider.Meta().(*conns.AWSClient).IAMConn
dnsSuffix := acctest.Provider.Meta().(*conns.AWSClient).DNSSuffix

input := &iam.ListRolesInput{
PathPrefix: aws.String("/aws-service-role/es."),
}

var role *iam.Role
err := conn.ListRolesPages(input, func(page *iam.ListRolesOutput, lastPage bool) bool {
for _, r := range page.Roles {
if strings.HasPrefix(aws.StringValue(r.Path), "/aws-service-role/es.") {
role = r
}
}

return !lastPage
})

if acctest.PreCheckSkipError(err) {
t.Skipf("skipping acceptance testing: %s", err)
}

if err != nil {
t.Fatalf("unexpected PreCheck error: %s", err)
}

if role == nil {
t.Fatalf("missing IAM Service Linked Role (es.%s), please create it in the AWS account and retry", dnsSuffix)
}
acctest.PreCheckIAMServiceLinkedRole(t, "/aws-service-role/es")
}

func testAccDomainConfig_basic(rName string) string {
Expand Down

0 comments on commit a382aab

Please sign in to comment.