Skip to content

Commit

Permalink
Merge branch 'develop' into feature/SCALRCORE-28287
Browse files Browse the repository at this point in the history
  • Loading branch information
DayS1eeper committed Oct 16, 2023
2 parents 090298b + 0436bb9 commit 80f6ec1
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 10 deletions.
16 changes: 12 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- `scalr_provider_configuration`: Fixed error message if aws credentials type is wrong. ([#275](https://github.com/Scalr/terraform-provider-scalr/pull/275))
- `data.scalr_enviroment`: Added new attribute `default_provider_configurations` ([#279](https://github.com/Scalr/terraform-provider-scalr/pull/279))
- `scalr_workspace`: Added new attribute `vcs-repo.trigger_patterns` ([#282](https://github.com/Scalr/terraform-provider-scalr/pull/282))

## [1.5.0] - 2023-10-13

### Added

- `scalr_vcs_provider`: Added new `draft_pr_runs_enabled` attribute ([#278](https://github.com/Scalr/terraform-provider-scalr/pull/278))
- `scalr_vcs_provider`: new attribute `draft_pr_runs_enabled` ([#278](https://github.com/Scalr/terraform-provider-scalr/pull/278))
- `data.scalr_enviroment`: new attribute `default_provider_configurations` ([#279](https://github.com/Scalr/terraform-provider-scalr/pull/279))
- `data.scalr_provider_configuration`: new attribute `environments` ([#285](https://github.com/Scalr/terraform-provider-scalr/pull/280/files))

### Fixed

- `scalr_provider_configuration`: fixed error message if aws credentials type is wrong ([#275](https://github.com/Scalr/terraform-provider-scalr/pull/275))
- `data.scalr_provider_configuration`: fixed `provider-name` attribute not populating ([#285](https://github.com/Scalr/terraform-provider-scalr/pull/280/files))

## [1.4.0] - 2023-08-11

Expand Down Expand Up @@ -734,7 +741,8 @@ Requires Scalr 8.0.1-beta.20200625 at least

- Initial release.

[Unreleased]: https://github.com/Scalr/terraform-provider-scalr/compare/v1.4.0...HEAD
[Unreleased]: https://github.com/Scalr/terraform-provider-scalr/compare/v1.5.0...HEAD
[1.5.0]: https://github.com/Scalr/terraform-provider-scalr/releases/tag/v1.5.0
[1.4.0]: https://github.com/Scalr/terraform-provider-scalr/releases/tag/v1.4.0
[1.3.0]: https://github.com/Scalr/terraform-provider-scalr/releases/tag/v1.3.0
[1.2.0]: https://github.com/Scalr/terraform-provider-scalr/releases/tag/v1.2.0
Expand Down
4 changes: 4 additions & 0 deletions docs/data-sources/provider_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ data "scalr_provider_configuration" "azure" {
- `id` (String) The provider configuration ID, in the format `pcfg-xxxxxxxxxxx`.
- `name` (String) The name of a Scalr provider configuration.
- `provider_name` (String) The name of a Terraform provider.

### Read-Only

- `environments` (List of String) The list of environment identifiers that the provider configuration is shared to, or `["*"]` if shared with all environments.
6 changes: 4 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ slug: "provider_overview"
order: 0
hidden: false
---
# Scalr Provider

The Scalr Terraform provider can be used to manage objects in Scalr with Terraform.

Using the Scalr Terraform provider is a best practice as you scale your Terraform and Scalr operations. It is not required, but many customers have a Scalr admin environment and workspace(s), which use the provider to manage all other objects in Scalr.
Expand Down Expand Up @@ -54,7 +56,7 @@ If you have tokens stored in files locally, the `~/.terraform.d/credentials.tfrc

As mentioned, a best practice is to use the Scalr Terraform provider to manage objects within Scalr.

If you are using Scalr to execute the Terraform runs that call the Scalr provider, you must override a default token set for each run. The default token has minimal permissions to allow for the run execution, which means the run will fail if you don't set the `SCALR_TOKEN` variable in the workspace. It is recommended to use a [service account](/docs/identity-and-access-management#service-accounts) for the token.
If you are using Scalr to execute the Terraform runs that call the Scalr provider, you must override a default token set for each run. The default token has minimal permissions to allow for the run execution, which means the run will fail if you don't set the `SCALR_TOKEN` variable in the workspace. It is recommended to use a [service account](https://docs.scalr.io/docs/identity-and-access-management#service-accounts) for the token.

![SCALR_TOKEN Variable](https://files.readme.io/2a1d8e3-Screen_Shot_2022-11-28_at_12.19.04_PM.png)

Expand All @@ -68,4 +70,4 @@ Not sure where to get started? Take a look at the Ignite repo, which will deploy
### Optional

- `hostname` (String) The Scalr hostname to connect to. Defaults to `scalr.io`. Can be overridden by setting the `SCALR_HOSTNAME` environment variable.
- `token` (String) The token used to authenticate with Scalr. Can be overridden by setting the `SCALR_TOKEN` environment variable. See [Scalr provider configuration](/docs/scalr) for information on generating a token.
- `token` (String) The token used to authenticate with Scalr. Can be overridden by setting the `SCALR_TOKEN` environment variable. See [Scalr provider configuration](https://docs.scalr.io/docs/scalr) for information on generating a token.
2 changes: 1 addition & 1 deletion docs/resources/provider_configuration_default.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ order: 12

Manage defaults of provider configurations for environments in Scalr. Create and destroy.

**Note:** To make the provider configuration default, it must be shared with the specified environment. See the definition of the resource [`scalr_provider_configuration`](provider_configuration.md) and attribute `environments` to learn more.
**Note:** To make the provider configuration default, it must be shared with the specified environment. See the definition of the resource [`scalr_provider_configuration`](provider_resource_scalr_provider_configuration) and attribute `environments` to learn more.

## Example Usage

Expand Down
17 changes: 17 additions & 0 deletions scalr/data_source_scalr_provider_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ func dataSourceScalrProviderConfiguration() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"environments": {
Description: "The list of environment identifiers that the provider configuration is shared to, or `[\"*\"]` if shared with all environments.",
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}
Expand Down Expand Up @@ -78,6 +84,17 @@ func dataSourceScalrProviderConfigurationRead(ctx context.Context, d *schema.Res

providerConfiguration := providerConfigurations.Items[0]
d.SetId(providerConfiguration.ID)
_ = d.Set("provider_name", providerConfiguration.ProviderName)

if providerConfiguration.IsShared {
_ = d.Set("environments", []string{"*"})
} else {
environments := make([]string, 0)
for _, environment := range providerConfiguration.Environments {
environments = append(environments, environment.ID)
}
_ = d.Set("environments", environments)
}

return nil
}
17 changes: 17 additions & 0 deletions scalr/data_source_scalr_provider_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scalr

import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"regexp"
"testing"

Expand Down Expand Up @@ -34,13 +35,29 @@ func TestAccScalrProviderConfigurationDataSource(t *testing.T) {
testAccCheckEqualID("data.scalr_provider_configuration.consul_id", "scalr_provider_configuration.consul"),
),
},
{
Config: testAccScalrProviderConfigurationDataSourceScalrConfig,
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckEqualID("data.scalr_provider_configuration.scalr", "scalr_provider_configuration.scalr"),
resource.TestCheckResourceAttr("data.scalr_provider_configuration.scalr", "name", rName),
resource.TestCheckResourceAttr("data.scalr_provider_configuration.scalr", "account_id", defaultAccount),
resource.TestCheckResourceAttr("data.scalr_provider_configuration.scalr", "provider_name", "scalr"),
),
},
{
Config: testAccScalrProviderConfigurationDataSourceInitConfig,
},
},
})
}

var rName = acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)

var testAccScalrProviderConfigurationDataSourceScalrConfig = testAccScalrProviderConfigurationScalrConfig(rName) + `
data "scalr_provider_configuration" "scalr" {
name = scalr_provider_configuration.scalr.name
}`

var testAccScalrProviderConfigurationDataSourceInitConfig = fmt.Sprintf(`
resource "scalr_provider_configuration" "kubernetes" {
name = "kubernetes1"
Expand Down
2 changes: 1 addition & 1 deletion scalr/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Provider() *schema.Provider {
Optional: true,
Description: "The token used to authenticate with Scalr." +
" Can be overridden by setting the `SCALR_TOKEN` environment variable." +
" See [Scalr provider configuration](/docs/scalr)" +
" See [Scalr provider configuration](https://docs.scalr.io/docs/scalr)" +
" for information on generating a token.",
DefaultFunc: schema.EnvDefaultFunc("SCALR_TOKEN", nil),
},
Expand Down
2 changes: 1 addition & 1 deletion scalr/resource_scalr_provider_configuration_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func resourceScalrProviderConfigurationDefault() *schema.Resource {
return &schema.Resource{
Description: "Manage defaults of provider configurations for environments in Scalr. Create and destroy." +
"\n\n**Note:** To make the provider configuration default, it must be shared with the specified environment." +
" See the definition of the resource [`scalr_provider_configuration`](provider_configuration.md)" +
" See the definition of the resource [`scalr_provider_configuration`](provider_resource_scalr_provider_configuration)" +
" and attribute `environments` to learn more.",
CreateContext: resourceScalrProviderConfigurationDefaultCreate,
ReadContext: resourceScalrProviderConfigurationDefaultRead,
Expand Down
4 changes: 3 additions & 1 deletion templates/index.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ slug: "provider_overview"
order: 0
hidden: false
---
# {{.ProviderShortName | title}} Provider

The Scalr Terraform provider can be used to manage objects in Scalr with Terraform.

Using the Scalr Terraform provider is a best practice as you scale your Terraform and Scalr operations. It is not required, but many customers have a Scalr admin environment and workspace(s), which use the provider to manage all other objects in Scalr.
Expand Down Expand Up @@ -40,7 +42,7 @@ If you have tokens stored in files locally, the `~/.terraform.d/credentials.tfrc

As mentioned, a best practice is to use the Scalr Terraform provider to manage objects within Scalr.

If you are using Scalr to execute the Terraform runs that call the Scalr provider, you must override a default token set for each run. The default token has minimal permissions to allow for the run execution, which means the run will fail if you don't set the `SCALR_TOKEN` variable in the workspace. It is recommended to use a [service account](/docs/identity-and-access-management#service-accounts) for the token.
If you are using Scalr to execute the Terraform runs that call the Scalr provider, you must override a default token set for each run. The default token has minimal permissions to allow for the run execution, which means the run will fail if you don't set the `SCALR_TOKEN` variable in the workspace. It is recommended to use a [service account](https://docs.scalr.io/docs/identity-and-access-management#service-accounts) for the token.

![SCALR_TOKEN Variable](https://files.readme.io/2a1d8e3-Screen_Shot_2022-11-28_at_12.19.04_PM.png)

Expand Down

0 comments on commit 80f6ec1

Please sign in to comment.