forked from hashicorp/terraform-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice_account_data_source.go
81 lines (72 loc) · 2.59 KB
/
service_account_data_source.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package cloudtrail
import (
"fmt"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
)
// See http://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-supported-regions.html
// See https://docs.aws.amazon.com/govcloud-us/latest/ug-east/verifying-cloudtrail.html
// See https://docs.aws.amazon.com/govcloud-us/latest/ug-west/verifying-cloudtrail.html
var ServiceAccountPerRegionMap = map[string]string{
endpoints.AfSouth1RegionID: "525921808201",
endpoints.ApEast1RegionID: "119688915426",
endpoints.ApNortheast1RegionID: "216624486486",
endpoints.ApNortheast2RegionID: "492519147666",
endpoints.ApNortheast3RegionID: "765225791966",
endpoints.ApSouth1RegionID: "977081816279",
endpoints.ApSoutheast1RegionID: "903692715234",
endpoints.ApSoutheast2RegionID: "284668455005",
endpoints.ApSoutheast3RegionID: "069019280451",
endpoints.CaCentral1RegionID: "819402241893",
endpoints.CnNorth1RegionID: "193415116832",
endpoints.CnNorthwest1RegionID: "681348832753",
endpoints.EuCentral1RegionID: "035351147821",
endpoints.EuNorth1RegionID: "829690693026",
endpoints.EuSouth1RegionID: "669305197877",
endpoints.EuWest1RegionID: "859597730677",
endpoints.EuWest2RegionID: "282025262664",
endpoints.EuWest3RegionID: "262312530599",
endpoints.MeSouth1RegionID: "034638983726",
endpoints.SaEast1RegionID: "814480443879",
endpoints.UsEast1RegionID: "086441151436",
endpoints.UsEast2RegionID: "475085895292",
endpoints.UsGovEast1RegionID: "608710470296",
endpoints.UsGovWest1RegionID: "608710470296",
endpoints.UsWest1RegionID: "388731089494",
endpoints.UsWest2RegionID: "113285607260",
}
func DataSourceServiceAccount() *schema.Resource {
return &schema.Resource{
Read: dataSourceServiceAccountRead,
Schema: map[string]*schema.Schema{
"region": {
Type: schema.TypeString,
Optional: true,
},
"arn": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceServiceAccountRead(d *schema.ResourceData, meta interface{}) error {
region := meta.(*conns.AWSClient).Region
if v, ok := d.GetOk("region"); ok {
region = v.(string)
}
if accid, ok := ServiceAccountPerRegionMap[region]; ok {
d.SetId(accid)
arn := arn.ARN{
Partition: meta.(*conns.AWSClient).Partition,
Service: "iam",
AccountID: accid,
Resource: "root",
}.String()
d.Set("arn", arn)
return nil
}
return fmt.Errorf("Unknown region (%q)", region)
}