Skip to content

Commit

Permalink
Merge branch 'develop' into fix/SCALRCORE-25049
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanMytsko committed Apr 28, 2023
2 parents fd50e5d + f70c14f commit 6a99c4d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- `data.scalr_module_version`: if there are several module versions with the same version, select the version that has the 'is-root-module' flag set to true. ([#229](https://github.com/Scalr/terraform-provider-scalr/pull/229))
- `data.scalr_role`: do not require default value for `account_id` to be present in run environment when searching for a system role. ([#241](https://github.com/Scalr/terraform-provider-scalr/pull/241))
- `scalr_provider_configuration`: fix terraform import ([#244](https://github.com/Scalr/terraform-provider-scalr/pull/244))

### Required
Expand Down
2 changes: 1 addition & 1 deletion scalr/data_source_scalr_role.go
Expand Up @@ -32,7 +32,7 @@ func dataSourceScalrRole() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Computed: true,
DefaultFunc: scalrAccountIDDefaultFunc,
DefaultFunc: scalrAccountIDOptionalDefaultFunc,
},

"is_system": {
Expand Down
10 changes: 10 additions & 0 deletions scalr/helpers.go
Expand Up @@ -174,6 +174,8 @@ func getDefaultScalrAccountID() (string, bool) {
return "", false
}

// scalrAccountIDDefaultFunc is a schema.SchemaDefaultFunc that returns default account id.
// If account info is not present, the error is returned.
func scalrAccountIDDefaultFunc() (interface{}, error) {
if accID, ok := getDefaultScalrAccountID(); ok {
return accID, nil
Expand All @@ -182,3 +184,11 @@ func scalrAccountIDDefaultFunc() (interface{}, error) {
"\nIf you are using Scalr Provider for local runs, please set the attribute in resources explicitly," +
"\nor export `SCALR_ACCOUNT_ID` environment variable prior the run.")
}

// scalrAccountIDOptionalDefaultFunc is a schema.SchemaDefaultFunc that returns default account id
// or an empty (string) value, if account info is not present.
// Never returns non-nil error.
func scalrAccountIDOptionalDefaultFunc() (interface{}, error) {
accID, _ := getDefaultScalrAccountID()
return accID, nil
}
10 changes: 1 addition & 9 deletions scalr/resource_scalr_webhook.go
Expand Up @@ -131,7 +131,7 @@ func resourceScalrWebhook() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Computed: true,
DefaultFunc: webhookAccountIDDefaultFunc,
DefaultFunc: scalrAccountIDOptionalDefaultFunc,
ForceNew: true,
},

Expand Down Expand Up @@ -174,14 +174,6 @@ func forceRecreateIf() schema.CustomizeDiffFunc {
}
}

// webhookAccountIDDefaultFunc returns default account id, if present.
// It won't return an error, as `account_id` is optional and computed
// for old-style webhooks.
func webhookAccountIDDefaultFunc() (interface{}, error) {
accID, _ := getDefaultScalrAccountID()
return accID, nil
}

// remove after https://scalr-labs.atlassian.net/browse/SCALRCORE-16234
func getResourceScope(ctx context.Context, scalrClient *scalr.Client, workspaceID string, environmentID string) (*scalr.Workspace, *scalr.Environment, *scalr.Account, error) {

Expand Down

0 comments on commit 6a99c4d

Please sign in to comment.