Skip to content

Commit 5998bb2

Browse files
authored
Merge pull request #10 from philips-software/feature/region-environment
Region and environment
2 parents c321aa7 + ec46cca commit 5998bb2

File tree

7 files changed

+92
-15
lines changed

7 files changed

+92
-15
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ require (
88
github.com/hashicorp/hcl/v2 v2.3.0 // indirect
99
github.com/hashicorp/terraform-config-inspect v0.0.0-20191212124732-c6ae6269b9d7 // indirect
1010
github.com/hashicorp/terraform-plugin-sdk v1.12.0
11-
github.com/philips-software/go-hsdp-api v0.17.1-0.20200615232637-d9626340de79
11+
github.com/philips-software/go-hsdp-api v0.19.1-0.20200701073942-567142717405
1212
github.com/pkg/errors v0.9.1
13+
github.com/stretchr/testify v1.5.1
1314
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 // indirect
1415
)
1516

go.sum

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ cloud.google.com/go v0.45.1 h1:lRi0CHyU+ytlvylOlFKKq0af6JncuyoRh1J+QJBqQx0=
77
cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc=
88
cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
99
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
10+
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
1011
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
1112
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
1213
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
@@ -183,8 +184,12 @@ github.com/mitchellh/reflectwalk v1.0.1 h1:FVzMWA5RllMAKIdUSC8mdWo3XtwoecrH79BY7
183184
github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
184185
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
185186
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
186-
github.com/philips-software/go-hsdp-api v0.17.1-0.20200615232637-d9626340de79 h1:zBdT2QfXOH140R111h3SFvkq5OwZJGftIAVEW5r2LUo=
187-
github.com/philips-software/go-hsdp-api v0.17.1-0.20200615232637-d9626340de79/go.mod h1:/OadmzPbhz0+4m6b+3LIjudljiTigrvyTsQJLd70Y8c=
187+
github.com/pelletier/go-toml v1.8.0 h1:Keo9qb7iRJs2voHvunFtuuYFsbWeOBh8/P9v/kVMFtw=
188+
github.com/pelletier/go-toml v1.8.0/go.mod h1:D6yutnOGMveHEPV7VQOuvI/gXY61bv+9bAOTRnLElKs=
189+
github.com/philips-software/go-hsdp-api v0.19.0 h1:ygdMrGSUokYQ1QaImxK8DPFipgXWNtiUSjpZnpX2i0Y=
190+
github.com/philips-software/go-hsdp-api v0.19.0/go.mod h1:9+2MQAUHTHJtQmTCiHwLalgrMRVin019Zo0/3Qf5Zc4=
191+
github.com/philips-software/go-hsdp-api v0.19.1-0.20200701073942-567142717405 h1:4yKlYeT9iGOgZWS39wm57IllAz0zIQ24tTG6ucj9K+0=
192+
github.com/philips-software/go-hsdp-api v0.19.1-0.20200701073942-567142717405/go.mod h1:9+2MQAUHTHJtQmTCiHwLalgrMRVin019Zo0/3Qf5Zc4=
188193
github.com/philips-software/go-hsdp-signer v1.3.0 h1:Si1voDE/GHzthmxpasPdntbu8aUW6EYJfI6gHVf7BCc=
189194
github.com/philips-software/go-hsdp-signer v1.3.0/go.mod h1:/QehZ/+Aks2t1TFpjhF/7ZSB8PJIIJHzLc03rOqwLw0=
190195
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
@@ -297,8 +302,8 @@ golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBn
297302
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
298303
golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
299304
golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
300-
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
301-
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
305+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
306+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
302307
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
303308
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
304309
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
@@ -334,6 +339,8 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
334339
gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
335340
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
336341
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
342+
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
343+
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
337344
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
338345
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
339346
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

hsdp/config.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package hsdp
33
import (
44
"github.com/hashicorp/go-retryablehttp"
55
"github.com/philips-software/go-hsdp-api/cartel"
6+
"github.com/philips-software/go-hsdp-api/config"
67
"github.com/philips-software/go-hsdp-api/credentials"
78
"github.com/philips-software/go-hsdp-api/iam"
89
"net/http"
@@ -18,6 +19,8 @@ type Config struct {
1819
CartelNoTLS bool
1920
CartelSkipVerify bool
2021
RetryMax int
22+
Region string
23+
Environment string
2124

2225
iamClient *iam.Client
2326
cartelClient *cartel.Client
@@ -63,6 +66,20 @@ func (c *Config) setupIAMClient() {
6366
standardClient = retryClient.StandardClient()
6467
}
6568
c.iamClient = nil
69+
// Auto config
70+
if c.Environment != "" && c.Region != "" {
71+
ac, err := config.New(config.WithRegion(c.Region), config.WithEnv(c.Environment))
72+
if err == nil {
73+
iamService := ac.Service("iam")
74+
if url, err := iamService.String("iam_url"); err == nil && c.IAMURL == "" {
75+
c.IAMURL = url
76+
}
77+
if url, err := iamService.String("idm_url"); err == nil && c.IDMURL == "" {
78+
c.IDMURL = url
79+
}
80+
}
81+
}
82+
6683
client, err := iam.NewClient(standardClient, &c.Config)
6784
if err != nil {
6885
c.iamClientErr = err
@@ -92,6 +109,14 @@ func (c *Config) setupS3CredsClient() {
92109
c.credsClientErr = c.iamClientErr
93110
return
94111
}
112+
if c.Environment != "" && c.Region != "" {
113+
ac, err := config.New(config.WithRegion(c.Region), config.WithEnv(c.Environment))
114+
if err == nil {
115+
if url, err := ac.Service("s3creds").String("url"); err == nil && c.S3CredsURL == "" {
116+
c.S3CredsURL = url
117+
}
118+
}
119+
}
95120
client, err := credentials.NewClient(c.iamClient, &credentials.Config{
96121
BaseURL: c.S3CredsURL,
97122
Debug: c.Debug,
@@ -111,13 +136,21 @@ func (c *Config) setupCartelClient() {
111136
client, err := cartel.NewClient(nil, cartel.Config{
112137
Host: c.CartelHost,
113138
Token: c.CartelToken,
114-
Secret: []byte(c.CartelSecret),
139+
Secret: c.CartelSecret,
115140
NoTLS: c.CartelNoTLS,
116141
SkipVerify: c.CartelSkipVerify,
117142
Debug: c.Debug,
118143
DebugLog: c.DebugLog,
119144
})
120-
145+
// Auto config
146+
if c.Environment != "" && c.Region != "" {
147+
ac, err := config.New(config.WithRegion(c.Region), config.WithEnv(c.Environment))
148+
if err == nil {
149+
if host, err := ac.Service("cartel").String("host"); err == nil && c.CartelHost == "" {
150+
c.CartelHost = host
151+
}
152+
}
153+
}
121154
if err != nil {
122155
c.cartelClient = nil
123156
c.cartelClientErr = err

hsdp/config_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package hsdp
2+
3+
import (
4+
"github.com/philips-software/go-hsdp-api/iam"
5+
"github.com/stretchr/testify/assert"
6+
"testing"
7+
)
8+
9+
func TestConfig(t *testing.T) {
10+
c := &Config{}
11+
12+
c.Region = "us-east"
13+
c.Environment = "client-test"
14+
c.OrgAdminUsername = "foo"
15+
c.OrgAdminPassword = "bar"
16+
17+
c.setupIAMClient()
18+
19+
assert.Equal(t, iam.ErrNotAuthorized, c.iamClientErr)
20+
}

hsdp/diff_suppress_funcs.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ func suppressCaseDiffs(k, old, new string, d *schema.ResourceData) bool {
2626
}
2727
return false
2828
}
29+
30+
func suppressOnID(k, old, new string, d *schema.ResourceData) bool {
31+
if d.Id() != "" {
32+
return true
33+
}
34+
return false
35+
}

hsdp/provider.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ import (
99
func Provider(build string) terraform.ResourceProvider {
1010
return &schema.Provider{
1111
Schema: map[string]*schema.Schema{
12+
"region": {
13+
Type: schema.TypeString,
14+
Optional: true,
15+
RequiredWith: []string{"environment"},
16+
Description: descriptions["region"],
17+
},
18+
"environment": {
19+
Type: schema.TypeString,
20+
Optional: true,
21+
RequiredWith: []string{"region"},
22+
Description: descriptions["environment"],
23+
},
1224
"iam_url": {
1325
Type: schema.TypeString,
1426
Optional: true,
@@ -90,7 +102,7 @@ func Provider(build string) terraform.ResourceProvider {
90102
"cartel_skip_verify": {
91103
Type: schema.TypeBool,
92104
Optional: true,
93-
Default: false,
105+
Default: true,
94106
Description: descriptions["cartel_skip_verify"],
95107
},
96108
"retry_max": {
@@ -139,6 +151,8 @@ var descriptions map[string]string
139151

140152
func init() {
141153
descriptions = map[string]string{
154+
"region": "The HSDP region to configure for",
155+
"environment": "The HSDP environment to configure for",
142156
"iam_url": "The HSDP IAM instance URL",
143157
"idm_url": "The HSDP IDM instance URL",
144158
"credentials_url": "The HSDP S3 Credentials instance URL",
@@ -163,6 +177,8 @@ func init() {
163177
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
164178
config := &Config{}
165179

180+
config.Region = d.Get("region").(string)
181+
config.Environment = d.Get("environment").(string)
166182
config.IAMURL = d.Get("iam_url").(string)
167183
config.IDMURL = d.Get("idm_url").(string)
168184
config.OAuth2ClientID = d.Get("oauth2_client_id").(string)

hsdp/resource_iam_client.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ func resourceIAMClient() *schema.Resource {
4040
Required: true,
4141
Sensitive: true,
4242
ForceNew: true,
43-
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
44-
if d.Id() != "" {
45-
return true
46-
}
47-
return false
48-
},
4943
},
5044
"description": &schema.Schema{
5145
Type: schema.TypeString,
@@ -165,7 +159,6 @@ func resourceIAMClientRead(d *schema.ResourceData, m interface{}) error {
165159
_ = d.Set("description", cl.Description)
166160
_ = d.Set("name", cl.Name)
167161
_ = d.Set("client_id", cl.ClientID)
168-
_ = d.Set("password", cl.Password)
169162
_ = d.Set("type", cl.Type)
170163
_ = d.Set("application_id", cl.ApplicationID)
171164
_ = d.Set("global_reference_id", cl.GlobalReferenceID)

0 commit comments

Comments
 (0)