github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/builtin/providers/aws/resource_aws_iam_saml_provider_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/aws/aws-sdk-go/aws"
     8  	"github.com/aws/aws-sdk-go/service/iam"
     9  	"github.com/hashicorp/terraform/helper/resource"
    10  	"github.com/hashicorp/terraform/terraform"
    11  )
    12  
    13  func TestAccAWSIAMSamlProvider_basic(t *testing.T) {
    14  	resource.Test(t, resource.TestCase{
    15  		PreCheck:     func() { testAccPreCheck(t) },
    16  		Providers:    testAccProviders,
    17  		CheckDestroy: testAccCheckIAMSamlProviderDestroy,
    18  		Steps: []resource.TestStep{
    19  			resource.TestStep{
    20  				Config: testAccIAMSamlProviderConfig,
    21  				Check: resource.ComposeTestCheckFunc(
    22  					testAccCheckIAMSamlProvider("aws_iam_saml_provider.salesforce"),
    23  				),
    24  			},
    25  			resource.TestStep{
    26  				Config: testAccIAMSamlProviderConfigUpdate,
    27  				Check: resource.ComposeTestCheckFunc(
    28  					testAccCheckIAMSamlProvider("aws_iam_saml_provider.salesforce"),
    29  				),
    30  			},
    31  		},
    32  	})
    33  }
    34  
    35  func testAccCheckIAMSamlProviderDestroy(s *terraform.State) error {
    36  	if len(s.RootModule().Resources) > 0 {
    37  		return fmt.Errorf("Expected all resources to be gone, but found: %#v", s.RootModule().Resources)
    38  	}
    39  
    40  	return nil
    41  }
    42  
    43  func testAccCheckIAMSamlProvider(id string) resource.TestCheckFunc {
    44  	return func(s *terraform.State) error {
    45  		rs, ok := s.RootModule().Resources[id]
    46  		if !ok {
    47  			return fmt.Errorf("Not Found: %s", id)
    48  		}
    49  
    50  		if rs.Primary.ID == "" {
    51  			return fmt.Errorf("No ID is set")
    52  		}
    53  
    54  		iamconn := testAccProvider.Meta().(*AWSClient).iamconn
    55  		_, err := iamconn.GetSAMLProvider(&iam.GetSAMLProviderInput{
    56  			SAMLProviderArn: aws.String(rs.Primary.ID),
    57  		})
    58  
    59  		if err != nil {
    60  			return err
    61  		}
    62  
    63  		return nil
    64  	}
    65  }
    66  
    67  const testAccIAMSamlProviderConfig = `
    68  resource "aws_iam_saml_provider" "salesforce" {
    69      name = "tf-salesforce-test"
    70      saml_metadata_document = "${file("./test-fixtures/saml-metadata.xml")}"
    71  }
    72  `
    73  
    74  const testAccIAMSamlProviderConfigUpdate = `
    75  resource "aws_iam_saml_provider" "salesforce" {
    76      name = "tf-salesforce-test"
    77      saml_metadata_document = "${file("./test-fixtures/saml-metadata-modified.xml")}"
    78  }
    79  `