Skip to content

Commit 157cb70

Browse files
davisnandomvantellingen
authored andcommitted
Fix pointer issue with not managed stores
1 parent 3c95064 commit 157cb70

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

internal/renderer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func renderResources(cfg *SiteConfig, version string) (string, error) {
1919
Funcs(helpers.TemplateFuncs()).
2020
Funcs(map[string]any{
2121
"RenderScopes": renderScope,
22+
"derefBool": func(i *bool, defaultValue bool) bool { if i == nil{return defaultValue } else{ return *i} },
2223
}).
2324
ParseFS(templates, "templates/*.tf.gtpl")
2425
if err != nil {

internal/renderer_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,52 @@ func TestRenderResourcesStores(t *testing.T) {
9797

9898
assert.Contains(t, data, `client_secret = data.sops.values["my-secret"]`)
9999
}
100+
101+
102+
func TestRenderResourcesStoresWithManagedFalse(t *testing.T) {
103+
trueRef := true
104+
cfg := &SiteConfig{
105+
ProjectKey: "key",
106+
ClientSecret: "test",
107+
ProjectSettings: &CommercetoolsProjectSettings{
108+
Countries: []string{"NL", "DE"},
109+
},
110+
Frontend: &CommercetoolsFrontendSettings{
111+
CreateCredentials: &trueRef,
112+
},
113+
TaxCategories: []CommercetoolsTaxCategory{
114+
{
115+
Key: "low",
116+
Name: "Low Tax",
117+
Rates: []CommercetoolsTax{
118+
{
119+
Country: "NL",
120+
Amount: 0.8,
121+
Name: "Low",
122+
IncludedInPrice: &trueRef,
123+
},
124+
},
125+
},
126+
},
127+
Stores: []CommercetoolsStore{
128+
{
129+
Key: "my-store",
130+
Managed: &[]bool{false}[0], // Create bool pointer
131+
},
132+
},
133+
Zones: []CommercetoolsZone{
134+
{
135+
Name: "Primary",
136+
Description: "Primary zone",
137+
Locations: []CommercetoolsZoneLocation{
138+
{
139+
Country: "NL",
140+
},
141+
},
142+
},
143+
},
144+
}
145+
data, err := renderResources(cfg, "0.1.0")
146+
require.NoError(t, err)
147+
assert.NotContains(t, data, `depends_on = [commercetools_store.my-store]`)
148+
}

internal/templates/frontend.tf.gtpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ resource "commercetools_api_client" "frontend_credentials_{{ $store.Key }}" {
44
name = "frontend_credentials_terraform_{{ $store.Key }}"
55
scope = {{ RenderScopes $.Config.Frontend.PermissionScopes $.Config.ProjectKey $store.Key }}
66

7-
{{ if $store.Managed }}
7+
{{ if derefBool $store.Managed true }}
88
depends_on = [commercetools_store.{{ $store.Key }}]
99
{{ end }}
1010
}

0 commit comments

Comments
 (0)