-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from Scalr/feature/SCALRCORE-21436
SCALRCORE-21436 [provider] Scalr Provider > Provider configuration resource and data source
- Loading branch information
Showing
13 changed files
with
1,869 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
layout: "scalr" | ||
page_title: "Scalr: scalr_provider_configuration" | ||
sidebar_current: "docs-datasource-scalr-provider-configuration" | ||
description: |- | ||
Get information on a provider configuration. | ||
--- | ||
|
||
# scalr_provider_configuration Data Source | ||
|
||
This data source is used to retrieve id of a single provider configuration by name or type. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "scalr_provider_configuration" "aws_dev" { | ||
name = "aws_dev" | ||
} | ||
data "scalr_provider_configuration" "azure" { | ||
provider_name = "azurerm" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Optional) The name of a Scalr provider configuration. | ||
* `provider_name` - (Optional) The name of a Terraform provider. | ||
* `environment_id` - (Optional) ID of the environment, in the format `env-xxxxxxxx`. | ||
|
||
## Attribute Reference | ||
|
||
All arguments plus: | ||
|
||
* `id` - The provider configuration ID, in the format `pcfg-xxxxxxxxxxx`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
layout: "scalr" | ||
page_title: "Scalr: scalr_provider_configurations" | ||
sidebar_current: "docs-datasource-scalr-provider-configurations" | ||
description: |- | ||
Get information on provider configurations. | ||
--- | ||
|
||
# scalr_provider_configurations Data Source | ||
|
||
This data source is used to retrieve list of provider configuration ids by name or type. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "scalr_provider_configurations" "aws" { | ||
name = "in:aws_dev,aws_demo,aws_prod" | ||
} | ||
data "scalr_provider_configurations" "google" { | ||
provider_name = "google" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Optional) The query used in a Scalr provider configuration name filter. | ||
* `provider_name` - (Optional) The name of a Terraform provider. | ||
* `environment_id` - (Optional) ID of the environment, in the format `env-xxxxxxxx`. | ||
|
||
## Attribute Reference | ||
|
||
All arguments plus: | ||
|
||
* `ids` - The list of provider configuration IDs, in the format [`pcfg-xxxxxxxxxxx`, `pcfg-yyyyyyyyy`]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
--- | ||
layout: "scalr" | ||
page_title: "Scalr: scalr_provider_configuration" | ||
sidebar_current: "docs-resource-scalr-provider-configuration" | ||
description: |- | ||
Manages provider configurations. | ||
--- | ||
|
||
# scalr_provider_configuration Resource | ||
|
||
Manage the state of provider configuraitons in Scalr. Creates, updates and destroy. | ||
|
||
## Example Usage | ||
|
||
Aws provider: | ||
|
||
```hcl | ||
resource "scalr_provider_configuration" "aws" { | ||
name = "aws_dev_us_east_1" | ||
account_id = "acc-xxxxxxxxx" | ||
export_shell_variables = false | ||
aws { | ||
secret_key = "my-secret-key" | ||
access_key = "my-access-key" | ||
} | ||
} | ||
``` | ||
|
||
Google provider: | ||
|
||
```hcl | ||
resource "scalr_provider_configuration" "google" { | ||
name = "google_main" | ||
account_id = "acc-xxxxxxxxx" | ||
google { | ||
project = "my-project" | ||
credentials = "my-credentials" | ||
} | ||
} | ||
``` | ||
|
||
Azurerm provider: | ||
|
||
```hcl | ||
resource "scalr_provider_configuration" "azurerm" { | ||
name = "azurerm" | ||
account_id = "acc-xxxxxxxxx" | ||
azurerm { | ||
client_id = "my-client-id" | ||
client_secret = "my-client-secret" | ||
subscription_id = "my-subscription-id" | ||
tenant_id = "my-tenant-id" | ||
} | ||
} | ||
``` | ||
|
||
Other providers: | ||
|
||
```hcl | ||
resource "scalr_provider_configuration" "kubernetes" { | ||
name = "k8s" | ||
account_id = "acc-xxxxxxxxx" | ||
custom { | ||
provider_name = "kubernetes" | ||
argument { | ||
name = "host" | ||
value = "my-host" | ||
description = "The hostname (in form of URI) of the Kubernetes API." | ||
} | ||
argument { | ||
name = "username" | ||
value = "my-username" | ||
} | ||
argument { | ||
name = "password" | ||
value = "my-password" | ||
sensitive = true | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `account_id` - (Required) The account that owns the variable, specified as an ID, in the format. | ||
* `name` - (Required) The name of a Scalr provider configuration. This field is unique for the account. | ||
* `export_shell_variables` - (Optional) Export provider variables into the run environment. This option is available only for built in providers. | ||
* `aws` - (Optional) Settings for the aws provider configuraiton. Exactly one of the following attributes must be set: `aws`, `google`, `azurerm`, `custom`. | ||
The `aws` block supports the following: | ||
* `secret_key` - (Optional) AWS secret key. | ||
* `access_key` - (Optional) AWS access key. | ||
* `google` - (Optional) Settings for the google provider configuraiton. Exactly one of the following attributes must be set: `aws`, `google`, `azurerm`, `custom`. | ||
The `google` block supports the following: | ||
* `project` - (Optional) The default project to manage resources in. If another project is specified on a resource, it will take precedence. | ||
* `credentials` - (Optional) Either the path to or the contents of a service account key file in JSON format. You can manage key files using the Cloud Console. If not provided, the application default credentials will be used. | ||
* `azurerm` - (Optional) Settings for the azurerm provider configuraiton. Exactly one of the following attributes must be set: `aws`, `google`, `azurerm`, `custom`. | ||
The `azurerm` block supports the following: | ||
* `client_id` - (Optional) The Client ID which should be used. | ||
* `client_secret` - (Optional) The Client Secret which should be used. | ||
* `subscription_id` - (Optional) The Subscription ID which should be used. | ||
* `tenant_id` - (Optional) The Tenant ID should be used. | ||
* `custom` - (Optional) Settings for the provider configuraiton that does not have first class scalr support. Exactly one of the following attributes must be set: `aws`, `google`, `azurerm`, `custom`. | ||
The `custom` block supports the following: | ||
* `provider_name` - (Required) The name of a Terraform provider. | ||
* `argument` - (Required) The provider configuration argument. | ||
The `argument` block supports the following: | ||
* `name` - (Required) The name of the provider configuration argument. | ||
* `value` - (Optional) The value of the provider configuration argument. | ||
* `sensitive` - (Optional) Set (true/false) to configure as sensitive. Default `false`. | ||
* `description` - (Optional) The description of the provider configuration argument. | ||
|
||
|
||
## Attribute Reference | ||
|
||
All arguments plus: | ||
|
||
* `id` - The ID of the provider configuration, in the format `pcfg-xxxxxxxx`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package scalr | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
|
||
scalr "github.com/scalr/go-scalr" | ||
) | ||
|
||
func dataSourceScalrProviderConfiguration() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceScalrProviderConfigurationRead, | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"account_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"provider_name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceScalrProviderConfigurationRead(d *schema.ResourceData, meta interface{}) error { | ||
scalrClient := meta.(*scalr.Client) | ||
|
||
accountID := d.Get("account_id").(string) | ||
name := d.Get("name").(string) | ||
providerName := d.Get("provider_name").(string) | ||
|
||
providersFilter := scalr.ProviderConfigurationFilter{ | ||
AccountID: accountID, | ||
Name: name, | ||
ProviderName: providerName, | ||
} | ||
options := scalr.ProviderConfigurationsListOptions{ | ||
Filter: &providersFilter, | ||
} | ||
|
||
providerConfigurations, err := scalrClient.ProviderConfigurations.List(ctx, options) | ||
if err != nil { | ||
return fmt.Errorf("Error retrieving provider configuration: %v", err) | ||
} | ||
|
||
if len(providerConfigurations.Items) > 1 { | ||
return errors.New("Your query returned more than one result. Please try a more specific search criteria.") | ||
} | ||
if len(providerConfigurations.Items) == 0 { | ||
return fmt.Errorf("Could not find provider configuration with name '%s', account_id: '%s', and provider_name: '%s'", name, accountID, providerName) | ||
} | ||
|
||
providerConfiguration := providerConfigurations.Items[0] | ||
d.SetId(providerConfiguration.ID) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package scalr | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccScalrProviderConfigurationDataSource_name(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccScalrProviderConfigurationAwsDataSourceInitConfig, // depends_on works improperly with data sources | ||
}, | ||
{ | ||
Config: testAccScalrProviderConfigurationAwsDataSourceConfig, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
testAccCheckEqualID("data.scalr_provider_configuration.aws", "scalr_provider_configuration.aws"), | ||
), | ||
}, | ||
{ | ||
Config: testAccScalrProviderConfigurationAwsDataSourceInitConfig, | ||
}, | ||
}, | ||
}) | ||
} | ||
func TestAccScalrProviderConfigurationDataSource_provider_name(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccScalrProviderConfigurationGoogleDataSourceInitConfig, | ||
}, | ||
{ | ||
Config: testAccScalrProviderConfigurationGoogleDataSourceConfig, | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
testAccCheckEqualID("data.scalr_provider_configuration.google", "scalr_provider_configuration.google"), | ||
), | ||
}, | ||
{ | ||
Config: testAccScalrProviderConfigurationAwsDataSourceInitConfig, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
var testAccScalrProviderConfigurationAwsDataSourceInitConfig = fmt.Sprintf(` | ||
resource "scalr_provider_configuration" "google" { | ||
name = "google_pcfg" | ||
account_id = "%[1]s" | ||
google { | ||
project = "my-new-project" | ||
credentials = "my-new-credentials" | ||
} | ||
} | ||
resource "scalr_provider_configuration" "aws" { | ||
name = "aws_pcfg" | ||
account_id = "%[1]s" | ||
aws { | ||
secret_key = "my-new-secret-key" | ||
access_key = "my-new-access-key" | ||
} | ||
}`, defaultAccount) | ||
var testAccScalrProviderConfigurationAwsDataSourceConfig = testAccScalrProviderConfigurationAwsDataSourceInitConfig + ` | ||
data "scalr_provider_configuration" "aws" { | ||
name = scalr_provider_configuration.aws.name | ||
} | ||
` | ||
|
||
var testAccScalrProviderConfigurationGoogleDataSourceInitConfig = fmt.Sprintf(` | ||
resource "scalr_provider_configuration" "google" { | ||
name = "google_pcfg" | ||
account_id = "%[1]s" | ||
google { | ||
project = "my-new-project" | ||
credentials = "my-new-credentials" | ||
} | ||
} | ||
resource "scalr_provider_configuration" "aws" { | ||
name = "aws_pcfg" | ||
account_id = "%[1]s" | ||
aws { | ||
secret_key = "my-new-secret-key" | ||
access_key = "my-new-access-key" | ||
} | ||
}`, defaultAccount) | ||
var testAccScalrProviderConfigurationGoogleDataSourceConfig = testAccScalrProviderConfigurationGoogleDataSourceInitConfig + ` | ||
data "scalr_provider_configuration" "google" { | ||
provider_name = "google" | ||
}` |
Oops, something went wrong.