From c0ebfb8101700d6e6300954c2efcf2077c690e01 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Thu, 7 Sep 2023 14:48:59 +0200 Subject: [PATCH] Fix conversion of job parameters (#744) ## Changes Another example of singular/plural conversion. Longer term solution is we do a full sweep of the type using reflection to make sure we cover all fields. ## Tests Unit test passes. --- bundle/deploy/terraform/convert.go | 6 ++++++ bundle/deploy/terraform/convert_test.go | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/bundle/deploy/terraform/convert.go b/bundle/deploy/terraform/convert.go index 41bde91d8..cd480c898 100644 --- a/bundle/deploy/terraform/convert.go +++ b/bundle/deploy/terraform/convert.go @@ -90,6 +90,12 @@ func BundleToTerraform(config *config.Root) (*schema.Root, bool) { Tag: git.GitTag, } } + + for _, v := range src.Parameters { + var t schema.ResourceJobParameter + conv(v, &t) + dst.Parameter = append(dst.Parameter, t) + } } tfroot.Resource.Job[k] = &dst diff --git a/bundle/deploy/terraform/convert_test.go b/bundle/deploy/terraform/convert_test.go index 4d912fbe0..34a65d70d 100644 --- a/bundle/deploy/terraform/convert_test.go +++ b/bundle/deploy/terraform/convert_test.go @@ -29,6 +29,16 @@ func TestConvertJob(t *testing.T) { GitProvider: jobs.GitProviderGitHub, GitUrl: "https://github.com/foo/bar", }, + Parameters: []jobs.JobParameterDefinition{ + { + Name: "param1", + Default: "default1", + }, + { + Name: "param2", + Default: "default2", + }, + }, }, } @@ -44,6 +54,9 @@ func TestConvertJob(t *testing.T) { assert.Equal(t, "my job", out.Resource.Job["my_job"].Name) assert.Len(t, out.Resource.Job["my_job"].JobCluster, 1) assert.Equal(t, "https://github.com/foo/bar", out.Resource.Job["my_job"].GitSource.Url) + assert.Len(t, out.Resource.Job["my_job"].Parameter, 2) + assert.Equal(t, "param1", out.Resource.Job["my_job"].Parameter[0].Name) + assert.Equal(t, "param2", out.Resource.Job["my_job"].Parameter[1].Name) assert.Nil(t, out.Data) }