File tree Expand file tree Collapse file tree 5 files changed +28
-2
lines changed
testdata/azurerm_backend_workspace Expand file tree Collapse file tree 5 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ func (b BackendBlock) SupplierConfig(workspace string) *config.SupplierConfig {
3232 case "gcs" :
3333 return b .parseGCSBackend (workspace )
3434 case "azurerm" :
35- return b .parseAzurermBackend ()
35+ return b .parseAzurermBackend (workspace )
3636 }
3737 return nil
3838}
@@ -79,10 +79,13 @@ func (b BackendBlock) parseGCSBackend(ws string) *config.SupplierConfig {
7979 }
8080}
8181
82- func (b BackendBlock ) parseAzurermBackend () * config.SupplierConfig {
82+ func (b BackendBlock ) parseAzurermBackend (ws string ) * config.SupplierConfig {
8383 if b .ContainerName == "" || b .Key == "" {
8484 return nil
8585 }
86+ if ws != DefaultStateName {
87+ b .Key = fmt .Sprintf ("%senv:%s" , b .Key , ws )
88+ }
8689 return & config.SupplierConfig {
8790 Key : state .TerraformStateReaderSupplier ,
8891 Backend : backend .BackendKeyAzureRM ,
Original file line number Diff line number Diff line change @@ -96,6 +96,15 @@ func TestBackend_SupplierConfig(t *testing.T) {
9696 Path : "states/prod.terraform.tfstate" ,
9797 },
9898 },
99+ {
100+ name : "test with Azure backend block with non-default workspace" ,
101+ filename : "testdata/azurerm_backend_workspace/azurerm_backend_block.tf" ,
102+ want : & config.SupplierConfig {
103+ Key : "tfstate" ,
104+ Backend : "azurerm" ,
105+ Path : "states/prod.terraform.tfstateenv:bar" ,
106+ },
107+ },
99108 {
100109 name : "test with unknown backend" ,
101110 filename : "testdata/unknown_backend_block.tf" ,
Original file line number Diff line number Diff line change 1+ ! .terraform
Original file line number Diff line number Diff line change 1+ bar
Original file line number Diff line number Diff line change 1+ terraform {
2+ backend "azurerm" {
3+ resource_group_name = " StorageAccount-ResourceGroup"
4+ storage_account_name = " abcd1234"
5+ container_name = " states"
6+ key = " prod.terraform.tfstate"
7+ }
8+ }
9+
10+ provider "azurerm" {
11+ features {}
12+ }
You can’t perform that action at this time.
0 commit comments