From 0752be698fe140dadaac961f4ef04fde0d6888b0 Mon Sep 17 00:00:00 2001 From: Mitch Connors Date: Tue, 27 Jun 2023 21:17:09 +0000 Subject: [PATCH] Make main-tf contents exported Signed-off-by: Mitch Connors --- pkg/terraform/files.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/terraform/files.go b/pkg/terraform/files.go index 78adac16..c769f62c 100644 --- a/pkg/terraform/files.go +++ b/pkg/terraform/files.go @@ -130,9 +130,7 @@ type FileProducer struct { features *feature.Flags } -// WriteMainTF writes the content main configuration file that has the desired -// state configuration for Terraform. -func (fp *FileProducer) WriteMainTF() (ProviderHandle, error) { +func (fp *FileProducer) BuildMainTF() map[string]any { // If the resource is in a deletion process, we need to remove the deletion // protection. lifecycle := map[string]any{ @@ -153,7 +151,7 @@ func (fp *FileProducer) WriteMainTF() (ProviderHandle, error) { // Note(turkenh): To use third party providers, we need to configure // provider name in required_providers. providerSource := strings.Split(fp.Setup.Requirement.Source, "/") - m := map[string]any{ + return map[string]any{ "terraform": map[string]any{ "required_providers": map[string]any{ providerSource[len(providerSource)-1]: map[string]string{ @@ -171,6 +169,12 @@ func (fp *FileProducer) WriteMainTF() (ProviderHandle, error) { }, }, } +} + +// WriteMainTF writes the content main configuration file that has the desired +// state configuration for Terraform. +func (fp *FileProducer) WriteMainTF() error { + m := fp.BuildMainTF() rawMainTF, err := json.JSParser.Marshal(m) if err != nil { return InvalidProviderHandle, errors.Wrap(err, "cannot marshal main hcl object")