mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-24 23:46:26 -06:00
3e14f56a96
This data source provides access during configuration to the ID of the AWS account for the connection to AWS. It is primarily useful for interpolating into policy documents, for example when creating the policy for an ELB or ALB access log bucket. This will need revisiting and further testing once the work for AssumeRole is integrated.
41 lines
931 B
Go
41 lines
931 B
Go
package aws
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"time"
|
|
|
|
"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,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func dataSourceAwsCallerIdentityRead(d *schema.ResourceData, meta interface{}) error {
|
|
client := meta.(*AWSClient)
|
|
|
|
log.Printf("[DEBUG] Reading Caller Identity.")
|
|
d.SetId(time.Now().UTC().String())
|
|
|
|
if client.accountid == "" {
|
|
log.Println("[DEBUG] No Account ID available, failing")
|
|
return fmt.Errorf("No AWS Account ID is available to the provider. Please ensure that\n" +
|
|
"skip_requesting_account_id is not set on the AWS provider.")
|
|
}
|
|
|
|
log.Printf("[DEBUG] Setting AWS Account ID to %s.", client.accountid)
|
|
d.Set("account_id", meta.(*AWSClient).accountid)
|
|
|
|
return nil
|
|
}
|