-
Notifications
You must be signed in to change notification settings - Fork 23
/
data_source_alks_keys.go
59 lines (50 loc) · 1.23 KB
/
data_source_alks_keys.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
package main
import (
"log"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceAlksKeys() *schema.Resource {
return &schema.Resource{
Read: dataSourceAlksKeysRead,
Schema: map[string]*schema.Schema{
"access_key": {
Type: schema.TypeString,
Computed: true,
},
"secret_key": {
Type: schema.TypeString,
Computed: true,
},
"session_token": {
Type: schema.TypeString,
Computed: true,
},
"account": {
Type: schema.TypeString,
Computed: true,
},
"role": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceAlksKeysRead(d *schema.ResourceData, meta interface{}) error {
log.Printf("[INFO] ALKS Keys Data Source Read")
providerStruct := meta.(*AlksClient)
client := providerStruct.client
resp, err := client.CreateIamSession()
if err != nil {
return err
}
// Return the information to user.
_ = d.Set("access_key", resp.AccessKey)
_ = d.Set("secret_key", resp.SecretKey)
_ = d.Set("session_token", resp.SessionToken)
_ = d.Set("account", client.AccountDetails.Account)
_ = d.Set("role", strings.Split(client.AccountDetails.Role, "/")[0])
d.SetId(client.AccountDetails.Account)
return nil
}