github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/builtin/providers/aws/resource_aws_iam_saml_provider.go (about) 1 package aws 2 3 import ( 4 "time" 5 6 "github.com/aws/aws-sdk-go/aws" 7 "github.com/aws/aws-sdk-go/service/iam" 8 9 "github.com/hashicorp/terraform/helper/schema" 10 ) 11 12 func resourceAwsIamSamlProvider() *schema.Resource { 13 return &schema.Resource{ 14 Create: resourceAwsIamSamlProviderCreate, 15 Read: resourceAwsIamSamlProviderRead, 16 Update: resourceAwsIamSamlProviderUpdate, 17 Delete: resourceAwsIamSamlProviderDelete, 18 19 Schema: map[string]*schema.Schema{ 20 "arn": &schema.Schema{ 21 Type: schema.TypeString, 22 Computed: true, 23 }, 24 "valid_until": &schema.Schema{ 25 Type: schema.TypeString, 26 Computed: true, 27 }, 28 "name": &schema.Schema{ 29 Type: schema.TypeString, 30 Required: true, 31 ForceNew: true, 32 }, 33 "saml_metadata_document": &schema.Schema{ 34 Type: schema.TypeString, 35 Required: true, 36 }, 37 }, 38 } 39 } 40 41 func resourceAwsIamSamlProviderCreate(d *schema.ResourceData, meta interface{}) error { 42 iamconn := meta.(*AWSClient).iamconn 43 44 input := &iam.CreateSAMLProviderInput{ 45 Name: aws.String(d.Get("name").(string)), 46 SAMLMetadataDocument: aws.String(d.Get("saml_metadata_document").(string)), 47 } 48 49 out, err := iamconn.CreateSAMLProvider(input) 50 if err != nil { 51 return err 52 } 53 54 d.SetId(*out.SAMLProviderArn) 55 56 return resourceAwsIamSamlProviderRead(d, meta) 57 } 58 59 func resourceAwsIamSamlProviderRead(d *schema.ResourceData, meta interface{}) error { 60 iamconn := meta.(*AWSClient).iamconn 61 62 input := &iam.GetSAMLProviderInput{ 63 SAMLProviderArn: aws.String(d.Id()), 64 } 65 out, err := iamconn.GetSAMLProvider(input) 66 if err != nil { 67 return err 68 } 69 70 validUntil := out.ValidUntil.Format(time.RFC1123) 71 d.Set("arn", d.Id()) 72 d.Set("valid_until", validUntil) 73 d.Set("saml_metadata_document", *out.SAMLMetadataDocument) 74 75 return nil 76 } 77 78 func resourceAwsIamSamlProviderUpdate(d *schema.ResourceData, meta interface{}) error { 79 iamconn := meta.(*AWSClient).iamconn 80 81 input := &iam.UpdateSAMLProviderInput{ 82 SAMLProviderArn: aws.String(d.Id()), 83 SAMLMetadataDocument: aws.String(d.Get("saml_metadata_document").(string)), 84 } 85 _, err := iamconn.UpdateSAMLProvider(input) 86 if err != nil { 87 return err 88 } 89 90 return resourceAwsIamSamlProviderRead(d, meta) 91 } 92 93 func resourceAwsIamSamlProviderDelete(d *schema.ResourceData, meta interface{}) error { 94 iamconn := meta.(*AWSClient).iamconn 95 96 input := &iam.DeleteSAMLProviderInput{ 97 SAMLProviderArn: aws.String(d.Id()), 98 } 99 _, err := iamconn.DeleteSAMLProvider(input) 100 101 return err 102 }