Skip to content

Commit

Permalink
Merge pull request #62 from Scalr/bugfix/SCALRCORE-19198
Browse files Browse the repository at this point in the history
SCALRCORE-19198 > Fix BC with scalr_variable resource
  • Loading branch information
emocharnik committed May 25, 2021
2 parents 1f111b9 + a2d199b commit 0888f39
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- `scalr_variable`: make `environment_id`, `workspace_id` and `account_id` attributes computable ([#60](https://github.com/Scalr/terraform-provider-scalr/pull/62))

### Required

- scalr server >= `8.0.1-beta.20210407`

## [1.0.0-rc15] - 2021-04-22

### Added
Expand Down
25 changes: 16 additions & 9 deletions scalr/resource_scalr_variable.go
Expand Up @@ -34,16 +34,16 @@ func resourceScalrVariable() *schema.Resource {
// Reject any changes for variable scope
var scopeAttributes = []string{"workspace_id", "environment_id", "account_id"}

notChangedFields := 0
scopeIsAlreadySet := false
for _, scope := range scopeAttributes {
old, new := d.GetChange(scope)

if old.(string) == "" || old.(string) == new.(string) {
notChangedFields++
old, _ := d.GetChange(scope)
if old.(string) != "" {
scopeIsAlreadySet = true
break
}
}

if notChangedFields < len(scopeAttributes) {
if scopeIsAlreadySet && (d.HasChange("workspace_id") || d.HasChange("environment_id") || d.HasChange("account_id")) {
return fmt.Errorf("Error changing scope for variable %s: scope is immutable attribute", d.Id())
}

Expand Down Expand Up @@ -116,16 +116,19 @@ func resourceScalrVariable() *schema.Resource {
"workspace_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},

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

"account_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
}
Expand Down Expand Up @@ -218,9 +221,13 @@ func resourceScalrVariableRead(d *schema.ResourceData, meta interface{}) error {

if variable.Workspace != nil {
d.Set("workspace_id", variable.Workspace.ID)
} else if variable.Environment != nil {
d.Set("workspace_id", nil)
} else if variable.Account != nil {
}

if variable.Environment != nil {
d.Set("environment_id", variable.Environment.ID)
}

if variable.Account != nil {
d.Set("account_id", variable.Account.ID)
}

Expand Down

0 comments on commit 0888f39

Please sign in to comment.