github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/resource_aws_iam_openid_connect_provider.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 6 "github.com/aws/aws-sdk-go/aws" 7 "github.com/aws/aws-sdk-go/aws/awserr" 8 "github.com/aws/aws-sdk-go/service/iam" 9 10 "github.com/hashicorp/terraform/helper/schema" 11 ) 12 13 func resourceAwsIamOpenIDConnectProvider() *schema.Resource { 14 return &schema.Resource{ 15 Create: resourceAwsIamOpenIDConnectProviderCreate, 16 Read: resourceAwsIamOpenIDConnectProviderRead, 17 Update: resourceAwsIamOpenIDConnectProviderUpdate, 18 Delete: resourceAwsIamOpenIDConnectProviderDelete, 19 Exists: resourceAwsIamOpenIDConnectProviderExists, 20 Importer: &schema.ResourceImporter{ 21 State: schema.ImportStatePassthrough, 22 }, 23 24 Schema: map[string]*schema.Schema{ 25 "arn": &schema.Schema{ 26 Type: schema.TypeString, 27 Computed: true, 28 }, 29 "url": &schema.Schema{ 30 Type: schema.TypeString, 31 Computed: false, 32 Required: true, 33 ForceNew: true, 34 ValidateFunc: validateOpenIdURL, 35 DiffSuppressFunc: suppressOpenIdURL, 36 }, 37 "client_id_list": &schema.Schema{ 38 Elem: &schema.Schema{Type: schema.TypeString}, 39 Type: schema.TypeList, 40 Required: true, 41 ForceNew: true, 42 }, 43 "thumbprint_list": &schema.Schema{ 44 Elem: &schema.Schema{Type: schema.TypeString}, 45 Type: schema.TypeList, 46 Required: true, 47 }, 48 }, 49 } 50 } 51 52 func resourceAwsIamOpenIDConnectProviderCreate(d *schema.ResourceData, meta interface{}) error { 53 iamconn := meta.(*AWSClient).iamconn 54 55 input := &iam.CreateOpenIDConnectProviderInput{ 56 Url: aws.String(d.Get("url").(string)), 57 ClientIDList: expandStringList(d.Get("client_id_list").([]interface{})), 58 ThumbprintList: expandStringList(d.Get("thumbprint_list").([]interface{})), 59 } 60 61 out, err := iamconn.CreateOpenIDConnectProvider(input) 62 if err != nil { 63 return err 64 } 65 66 d.SetId(*out.OpenIDConnectProviderArn) 67 68 return resourceAwsIamOpenIDConnectProviderRead(d, meta) 69 } 70 71 func resourceAwsIamOpenIDConnectProviderRead(d *schema.ResourceData, meta interface{}) error { 72 iamconn := meta.(*AWSClient).iamconn 73 74 input := &iam.GetOpenIDConnectProviderInput{ 75 OpenIDConnectProviderArn: aws.String(d.Id()), 76 } 77 out, err := iamconn.GetOpenIDConnectProvider(input) 78 if err != nil { 79 return err 80 } 81 82 d.Set("arn", d.Id()) 83 d.Set("url", out.Url) 84 d.Set("client_id_list", flattenStringList(out.ClientIDList)) 85 d.Set("thumbprint_list", flattenStringList(out.ThumbprintList)) 86 87 return nil 88 } 89 90 func resourceAwsIamOpenIDConnectProviderUpdate(d *schema.ResourceData, meta interface{}) error { 91 iamconn := meta.(*AWSClient).iamconn 92 93 if d.HasChange("thumbprint_list") { 94 input := &iam.UpdateOpenIDConnectProviderThumbprintInput{ 95 OpenIDConnectProviderArn: aws.String(d.Id()), 96 ThumbprintList: expandStringList(d.Get("thumbprint_list").([]interface{})), 97 } 98 99 _, err := iamconn.UpdateOpenIDConnectProviderThumbprint(input) 100 if err != nil { 101 return err 102 } 103 } 104 105 return resourceAwsIamOpenIDConnectProviderRead(d, meta) 106 } 107 108 func resourceAwsIamOpenIDConnectProviderDelete(d *schema.ResourceData, meta interface{}) error { 109 iamconn := meta.(*AWSClient).iamconn 110 111 input := &iam.DeleteOpenIDConnectProviderInput{ 112 OpenIDConnectProviderArn: aws.String(d.Id()), 113 } 114 _, err := iamconn.DeleteOpenIDConnectProvider(input) 115 116 if err != nil { 117 if err, ok := err.(awserr.Error); ok && err.Code() == "NoSuchEntity" { 118 return nil 119 } 120 return fmt.Errorf("Error deleting platform application %s", err) 121 } 122 123 return nil 124 } 125 126 func resourceAwsIamOpenIDConnectProviderExists(d *schema.ResourceData, meta interface{}) (bool, error) { 127 iamconn := meta.(*AWSClient).iamconn 128 129 input := &iam.GetOpenIDConnectProviderInput{ 130 OpenIDConnectProviderArn: aws.String(d.Id()), 131 } 132 _, err := iamconn.GetOpenIDConnectProvider(input) 133 if err != nil { 134 if err, ok := err.(awserr.Error); ok && err.Code() == "NoSuchEntity" { 135 return false, nil 136 } 137 return true, err 138 } 139 140 return true, nil 141 }