Skip to content

Commit 7559021

Browse files
feat(provider): add profile name from configuration file support (scaleway#875)
* feat(provider): add profile name from configuration file support * feat(provider): enhance error handling * chore(provider): add section about new profile feature usage * fix(provider): fix condition * Apply suggestions from code review Co-authored-by: jaime Bernabe <[email protected]>
1 parent fbf973d commit 7559021

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

docs/index.md

+32
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,38 @@ If it fails to detect credentials inline, or in the environment, Terraform will
178178
You can optionally specify a different location with `SCW_CONFIG_PATH` environment variable.
179179
You can find more information about this configuration [in the documentation](https://github.com/scaleway/scaleway-sdk-go/blob/master/scw/README.md#scaleway-config).
180180

181+
This method also supports a `profile` configuration:
182+
183+
Example:
184+
185+
If your shared configuration file contains:
186+
187+
```yaml
188+
profiles:
189+
myProfile:
190+
access_key: xxxxxxxxxxxxxxxxxxxx
191+
secret_key: xxxxxxxx-xxx-xxxx-xxxx-xxxxxxxxxxx
192+
default_organization_id: xxxxxxxx-xxx-xxxx-xxxx-xxxxxxxxxxx
193+
default_project_id: xxxxxxxx-xxx-xxxx-xxxx-xxxxxxxxxxx
194+
default_zone: fr-par-2
195+
default_region: fr-par
196+
api_url: https://api.scaleway.com
197+
insecure: false
198+
```
199+
200+
You can invoke and use this profile in the provider declaration:
201+
202+
```hcl
203+
provider "scaleway" {
204+
alias = "p2"
205+
profile = "myProfile"
206+
}
207+
208+
resource "scaleway_instance_ip" "server_ip" {
209+
provider = scaleway.p2
210+
}
211+
```
212+
181213
## Arguments Reference
182214

183215
In addition to [generic provider arguments](https://www.terraform.io/docs/configuration/providers.html) (e.g. `alias` and `version`), the following arguments are supported in the Scaleway provider block:

scaleway/provider.go

+11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ func Provider(config *ProviderConfig) plugin.ProviderFunc {
3939
Description: "The Scaleway secret Key.",
4040
ValidateFunc: validationUUID(),
4141
},
42+
"profile": {
43+
Type: schema.TypeString,
44+
Optional: true, // To allow user to use `access_key`, `secret_key`, `project_id`...
45+
Description: "The Scaleway profile to use.",
46+
},
4247
"project_id": {
4348
Type: schema.TypeString,
4449
Optional: true, // To allow user to use organization instead of project
@@ -230,6 +235,12 @@ func loadProfile(d *schema.ResourceData) (*scw.Profile, error) {
230235

231236
providerProfile := &scw.Profile{}
232237
if d != nil {
238+
if profileName, exist := d.GetOk("profile"); exist {
239+
profileFromConfig, err := config.GetProfile(profileName.(string))
240+
if err == nil {
241+
providerProfile = profileFromConfig
242+
}
243+
}
233244
if accessKey, exist := d.GetOk("access_key"); exist {
234245
providerProfile.AccessKey = scw.StringPtr(accessKey.(string))
235246
}

0 commit comments

Comments
 (0)