2016-08-15 23:43:24 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
2017-03-27 15:32:31 +02:00
|
|
|
"github.com/aws/aws-sdk-go/service/sts"
|
2016-08-15 23:43:24 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
)
|
|
|
|
|
|
|
|
func dataSourceAwsCallerIdentity() *schema.Resource {
|
|
|
|
return &schema.Resource{
|
|
|
|
Read: dataSourceAwsCallerIdentityRead,
|
|
|
|
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
"account_id": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
2017-03-27 15:32:31 +02:00
|
|
|
|
|
|
|
"arn": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
"user_id": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
2016-08-15 23:43:24 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func dataSourceAwsCallerIdentityRead(d *schema.ResourceData, meta interface{}) error {
|
2017-03-27 15:32:31 +02:00
|
|
|
client := meta.(*AWSClient).stsconn
|
|
|
|
|
|
|
|
res, err := client.GetCallerIdentity(&sts.GetCallerIdentityInput{})
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error getting Caller Identity: %v", err)
|
|
|
|
}
|
2016-08-15 23:43:24 +02:00
|
|
|
|
2017-04-04 16:41:30 +02:00
|
|
|
log.Printf("[DEBUG] Received Caller Identity: %s", res)
|
2016-08-15 23:43:24 +02:00
|
|
|
|
2017-04-04 16:41:30 +02:00
|
|
|
d.SetId(time.Now().UTC().String())
|
2017-04-03 20:10:57 +02:00
|
|
|
d.Set("account_id", res.Account)
|
|
|
|
d.Set("arn", res.Arn)
|
|
|
|
d.Set("user_id", res.UserId)
|
2016-08-15 23:43:24 +02:00
|
|
|
return nil
|
|
|
|
}
|