Skip to content

Commit

Permalink
Merged automatically by CI pipeline
Browse files Browse the repository at this point in the history
SCALRCORE-28030 Provider > Data sources > Provider configurations: Improvements
  • Loading branch information
emocharnik authored Oct 6, 2023
2 parents e3797d4 + 45d67b5 commit ee02e37
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ 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_provider_configuration`: Added new attribute `environments` ([#285](https://github.com/Scalr/terraform-provider-scalr/pull/280/files))
- `data.scalr_provider_configuration`: Fixed `provider-name` attribute ([#285](https://github.com/Scalr/terraform-provider-scalr/pull/280/files))
- `data.scalr_enviroment`: Added new attribute `default_provider_configurations` ([#279](https://github.com/Scalr/terraform-provider-scalr/pull/279))

### Added
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.
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

0 comments on commit ee02e37

Please sign in to comment.