Skip to content

Commit

Permalink
SCALRCORE-18895 changes after CR
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanMytsko committed Jun 15, 2021
1 parent 10a9a41 commit 547e72e
Show file tree
Hide file tree
Showing 9 changed files with 491 additions and 15 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/terraform-provider-scalr.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

424 changes: 424 additions & 0 deletions covprofile

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/resources/scalr_variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ resource "scalr_variable" "example" {

* `key` - (Required) Key of the variable.
* `value` - (Required) Variable value.
* `category` - (Required) Indicates if this is a Terraform or environment variable. Allowed values are `terraform` or `shell`.
* `hcl` - (Optional) Set (true/false) to configure the variable as a string of HCL code. Has no effect for `category = "env"` variables. Default `false`.
* `category` - (Required) Indicates if this is a Terraform or shell variable. Allowed values are `terraform` or `shell`.
* `hcl` - (Optional) Set (true/false) to configure the variable as a string of HCL code. Has no effect for `category = "shell"` variables. Default `false`.
* `sensitive` - (Optional) Set (true/false) to configure as sensitive. Sensitive variable values are not visible after being set. Default `false`.
* `final` - (Optional) Set (true/false) to configure as final. Indicates whether the variable can be overridden on a lower scope down the Scalr organizational model. Default `false`.
* `force` - (Optional) Set (true/false) to configure as force. Allows creating final variables on higher scope, even if the same variable exists on lower scope (lower is to be deleted). Default `false`.
Expand Down
5 changes: 2 additions & 3 deletions scalr/resource_scalr_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ func resourceScalrVariable() *schema.Resource {
SchemaVersion: 2,
StateUpgraders: []schema.StateUpgrader{
{
Type: resourceScalrVariableResourceV1().CoreConfigSchema().ImpliedType(),
Type: resourceScalrVariableResourceV0().CoreConfigSchema().ImpliedType(),
Upgrade: resourceScalrVariableStateUpgradeV0,
Version: 0,
},
{
Type: resourceScalrVariableResourceV0().CoreConfigSchema().ImpliedType(),
Type: resourceScalrVariableResourceV1().CoreConfigSchema().ImpliedType(),
Upgrade: resourceScalrVariableStateUpgradeV1,
Version: 1,
},
Expand All @@ -88,7 +88,6 @@ func resourceScalrVariable() *schema.Resource {
ValidateFunc: validation.StringInSlice(
[]string{
string(scalr.CategoryEnv),
string(scalr.CategoryShell),
string(scalr.CategoryTerraform),
},
false,
Expand Down
38 changes: 30 additions & 8 deletions scalr/resource_scalr_variable_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,44 @@ func resourceScalrVariableResourceV1() *schema.Resource {
Default: false,
},

"final": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"force": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

"workspace_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Optional: true,
Computed: true,
},

"environment_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},

"account_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
}
}

func resourceScalrVariableStateUpgradeV1(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {

var_category := rawState["category"].(string)

if var_category == string(scalr.CategoryEnv) {
var_category = string(scalr.CategoryShell)
varCategory := rawState["category"].(string)
if varCategory == string(scalr.CategoryEnv) {
varCategory = string(scalr.CategoryShell)
}
rawState["category"] = var_category
rawState["category"] = varCategory
return rawState, nil
}
4 changes: 2 additions & 2 deletions scalr/resource_scalr_variable_migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestResourceScalrVariableStateUpgradeV0(t *testing.T) {
assertCorrectState(t, err, actual, expected)
}

func testResourceScalrVariableStateDataCategoryV2() map[string]interface{} {
func testResourceScalrVariableStateDataCategoryV1() map[string]interface{} {
return map[string]interface{}{
"category": "env",
}
Expand All @@ -47,6 +47,6 @@ func testResourceScalrVariableStateDataV2() map[string]interface{} {

func TestResourceScalrVariableStateUpgradeV1(t *testing.T) {
expected := testResourceScalrVariableStateDataV2()
actual, err := resourceScalrVariableStateUpgradeV1(testResourceScalrVariableStateDataCategoryV2(), nil)
actual, err := resourceScalrVariableStateUpgradeV1(testResourceScalrVariableStateDataCategoryV1(), nil)
assertCorrectState(t, err, actual, expected)
}

0 comments on commit 547e72e

Please sign in to comment.