refactor: use workspace name in azurerm backend
parent
f4a92e7b32
commit
cb5ab70559
|
@ -32,7 +32,7 @@ func (b BackendBlock) SupplierConfig(workspace string) *config.SupplierConfig {
|
|||
case "gcs":
|
||||
return b.parseGCSBackend(workspace)
|
||||
case "azurerm":
|
||||
return b.parseAzurermBackend()
|
||||
return b.parseAzurermBackend(workspace)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -79,10 +79,13 @@ func (b BackendBlock) parseGCSBackend(ws string) *config.SupplierConfig {
|
|||
}
|
||||
}
|
||||
|
||||
func (b BackendBlock) parseAzurermBackend() *config.SupplierConfig {
|
||||
func (b BackendBlock) parseAzurermBackend(ws string) *config.SupplierConfig {
|
||||
if b.ContainerName == "" || b.Key == "" {
|
||||
return nil
|
||||
}
|
||||
if ws != DefaultStateName {
|
||||
b.Key = fmt.Sprintf("%senv:%s", b.Key, ws)
|
||||
}
|
||||
return &config.SupplierConfig{
|
||||
Key: state.TerraformStateReaderSupplier,
|
||||
Backend: backend.BackendKeyAzureRM,
|
||||
|
|
|
@ -96,6 +96,15 @@ func TestBackend_SupplierConfig(t *testing.T) {
|
|||
Path: "states/prod.terraform.tfstate",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "test with Azure backend block with non-default workspace",
|
||||
filename: "testdata/azurerm_backend_workspace/azurerm_backend_block.tf",
|
||||
want: &config.SupplierConfig{
|
||||
Key: "tfstate",
|
||||
Backend: "azurerm",
|
||||
Path: "states/prod.terraform.tfstateenv:bar",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "test with unknown backend",
|
||||
filename: "testdata/unknown_backend_block.tf",
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
!.terraform
|
|
@ -0,0 +1 @@
|
|||
bar
|
12
pkg/terraform/hcl/testdata/azurerm_backend_workspace/azurerm_backend_block.tf
vendored
Normal file
12
pkg/terraform/hcl/testdata/azurerm_backend_workspace/azurerm_backend_block.tf
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
terraform {
|
||||
backend "azurerm" {
|
||||
resource_group_name = "StorageAccount-ResourceGroup"
|
||||
storage_account_name = "abcd1234"
|
||||
container_name = "states"
|
||||
key = "prod.terraform.tfstate"
|
||||
}
|
||||
}
|
||||
|
||||
provider "azurerm" {
|
||||
features {}
|
||||
}
|
Loading…
Reference in New Issue