mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-08 15:13:56 -06:00
8159731c91
Allows users from govcloud and other regions (aws-cn) to now use the following resources correctly: ``` - data "aws_billing_service_account" - data "aws_elb_service_account" - resource "aws_cloudfront_origin_access_identity" - resource "aws_ecs_service" - resource "aws_iam_saml_provider" - resource "aws_lambda_permission" - resource "aws_sns_topic_policy" ```
101 lines
2.4 KiB
Go
101 lines
2.4 KiB
Go
package aws
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
|
"github.com/aws/aws-sdk-go/service/iam"
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccAWSIAMSamlProvider_basic(t *testing.T) {
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckIAMSamlProviderDestroy,
|
|
Steps: []resource.TestStep{
|
|
{
|
|
Config: testAccIAMSamlProviderConfig,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckIAMSamlProvider("aws_iam_saml_provider.salesforce"),
|
|
),
|
|
},
|
|
{
|
|
Config: testAccIAMSamlProviderConfigUpdate,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckIAMSamlProvider("aws_iam_saml_provider.salesforce"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckIAMSamlProviderDestroy(s *terraform.State) error {
|
|
iamconn := testAccProvider.Meta().(*AWSClient).iamconn
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
if rs.Type != "aws_iam_saml_provider" {
|
|
continue
|
|
}
|
|
|
|
input := &iam.GetSAMLProviderInput{
|
|
SAMLProviderArn: aws.String(rs.Primary.ID),
|
|
}
|
|
out, err := iamconn.GetSAMLProvider(input)
|
|
if err != nil {
|
|
if iamerr, ok := err.(awserr.Error); ok && iamerr.Code() == "NoSuchEntity" {
|
|
// none found, that's good
|
|
return nil
|
|
}
|
|
return fmt.Errorf("Error reading IAM SAML Provider, out: %s, err: %s", out, err)
|
|
}
|
|
|
|
if out != nil {
|
|
return fmt.Errorf("Found IAM SAML Provider, expected none: %s", out)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func testAccCheckIAMSamlProvider(id string) resource.TestCheckFunc {
|
|
return func(s *terraform.State) error {
|
|
rs, ok := s.RootModule().Resources[id]
|
|
if !ok {
|
|
return fmt.Errorf("Not Found: %s", id)
|
|
}
|
|
|
|
if rs.Primary.ID == "" {
|
|
return fmt.Errorf("No ID is set")
|
|
}
|
|
|
|
iamconn := testAccProvider.Meta().(*AWSClient).iamconn
|
|
_, err := iamconn.GetSAMLProvider(&iam.GetSAMLProviderInput{
|
|
SAMLProviderArn: aws.String(rs.Primary.ID),
|
|
})
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
const testAccIAMSamlProviderConfig = `
|
|
resource "aws_iam_saml_provider" "salesforce" {
|
|
name = "tf-salesforce-test"
|
|
saml_metadata_document = "${file("./test-fixtures/saml-metadata.xml")}"
|
|
}
|
|
`
|
|
|
|
const testAccIAMSamlProviderConfigUpdate = `
|
|
resource "aws_iam_saml_provider" "salesforce" {
|
|
name = "tf-salesforce-test"
|
|
saml_metadata_document = "${file("./test-fixtures/saml-metadata-modified.xml")}"
|
|
}
|
|
`
|