Skip to content

Commit

Permalink
merge epic into branch
Browse files Browse the repository at this point in the history
  • Loading branch information
DayS1eeper committed Jun 16, 2022
2 parents 3b69c2d + 39a0650 commit 2c636cc
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 23 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ scalr_workspace_run_schedule
- `scalr_policy_group`: remove environments and workspaces as includes ([#125](https://github.com/Scalr/terraform-provider-scalr/pull/125))
- `scalr_variable`: updated the confusing error for multi-scope variables ([#119](https://github.com/Scalr/terraform-provider-scalr/pull/119))

### Added
- **New resource:** `scalr_provider_configuration` ([#137](https://github.com/Scalr/terraform-provider-scalr/pull/137))

## [1.0.0-rc28] - 2022-04-01

### Added
Expand Down
25 changes: 21 additions & 4 deletions docs/resources/scalr_provider_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ resource "scalr_provider_configuration" "azurerm" {
}
```

Scalr provider:

```hcl
resource "scalr_provider_configuration" "scalr" {
name = "scalr"
account_id = "acc-xxxxxxxxx"
scalr {
hostname = "scalr.host.example.com"
token = "my-scalr-token"
}
}
```

Other providers:

```hcl
Expand Down Expand Up @@ -85,21 +98,25 @@ resource "scalr_provider_configuration" "kubernetes" {
* `account_id` - (Required) The account that owns the variable, specified as an ID, in the format.
* `name` - (Required) The name of a Scalr provider configuration. This field is unique for the account.
* `export_shell_variables` - (Optional) Export provider variables into the run environment. This option is available only for built in providers.
* `aws` - (Optional) Settings for the aws provider configuraiton. Exactly one of the following attributes must be set: `aws`, `google`, `azurerm`, `custom`.
* `aws` - (Optional) Settings for the aws provider configuraiton. Exactly one of the following attributes must be set: `aws`, `google`, `azurerm`, `scalr`, `custom`.
The `aws` block supports the following:
* `secret_key` - (Optional) AWS secret key.
* `access_key` - (Optional) AWS access key.
* `google` - (Optional) Settings for the google provider configuraiton. Exactly one of the following attributes must be set: `aws`, `google`, `azurerm`, `custom`.
* `google` - (Optional) Settings for the google provider configuraiton. Exactly one of the following attributes must be set: `aws`, `google`, `azurerm`, `scalr`, `custom`.
The `google` block supports the following:
* `project` - (Optional) The default project to manage resources in. If another project is specified on a resource, it will take precedence.
* `credentials` - (Optional) Either the path to or the contents of a service account key file in JSON format. You can manage key files using the Cloud Console. If not provided, the application default credentials will be used.
* `azurerm` - (Optional) Settings for the azurerm provider configuraiton. Exactly one of the following attributes must be set: `aws`, `google`, `azurerm`, `custom`.
* `azurerm` - (Optional) Settings for the azurerm provider configuraiton. Exactly one of the following attributes must be set: `aws`, `google`, `azurerm`, `scalr`, `custom`.
The `azurerm` block supports the following:
* `client_id` - (Optional) The Client ID which should be used.
* `client_secret` - (Optional) The Client Secret which should be used.
* `subscription_id` - (Optional) The Subscription ID which should be used.
* `tenant_id` - (Optional) The Tenant ID should be used.
* `custom` - (Optional) Settings for the provider configuraiton that does not have first class scalr support. Exactly one of the following attributes must be set: `aws`, `google`, `azurerm`, `custom`.
* `scalr` - (Optional) Settings for the Scalr provider configuraiton. Exactly one of the following attributes must be set: `aws`, `google`, `azurerm`, `scalr`, `custom`.
The `scalr` block supports the following:
* `hostname` - (Optional) The Scalr hostname which should be used.
* `token` - (Optional) The Scalr Token which should be used.
* `custom` - (Optional) Settings for the provider configuraiton that does not have first class scalr support. Exactly one of the following attributes must be set: `aws`, `google`, `azurerm`, `scalr`, `custom`.
The `custom` block supports the following:
* `provider_name` - (Required) The name of a Terraform provider.
* `argument` - (Required) The provider configuration argument.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require (
github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce
github.com/hashicorp/terraform-plugin-sdk v1.17.2
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734
github.com/scalr/go-scalr v0.0.0-20220608155411-6e6a912ba37d
github.com/scalr/go-scalr v0.0.0-20220616132445-6d6376eb80a6
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ github.com/posener/complete v1.2.1 h1:LrvDIY//XNo65Lq84G/akBuMGlawHvGBABv8f/ZN6D
github.com/posener/complete v1.2.1/go.mod h1:6gapUrK/U1TAN7ciCoNRIdVC5sbdBTUh1DKN0g6uH7E=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/scalr/go-scalr v0.0.0-20220608155411-6e6a912ba37d h1:dzPuWZ+8AFEcflC/N9LBVhxdHjLrpQT0t88ch9ztb84=
github.com/scalr/go-scalr v0.0.0-20220608155411-6e6a912ba37d/go.mod h1:xMnwfer9UxugeNITZjTpQBwQ/4bw6/JdyDLpGdmyorE=
github.com/scalr/go-scalr v0.0.0-20220616132445-6d6376eb80a6 h1:W6E+G4BwY70FyqD69eYtjxsuvUjoBBC45uSjUG+taA4=
github.com/scalr/go-scalr v0.0.0-20220616132445-6d6376eb80a6/go.mod h1:xMnwfer9UxugeNITZjTpQBwQ/4bw6/JdyDLpGdmyorE=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
Expand Down
48 changes: 42 additions & 6 deletions scalr/resource_scalr_provider_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func resourceScalrProviderConfiguration() *schema.Resource {
CustomizeDiff: customdiff.All(
func(d *schema.ResourceDiff, meta interface{}) error {
changedProviderNames := 0
providerNameAttrs := []string{"aws", "google", "azurerm", "custom"}
providerNameAttrs := []string{"aws", "google", "azurerm", "scalr", "custom"}
for _, providerNameAttr := range providerNameAttrs {
if d.HasChange(providerNameAttr) {
changedProviderNames += 1
Expand Down Expand Up @@ -58,7 +58,7 @@ func resourceScalrProviderConfiguration() *schema.Resource {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
ExactlyOneOf: []string{"google", "azurerm", "custom"},
ExactlyOneOf: []string{"google", "azurerm", "scalr", "custom"},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"account_type": {
Expand Down Expand Up @@ -97,7 +97,7 @@ func resourceScalrProviderConfiguration() *schema.Resource {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
ExactlyOneOf: []string{"aws", "azurerm", "custom"},
ExactlyOneOf: []string{"aws", "azurerm", "scalr", "custom"},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"project": {
Expand All @@ -116,7 +116,7 @@ func resourceScalrProviderConfiguration() *schema.Resource {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
ExactlyOneOf: []string{"aws", "google", "custom"},
ExactlyOneOf: []string{"aws", "google", "scalr", "custom"},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"client_id": {
Expand All @@ -139,11 +139,30 @@ func resourceScalrProviderConfiguration() *schema.Resource {
},
},
},
"scalr": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
ExactlyOneOf: []string{"aws", "google", "azurerm", "custom"},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"hostname": {
Type: schema.TypeString,
Required: true,
},
"token": {
Type: schema.TypeString,
Required: true,
Sensitive: true,
},
},
},
},
"custom": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
ExactlyOneOf: []string{"aws", "google", "azurerm"},
ExactlyOneOf: []string{"aws", "google", "azurerm", "scalr"},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"provider_name": {
Expand Down Expand Up @@ -257,6 +276,10 @@ func resourceScalrProviderConfigurationCreate(d *schema.ResourceData, meta inter
if v, ok := d.GetOk("azurerm.0.tenant_id"); ok {
configurationOptions.AzurermTenantId = scalr.String(v.(string))
}
} else if _, ok := d.GetOk("scalr"); ok {
configurationOptions.ProviderName = scalr.String("scalr")
configurationOptions.ScalrHostname = scalr.String(d.Get("scalr.0.hostname").(string))
configurationOptions.ScalrToken = scalr.String(d.Get("scalr.0.token").(string))

} else if v, ok := d.GetOk("custom"); ok {
custom := v.([]interface{})[0].(map[string]interface{})
Expand Down Expand Up @@ -355,6 +378,16 @@ func resourceScalrProviderConfigurationRead(d *schema.ResourceData, meta interfa
}

d.Set("google", []map[string]interface{}{google})
case "scalr":
stateScalrParameters := d.Get("scalr").([]interface{})[0].(map[string]interface{})
stateToken := stateScalrParameters["token"].(string)

d.Set("scalr", []map[string]interface{}{
{
"hostname": providerConfiguration.ScalrHostname,
"token": stateToken,
},
})
case "azurerm":
stateAzurermParameters := d.Get("azurerm").([]interface{})[0].(map[string]interface{})
stateClientSecret := stateAzurermParameters["client_secret"].(string)
Expand Down Expand Up @@ -408,7 +441,7 @@ func resourceScalrProviderConfigurationUpdate(d *schema.ResourceData, meta inter

id := d.Id()

if d.HasChange("name") || d.HasChange("export_shell_variables") || d.HasChange("aws") || d.HasChange("google") || d.HasChange("azurerm") {
if d.HasChange("name") || d.HasChange("export_shell_variables") || d.HasChange("aws") || d.HasChange("google") || d.HasChange("azurerm") || d.HasChange("scalr") || d.HasChange("custom") {
configurationOptions := scalr.ProviderConfigurationUpdateOptions{
Name: scalr.String(d.Get("name").(string)),
ExportShellVariables: scalr.Bool(d.Get("export_shell_variables").(bool)),
Expand Down Expand Up @@ -453,6 +486,9 @@ func resourceScalrProviderConfigurationUpdate(d *schema.ResourceData, meta inter
if v, ok := d.GetOk("google.0.project"); ok {
configurationOptions.GoogleProject = scalr.String(v.(string))
}
} else if _, ok := d.GetOk("scalr"); ok {
configurationOptions.ScalrHostname = scalr.String(d.Get("scalr.0.hostname").(string))
configurationOptions.ScalrToken = scalr.String(d.Get("scalr.0.token").(string))
} else if _, ok := d.GetOk("azurerm"); ok {
if v, ok := d.GetOk("azurerm.0.client_id"); ok {
configurationOptions.AzurermClientId = scalr.String(v.(string))
Expand Down
Loading

0 comments on commit 2c636cc

Please sign in to comment.