Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(provider): add profile name from configuration file support #875

Merged
merged 9 commits into from
Oct 4, 2021
27 changes: 27 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,33 @@ If it fails to detect credentials inline, or in the environment, Terraform will
You can optionally specify a different location with `SCW_CONFIG_PATH` environment variable.
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).

This method also supports a `profile` configuration:

Example:

If your shared configuration file contains:

```yaml
profiles:
myProfile:
access_key: xxxxxxxxxxxxxxxxxxxx
secret_key: xxxxxxxx-xxx-xxxx-xxxx-xxxxxxxxxxx
default_organization_id: xxxxxxxx-xxx-xxxx-xxxx-xxxxxxxxxxx
default_project_id: xxxxxxxx-xxx-xxxx-xxxx-xxxxxxxxxxx
default_zone: fr-par-1
default_region: fr-par
api_url: https://api.scaleway.com
insecure: false
```

You can invoke and use this profile in the provider declaration:

```hcl
provider "scaleway" {
profile = "myProfile"
}
```

## Arguments Reference

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:
Expand Down
11 changes: 11 additions & 0 deletions scaleway/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ func Provider(config *ProviderConfig) plugin.ProviderFunc {
Description: "The Scaleway secret Key.",
ValidateFunc: validationUUID(),
},
"profile": {
Type: schema.TypeString,
Optional: true, // To allow user to use `access_key`, `secret_key`, `project_id`...
Description: "The Scaleway profile to use.",
},
"project_id": {
Type: schema.TypeString,
Optional: true, // To allow user to use organization instead of project
Expand Down Expand Up @@ -228,6 +233,12 @@ func loadProfile(d *schema.ResourceData) (*scw.Profile, error) {

providerProfile := &scw.Profile{}
if d != nil {
if profileName, exist := d.GetOk("profile"); exist {
profileFromConfig, err := config.GetProfile(profileName.(string))
if err == nil {
providerProfile = profileFromConfig
}
}
if accessKey, exist := d.GetOk("access_key"); exist {
providerProfile.AccessKey = scw.StringPtr(accessKey.(string))
}
Expand Down