forked from hashicorp/terraform-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_account_data_source.go
80 lines (71 loc) · 2.57 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
package redshift
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/redshift/latest/mgmt/db-auditing.html#db-auditing-bucket-permissions
// See https://docs.aws.amazon.com/govcloud-us/latest/UserGuide/govcloud-redshift.html
// See https://docs.amazonaws.cn/en_us/redshift/latest/mgmt/db-auditing.html#db-auditing-bucket-permissions
var ServiceAccountPerRegionMap = map[string]string{
endpoints.AfSouth1RegionID: "365689465814",
endpoints.ApEast1RegionID: "313564881002",
endpoints.ApNortheast1RegionID: "404641285394",
endpoints.ApNortheast2RegionID: "760740231472",
endpoints.ApNortheast3RegionID: "090321488786",
endpoints.ApSouth1RegionID: "865932855811",
endpoints.ApSoutheast1RegionID: "361669875840",
endpoints.ApSoutheast2RegionID: "762762565011",
endpoints.CaCentral1RegionID: "907379612154",
endpoints.CnNorth1RegionID: "111890595117",
endpoints.CnNorthwest1RegionID: "660998842044",
endpoints.EuCentral1RegionID: "053454850223",
endpoints.EuNorth1RegionID: "729911121831",
endpoints.EuSouth1RegionID: "945612479654",
endpoints.EuWest1RegionID: "210876761215",
endpoints.EuWest2RegionID: "307160386991",
endpoints.EuWest3RegionID: "915173422425",
endpoints.MeSouth1RegionID: "013126148197",
endpoints.SaEast1RegionID: "075028567923",
endpoints.UsEast1RegionID: "193672423079",
endpoints.UsEast2RegionID: "391106570357",
endpoints.UsGovEast1RegionID: "665727464434",
endpoints.UsGovWest1RegionID: "665727464434",
endpoints.UsWest1RegionID: "262260360010",
endpoints.UsWest2RegionID: "902366379725",
}
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: "user/logs",
}.String()
d.Set("arn", arn)
return nil
}
return fmt.Errorf("Unknown region (%q)", region)
}