Skip to content

Commit

Permalink
Make main-tf contents exported
Browse files Browse the repository at this point in the history
  • Loading branch information
therealmitchconnors committed Jun 27, 2023
1 parent 018e640 commit 7ab8c0b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/terraform/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ type FileProducer struct {
fs afero.Afero
}

// 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.
fp.parameters["lifecycle"] = map[string]bool{
Expand All @@ -108,7 +106,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{
Expand All @@ -126,6 +124,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")
Expand Down

0 comments on commit 7ab8c0b

Please sign in to comment.