Skip to content

Commit 5f428d0

Browse files
committed
feat: Added support for adding providers through mach config directly, without needing plugins
1 parent 2efba9b commit 5f428d0

File tree

21 files changed

+308
-24
lines changed

21 files changed

+308
-24
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Added
2+
body: Added support for adding providers through mach config directly, without needing plugins
3+
time: 2025-06-27T15:20:55.908740714+02:00

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ require (
5252
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
5353
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
5454
github.com/felixge/httpsnoop v1.0.4 // indirect
55+
github.com/flosch/pongo2/v5 v5.0.0 // indirect
5556
github.com/go-logr/logr v1.4.2 // indirect
5657
github.com/go-logr/stdr v1.2.2 // indirect
5758
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,8 @@ github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
745745
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
746746
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
747747
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
748+
github.com/flosch/pongo2/v5 v5.0.0 h1:ZauMp+iPZzh2aI1QM2UwRb0lXD4BoFcvBuWqefkIuq0=
749+
github.com/flosch/pongo2/v5 v5.0.0/go.mod h1:6ysKu++8ANFXmc3x6uA6iVaS+PKUoDfdX3yPcv8TIzY=
748750
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
749751
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
750752
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=

internal/cmd/testdata/cases/generate/aws-deployment-type-mixed/expected/main/test-1/component-2/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ module "component-2" {
3030
variables = {
3131
parent_names = [data.terraform_remote_state.test-1.outputs.component-1.name]
3232
}
33+
component_version = "test"
34+
environment = "test"
35+
site = "test-1"
36+
tags = { "Component" : "component-2", "Site" : "test-1", "Version" : "test" }
3337
}
3438

3539
output "component-2" {

internal/cmd/testdata/cases/generate/aws-deployment-type-mixed/expected/main/test-1/main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ locals {
3131

3232
# Component: component-1
3333
module "component-1" {
34-
source = "{{ .PWD }}/testdata/modules/application"
34+
source = "{{ .PWD }}/testdata/modules/application"
35+
component_version = "test"
36+
environment = "test"
37+
site = "test-1"
38+
tags = { "Component" : "component-1", "Site" : "test-1", "Version" : "test" }
3539
}
3640

3741
output "component-1" {

internal/cmd/testdata/cases/generate/aws-deployment-type-site/expected/main/test-1/main.tf

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ locals {
3131

3232
# Component: component-1
3333
module "component-1" {
34-
source = "{{ .PWD }}/testdata/modules/application"
34+
source = "{{ .PWD }}/testdata/modules/application"
35+
component_version = "test"
36+
environment = "test"
37+
site = "test-1"
38+
tags = { "Component" : "component-1", "Site" : "test-1", "Version" : "test" }
3539
}
3640

3741
output "component-1" {
@@ -42,7 +46,11 @@ output "component-1" {
4246

4347
# Component: component-2
4448
module "component-2" {
45-
source = "{{ .PWD }}/testdata/modules/application"
49+
source = "{{ .PWD }}/testdata/modules/application"
50+
component_version = "test"
51+
environment = "test"
52+
site = "test-1"
53+
tags = { "Component" : "component-2", "Site" : "test-1", "Version" : "test" }
4654
}
4755

4856
output "component-2" {

internal/cmd/testdata/cases/generate/aws-multisite/expected/main/test-1/component-1/main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ terraform {
1515
# Resources
1616
# Component: component-1
1717
module "component-1" {
18-
source = "{{ .PWD }}/testdata/modules/application"
18+
source = "{{ .PWD }}/testdata/modules/application"
19+
component_version = "test"
20+
environment = "test"
21+
site = "test-1"
22+
tags = { "Component" : "component-1", "Site" : "test-1", "Version" : "test" }
1923
}
2024

2125
output "component-1" {

internal/cmd/testdata/cases/generate/aws-multisite/expected/main/test-2/component-1/main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ terraform {
1515
# Resources
1616
# Component: component-1
1717
module "component-1" {
18-
source = "{{ .PWD }}/testdata/modules/application"
18+
source = "{{ .PWD }}/testdata/modules/application"
19+
component_version = "test"
20+
environment = "test"
21+
site = "test-2"
22+
tags = { "Component" : "component-1", "Site" : "test-2", "Version" : "test" }
1923
}
2024

2125
output "component-1" {

internal/cmd/testdata/modules/application/main.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@ variable "variables" {
1616
})
1717
}
1818

19+
variable "component_version" {
20+
type = string
21+
}
22+
23+
variable "environment" {
24+
type = string
25+
}
26+
27+
variable "site" {
28+
type = string
29+
}
30+
31+
variable "tags" {
32+
type = map(string)
33+
}
34+
1935
data "http" "example" {
2036
count = var.variables.fail == true ? 1 : 0
2137
url = "fails"

internal/config/global.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55
"github.com/mach-composer/mach-composer-cli/internal/cli"
66
"github.com/mach-composer/mach-composer-cli/internal/config/variable"
77
"github.com/mach-composer/mach-composer-cli/internal/utils"
8+
"github.com/rs/zerolog/log"
89
"gopkg.in/yaml.v3"
10+
"slices"
911
)
1012

1113
type GlobalConfig struct {
@@ -19,8 +21,9 @@ type GlobalConfig struct {
1921
}
2022

2123
type TerraformConfig struct {
22-
Providers map[string]string `yaml:"providers"`
23-
RemoteState map[string]any `yaml:"remote_state"`
24+
Providers map[string]string `yaml:"providers"`
25+
ProviderConfigs ProviderConfigs `yaml:"provider_configs"`
26+
RemoteState map[string]any `yaml:"remote_state"`
2427
}
2528

2629
func parseGlobalNode(cfg *MachConfig, globalNode *yaml.Node) error {
@@ -56,6 +59,20 @@ func parseGlobalNode(cfg *MachConfig, globalNode *yaml.Node) error {
5659
}
5760
}
5861

62+
if cfg.Global.TerraformConfig != nil {
63+
pluginNames := cfg.Plugins.AllNames()
64+
providerNames, err := cfg.Global.TerraformConfig.ProviderConfigs.Names()
65+
if err != nil {
66+
return fmt.Errorf("failed to get provider names: %w", err)
67+
}
68+
69+
for _, providerName := range providerNames {
70+
if slices.Contains(pluginNames, providerName) {
71+
log.Warn().Str("plugin", providerName).Str("name", providerName).Msgf("plugin exists with the same name as a provider: %s, this might cause duplicate providers in the generated Terraform code", providerName)
72+
}
73+
}
74+
}
75+
5976
if node, ok := nodes["terraform_config"]; ok {
6077
children := MapYamlNodes(node.Content)
6178

0 commit comments

Comments
 (0)