Skip to content

Commit

Permalink
tooling fails on missing values
Browse files Browse the repository at this point in the history
Signed-off-by: Gerd Oberlechner <[email protected]>
  • Loading branch information
geoberle committed Oct 24, 2024
1 parent 7d3866a commit 98621ba
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 66 deletions.
46 changes: 0 additions & 46 deletions .github/actions/templatize.yml

This file was deleted.

14 changes: 6 additions & 8 deletions tooling/templatize/cmd/generate/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,22 @@ func TestExecuteTemplate(t *testing.T) {
"region_maestro_keyvault": "kv",
"region_eventgrid_namespace": "ns",
},
input: `param maestroKeyVaultName = '{{index . "region_maestro_keyvault"}}'
param maestroEventGridNamespacesName = '{{index . "region_eventgrid_namespace"}}'
input: `param maestroKeyVaultName = '{{ .region_maestro_keyvault }}'
param maestroEventGridNamespacesName = '{{ .region_eventgrid_namespace }}'
param maestroEventGridMaxClientSessionsPerAuthName = 4`,
expected: `param maestroKeyVaultName = 'kv'
param maestroEventGridNamespacesName = 'ns'
param maestroEventGridMaxClientSessionsPerAuthName = 4`,
},
{
name: "referencing unset variable errors", // TODO: this does not error today, just gets an empty string, this is not the UX we want
name: "referencing unset variable errors",
config: config.Variables{
"region_maestro_keyvault": "kv",
},
input: `param maestroKeyVaultName = '{{index . "region_maestro_keyvault"}}'
param maestroEventGridNamespacesName = '{{index . "region_eventgrid_namespace"}}'
param maestroEventGridMaxClientSessionsPerAuthName = 4`,
expected: `param maestroKeyVaultName = 'kv'
param maestroEventGridNamespacesName = '<no value>'
input: `param maestroKeyVaultName = '{{ .region_maestro_keyvault }}'
param maestroEventGridNamespacesName = '{{ .region_eventgrid_namespace }}'
param maestroEventGridMaxClientSessionsPerAuthName = 4`,
expectedError: true,
},
} {
t.Run(testCase.name, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tooling/templatize/cmd/generate/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,5 @@ func (opts *GenerationOptions) ExecuteTemplate() error {
log.Printf("error closing output: %v\n", err)
}
}()
return tmpl.ExecuteTemplate(opts.Output, opts.InputFile, opts.Config)
return tmpl.Option("missingkey=error").ExecuteTemplate(opts.Output, opts.InputFile, opts.Config)
}
2 changes: 1 addition & 1 deletion tooling/templatize/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (cp *configProviderImpl) loadConfig(cloud, deployEnv string) (*VariableOver
}

var tmplBytes bytes.Buffer
if err := tmpl.Execute(&tmplBytes, vars); err != nil {
if err := tmpl.Option("missingkey=error").Execute(&tmplBytes, vars); err != nil {
return nil, err
}

Expand Down
16 changes: 8 additions & 8 deletions tooling/templatize/testdata/helm.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# copy from maestro/Makefile#L14
deploy-server:
TENANT_ID="{{index . "tenantId"}}"
REGION_RG="{{index . "region_resourcegroup"}}"
EVENTGRID_NS="{{index . "region_eventgrid_namespace"}}"
MAESTRO_KV="{{index . "region_maestro_keyvault"}}"
SERVICE_RG="{{index . "svc_resourcegroup"}}"
AKS="{{index . "aks_name"}}"
MAESTRO_MI="{{index . "maestro_msi"}}"
HELM_CHART="{{index . "maestro_helm_chart"}}"
TENANT_ID="{{ .tenantId }}"
REGION_RG="{{ .region_resourcegroup }}"
EVENTGRID_NS="{{ .region_eventgrid_namespace }}"
MAESTRO_KV="{{ .region_maestro_keyvault }}"
SERVICE_RG="{{ .svc_resourcegroup }}"
AKS="{{ .aks_name }}"
MAESTRO_MI="{{ .maestro_msi }}"
HELM_CHART="{{ .maestro_helm_chart }}"

EVENTGRID_HOSTNAME=$(az event namespace show -g "${REGION_RG}" -n "${EVENTGRID_NS}" --query "properties.topicSpacesConfiguration.hostname")
MAESTRO_MI_CLIENT_ID=$(az identity show -g "${SERVICE_RG}" -n "${MAESTRO_MI}" --query "clientId")
Expand Down
4 changes: 2 additions & 2 deletions tooling/templatize/testdata/test.bicepparam
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ param baseDNSZoneName = 'hcp.osadev.cloud'
param baseDNSZoneResourceGroup = 'global'

// maestro
param maestroKeyVaultName = '{{index . "region_maestro_keyvault"}}'
param maestroEventGridNamespacesName = '{{index . "region_eventgrid_namespace"}}'
param maestroKeyVaultNamea = '{{ .region_maestro_keyvault }}'
param maestroEventGridNamespacesName = '{{ .region_eventgrid_namespace }}'
param maestroEventGridMaxClientSessionsPerAuthName = 4

// These parameters are always overriden in the Makefile
Expand Down

0 comments on commit 98621ba

Please sign in to comment.