Skip to content

Commit

Permalink
SCALRCORE-24000 Added var_files validation
Browse files Browse the repository at this point in the history
  • Loading branch information
petroprotsakh committed Nov 8, 2022
1 parent ecb8e50 commit 47dd991
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `module_verion`: data source: change relation from latest-module-version to module-version ([#181](https://github.com/Scalr/terraform-provider-scalr/pull/181))

### Fixed

- panic when creating workspace with empty var file value ([#191](https://github.com/Scalr/terraform-provider-scalr/pull/191))

## [1.0.0-rc38] - 2022-10-20

### Added
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/scalr_workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ resource "scalr_workspace" "cli-driven" {
* `execution-mode` - (Optional) Which execution mode to use. Valid values are `remote` and `local`. When set to `local`, the workspace will be used for state storage only. Defaults to `remote` (not set, backend default is used).
* `terraform_version` - (Optional) The version of Terraform to use for this workspace. Defaults to the latest available version.
* `working_directory` - (Optional) A relative path that Terraform will be run in. Defaults to the root of the repository `""`.
var_files` - (Optional) A list of paths to the `.tfvars` file(s) to be used as part of the workspace configuration.
* `var_files` - (Optional) A list of paths to the `.tfvars` file(s) to be used as part of the workspace configuration.
* `run_operation_timeout` - (Optional) The number of minutes run operation can be executed before termination. Defaults to `0` (not set, backend default is used).
* `module_version_id` - (Optional) The identifier of a module version in the format `modver-<RANDOM STRING>`. This attribute conflicts with `vcs_provider_id` and `vcs_repo` attributes.
* `agent_pool_id` - (Optional) The identifier of an agent pool in the format `apool-<RANDOM STRING>`.
Expand Down
26 changes: 20 additions & 6 deletions scalr/resource_scalr_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,22 @@ func parseTriggerPrefixDefinitions(vcsRepo map[string]interface{}) ([]string, er
return triggerPrefixes, nil
}

func parseVarFilesDefinitions(d *schema.ResourceData) ([]string, error) {
varFiles := make([]string, 0)

varFileIds := d.Get("var_files").([]interface{})
err := ValidateIDsDefinitions(varFileIds)
if err != nil {
return nil, fmt.Errorf("Got error during parsing var files: %s", err.Error())
}

for _, varFileId := range varFileIds {
varFiles = append(varFiles, varFileId.(string))
}

return varFiles, nil
}

func resourceScalrWorkspaceCreate(d *schema.ResourceData, meta interface{}) error {
scalrClient := meta.(*scalr.Client)

Expand Down Expand Up @@ -390,13 +406,11 @@ func resourceScalrWorkspaceCreate(d *schema.ResourceData, meta interface{}) erro
}
}

if v, ok := d.Get("var_files").([]interface{}); ok {
varFiles := make([]string, 0)
for _, varFile := range v {
varFiles = append(varFiles, varFile.(string))
}
options.VarFiles = varFiles
varFiles, err := parseVarFilesDefinitions(d)
if err != nil {
return err
}
options.VarFiles = varFiles

if tagIDs, ok := d.GetOk("tag_ids"); ok {
tagIDsList := tagIDs.(*schema.Set).List()
Expand Down

0 comments on commit 47dd991

Please sign in to comment.