-
Notifications
You must be signed in to change notification settings - Fork 26
/
data_source_aviatrix_account.go
80 lines (73 loc) · 1.85 KB
/
data_source_aviatrix_account.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 aviatrix
import (
"log"
"fmt"
"github.com/hashicorp/terraform/helper/schema"
"github.com/AviatrixSystems/go-aviatrix/goaviatrix"
)
func dataSourceAviatrixAccount() *schema.Resource {
return &schema.Resource{
Read: dataSourceAviatrixAccountRead,
Schema: map[string]*schema.Schema {
"account_name": {
Type: schema.TypeString,
Required: true,
},
"account_email": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"cloud_type": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
"aws_account_number": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"aws_iam": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"aws_role_arn": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"aws_role_ec2": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"aws_access_key": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"aws_secret_key": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
},
}
}
func dataSourceAviatrixAccountRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*goaviatrix.Client)
account := &goaviatrix.Account{
AccountName: d.Get("account_name").(string),
}
log.Printf("[INFO] Looking for Aviatrix account: %#v", account)
acc, err := client.GetAccount(account)
if err != nil {
return fmt.Errorf("Aviatrix Account: %s", err)
}
if acc != nil {
d.Set("account_name", acc.AccountName)
d.Set("account_email", acc.AccountEmail)
d.Set("cloud_type", acc.CloudType)
d.Set("aws_account_number", acc.AwsAccountNumber)
d.Set("aws_access_key", acc.AwsAccessKey)
d.Set("aws_secret_key", acc.AwsSecretKey)
d.SetId(acc.AccountName)
} else {
d.SetId("")
}
return nil
}