Skip to content

Commit

Permalink
Merge pull request #362 from magodo/provider_config_attr
Browse files Browse the repository at this point in the history
`Config.ProviderConfig` supports flexible attributes
  • Loading branch information
magodo authored Feb 22, 2023
2 parents 840ee3d + 6b19a77 commit 767665b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
14 changes: 7 additions & 7 deletions internal/meta/base_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/Azure/aztfy/pkg/config"
"github.com/Azure/aztfy/pkg/log"
"github.com/zclconf/go-cty/cty"

"github.com/Azure/aztfy/internal/client"
"github.com/Azure/aztfy/internal/resmap"
Expand Down Expand Up @@ -75,7 +76,7 @@ type baseMeta struct {
devProvider bool
backendType string
backendConfig []string
providerConfig map[string]string
providerConfig map[string]cty.Value
fullConfig bool
parallelism int
hclOnly bool
Expand Down Expand Up @@ -569,14 +570,13 @@ func (meta *baseMeta) buildTerraformConfig(backendType string) string {
}

func (meta *baseMeta) buildProviderConfig() string {
lines := []string{" features {}"}
f := hclwrite.NewEmptyFile()
body := f.Body().AppendNewBlock("provider", []string{"azurerm"}).Body()
body.AppendNewBlock("features", nil)
for k, v := range meta.providerConfig {
lines = append(lines, fmt.Sprintf(" %s = %s", k, v))
body.SetAttributeValue(k, v)
}
return fmt.Sprintf(`provider "azurerm" {
%s
}
`, strings.Join(lines, "\n"))
return string(f.Bytes())
}

func (meta *baseMeta) initTF(ctx context.Context) error {
Expand Down
5 changes: 3 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/Azure/aztfy/pkg/telemetry"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/zclconf/go-cty/cty"
)

type OutputFileNames struct {
Expand Down Expand Up @@ -36,10 +37,10 @@ type CommonConfig struct {
// BackendConfig specifies an array of Terraform backend configs.
BackendConfig []string
// ProviderConfig specifies key value pairs that will be expanded to the terraform-provider-azurerm settings (i.e. `azurerm {}` block)
// Currently, only the top level attribute whose type is string is supported.
// Currently, only the attributes (rather than blocks) are supported.
// This is not used directly by aztfy binary as the provider configs can be set by environment variable already.
// While it is useful for module users that want support multi-users scenarios in one process (in which case changing env vars affect the whole process).
ProviderConfig map[string]string
ProviderConfig map[string]cty.Value
// FullConfig specifies whether to export all (non computed-only) Terarform properties when generating TF configs.
FullConfig bool
// Parallelism specifies the parallelism for the process
Expand Down

0 comments on commit 767665b

Please sign in to comment.