github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/aws/data_source_aws_canonical_user_id.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "log" 6 7 "github.com/aws/aws-sdk-go/aws" 8 "github.com/aws/aws-sdk-go/service/s3" 9 "github.com/hashicorp/terraform/helper/schema" 10 ) 11 12 func dataSourceAwsCanonicalUserId() *schema.Resource { 13 return &schema.Resource{ 14 Read: dataSourceAwsCanonicalUserIdRead, 15 16 Schema: map[string]*schema.Schema{ 17 "id": { 18 Type: schema.TypeString, 19 Computed: true, 20 }, 21 "display_name": { 22 Type: schema.TypeString, 23 Computed: true, 24 }, 25 }, 26 } 27 } 28 29 func dataSourceAwsCanonicalUserIdRead(d *schema.ResourceData, meta interface{}) error { 30 conn := meta.(*AWSClient).s3conn 31 32 log.Printf("[DEBUG] Listing S3 buckets.") 33 34 req := &s3.ListBucketsInput{} 35 resp, err := conn.ListBuckets(req) 36 if err != nil { 37 return err 38 } 39 if resp == nil || resp.Owner == nil { 40 return fmt.Errorf("no canonical user ID found") 41 } 42 43 d.SetId(aws.StringValue(resp.Owner.ID)) 44 d.Set("id", resp.Owner.ID) 45 d.Set("display_name", resp.Owner.DisplayName) 46 47 return nil 48 }