Skip to content

Commit

Permalink
fix: added all azurem backend options (#443)
Browse files Browse the repository at this point in the history
<!--

Describe in detail the changes you are proposing, and the rationale.

-->

<!--

Link all GitHub issues fixed by this PR, and add references to prior
related PRs.

-->

Fixes #

### NEW FEATURES | UPGRADE NOTES | ENHANCEMENTS | BUG FIXES |
EXPERIMENTS

<!--

Write a short description of your changes. Examples:

- Fixed a bug
- Added a new feature
- Updated documentation

--> 

-
  • Loading branch information
demeyerthom authored Sep 9, 2024
2 parents b6c449e + d250fc8 commit 5dd076f
Show file tree
Hide file tree
Showing 6 changed files with 485 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Fixed-20240906-140210.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Fixed
body: Added all the terraform azurem backend options
time: 2024-09-06T14:02:10.609294121+02:00
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# SiteComponent: test-1/component-1
terraform {
backend "azurerm" {
resource_group_name = "resourcegroupid"
key = "test-1/component-1"
storage_account_name = "storageaccount"
container_name = "container-name"
key = "test-1/component-1"
resource_group_name = "resourcegroupid"
}
required_providers {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# site: test-1
terraform {
backend "azurerm" {
resource_group_name = "resourcegroupid"
key = "test-1"
storage_account_name = "storageaccount"
container_name = "container-name"
key = "test-1"
resource_group_name = "resourcegroupid"
}
required_providers {}
}
Expand Down
164 changes: 154 additions & 10 deletions internal/state/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,30 @@ import (
)

type AzureState struct {
ResourceGroup string `mapstructure:"resource_group"`
StorageAccount string `mapstructure:"storage_account"`
ContainerName string `mapstructure:"container_name"`
StateFolder string `mapstructure:"state_folder"`
StorageAccount string `mapstructure:"storage_account"`
ContainerName string `mapstructure:"container_name"`
Environment string `mapstructure:"environment"`
Endpoint string `mapstructure:"endpoint"`
MetadataHost string `mapstructure:"metadata_host"`
Snapshot bool `mapstructure:"snapshot"`
ResourceGroup string `mapstructure:"resource_group"`
MsiEndpoint string `mapstructure:"msi_endpoint"`
SubscriptionId string `mapstructure:"subscription_id"`
TenantId string `mapstructure:"tenant_id"`
UseMsi bool `mapstructure:"use_msi"`
OidcRequestUrl string `mapstructure:"oidc_request_url"`
OidcRequestToken string `mapstructure:"oidc_request_token"`
OidcToken string `mapstructure:"oidc_token"`
OidcTokenFilePath string `mapstructure:"oidc_token_file_path"`
UseOidc bool `mapstructure:"use_oidc"`
SasToken string `mapstructure:"sas_token"`
AccessKey string `mapstructure:"access_key"`
UseAzureAdAuth bool `mapstructure:"use_azuread_auth"`
ClientId string `mapstructure:"client_id"`
ClientSecret string `mapstructure:"client_secret"`
ClientCertificatePassword string `mapstructure:"client_certificate_password"`
ClientCertificatePath string `mapstructure:"client_certificate_path"`
StateFolder string `mapstructure:"state_folder"`
}

func (a AzureState) Identifier(identifier string) string {
Expand All @@ -35,10 +55,72 @@ func (ar *AzureRenderer) Backend() (string, error) {

tpl := `
backend "azurerm" {
resource_group_name = "{{ .State.ResourceGroup }}"
key = "{{ .Identifier }}"
storage_account_name = "{{ .State.StorageAccount }}"
container_name = "{{ .State.ContainerName }}"
key = "{{ .Identifier }}"
container_name = "{{ .State.ContainerName }}"
{{- if .State.Environment }}
environment = "{{ .State.Environment }}"
{{- end }}
{{- if .State.Endpoint }}
endpoint = "{{ .State.Endpoint }}"
{{- end }}
{{- if .State.MetadataHost }}
metadata_host = "{{ .State.MetadataHost }}"
{{- end }}
{{- if .State.Snapshot }}
snapshot = true
{{- end }}
{{- if .State.ResourceGroup }}
resource_group_name = "{{ .State.ResourceGroup }}"
{{- end }}
{{- if .State.MsiEndpoint }}
msi_endpoint = "{{ .State.MsiEndpoint }}"
{{- end }}
{{- if .State.SubscriptionId }}
subscription_id = "{{ .State.SubscriptionId }}"
{{- end }}
{{- if .State.TenantId }}
tenant_id = "{{ .State.TenantId }}"
{{- end }}
{{- if .State.UseMsi }}
use_msi = true
{{- end }}
{{- if .State.OidcRequestUrl }}
oidc_request_url = "{{ .State.OidcRequestUrl }}"
{{- end }}
{{- if .State.OidcRequestToken }}
oidc_request_token = "{{ .State.OidcRequestToken }}"
{{- end }}
{{- if .State.OidcToken }}
oidc_token = "{{ .State.OidcToken }}"
{{- end }}
{{- if .State.OidcTokenFilePath }}
oidc_token_file_path = "{{ .State.OidcTokenFilePath }}"
{{- end }}
{{- if .State.UseOidc }}
use_oidc = true
{{- end }}
{{- if .State.SasToken }}
sas_token = "{{ .State.SasToken }}"
{{- end }}
{{- if .State.AccessKey }}
access_key = "{{ .State.AccessKey }}"
{{- end }}
{{- if .State.UseAzureAdAuth }}
use_azuread_auth = true
{{- end }}
{{- if .State.ClientId }}
client_id = "{{ .State.ClientId }}"
{{- end }}
{{- if .State.ClientSecret }}
client_secret = "{{ .State.ClientSecret }}"
{{- end }}
{{- if .State.ClientCertificatePassword }}
client_certificate_password = "{{ .State.ClientCertificatePassword }}"
{{- end }}
{{- if .State.ClientCertificatePath }}
client_certificate_path = "{{ .State.ClientCertificatePath }}"
{{- end }}
}
`
return utils.RenderGoTemplate(tpl, templateContext)
Expand All @@ -60,10 +142,72 @@ func (ar *AzureRenderer) RemoteState() (string, error) {
backend = "azurerm"
config = {
resource_group_name = "{{ .State.ResourceGroup }}"
key = "{{ .Identifier }}"
storage_account_name = "{{ .State.StorageAccount }}"
container_name = "{{ .State.ContainerName }}"
key = "{{ .Identifier }}"
container_name = "{{ .State.ContainerName }}"
{{- if .State.Environment }}
environment = "{{ .State.Environment }}"
{{- end }}
{{- if .State.Endpoint }}
endpoint = "{{ .State.Endpoint }}"
{{- end }}
{{- if .State.MetadataHost }}
metadata_host = "{{ .State.MetadataHost }}"
{{- end }}
{{- if .State.Snapshot }}
snapshot = true
{{- end }}
{{- if .State.ResourceGroup }}
resource_group_name = "{{ .State.ResourceGroup }}"
{{- end }}
{{- if .State.MsiEndpoint }}
msi_endpoint = "{{ .State.MsiEndpoint }}"
{{- end }}
{{- if .State.SubscriptionId }}
subscription_id = "{{ .State.SubscriptionId }}"
{{- end }}
{{- if .State.TenantId }}
tenant_id = "{{ .State.TenantId }}"
{{- end }}
{{- if .State.UseMsi }}
use_msi = true
{{- end }}
{{- if .State.OidcRequestUrl }}
oidc_request_url = "{{ .State.OidcRequestUrl }}"
{{- end }}
{{- if .State.OidcRequestToken }}
oidc_request_token = "{{ .State.OidcRequestToken }}"
{{- end }}
{{- if .State.OidcToken }}
oidc_token = "{{ .State.OidcToken }}"
{{- end }}
{{- if .State.OidcTokenFilePath }}
oidc_token_file_path = "{{ .State.OidcTokenFilePath }}"
{{- end }}
{{- if .State.UseOidc }}
use_oidc = true
{{- end }}
{{- if .State.SasToken }}
sas_token = "{{ .State.SasToken }}"
{{- end }}
{{- if .State.AccessKey }}
access_key = "{{ .State.AccessKey }}"
{{- end }}
{{- if .State.UseAzureAdAuth }}
use_azuread_auth = true
{{- end }}
{{- if .State.ClientId }}
client_id = "{{ .State.ClientId }}"
{{- end }}
{{- if .State.ClientSecret }}
client_secret = "{{ .State.ClientSecret }}"
{{- end }}
{{- if .State.ClientCertificatePassword }}
client_certificate_password = "{{ .State.ClientCertificatePassword }}"
{{- end }}
{{- if .State.ClientCertificatePath }}
client_certificate_path = "{{ .State.ClientCertificatePath }}"
{{- end }}
}
}
`
Expand Down
Loading

0 comments on commit 5dd076f

Please sign in to comment.