Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for opentofu #328

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

LucasMrqes
Copy link
Collaborator

@LucasMrqes LucasMrqes commented Sep 13, 2024

This makes it possible to use opentofu instead of terraform. It involves some CRD modifications:

  • Terragrunt configuration is no longer under terraform config in TerraformRepository & Layer spec
  • One can choose between terraform and opentofu as base executor for infra as code in layer and repositories config with spec.terraform.enabled and spec.terragrunt.enabled
  • Validation rules prevent users from setting both parameters to true
  • Layer config overrides Repo config.

Todo:

  • Update CRDs
  • Integrate opentofu to runner
  • Add tests, specifically for parameter merge edge cases
  • Fix test data used in runner & end-to-end tests
  • Update documentation
  • Better, dynamic logging with less hardcoded references to "terraform"

@LucasMrqes LucasMrqes marked this pull request as ready for review September 23, 2024 22:27
Comment on lines +197 to +208
{
"OverrideRepositoryWithLayer",
&configv1alpha1.TerraformRepository{
Spec: configv1alpha1.TerraformRepositorySpec{
OpenTofuConfig: configv1alpha1.OpenTofuConfig{
Version: "1.0.1",
},
},
},
&configv1alpha1.TerraformLayer{},
"1.0.1",
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a duplicate of OnlyRepositoryVersion.
The "correct" OverrideRepositoryWithLayer is a few lines below.

Comment on lines +36 to +37
OpenTofuConfig OpenTofuConfig `json:"opentofu,omitempty"`
TerragruntConfig TerragruntConfig `json:"terragrunt,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We must remember to put these changes as breaking in the next release

ExecPath: filepath.Join(binaryPath, "OpenTofu", baseExecVersion, "tofu"),
}
} else {
return nil, errors.New("Please enable either Terraform or OpenTofu in the repository or layer configuration")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an user forgets to enable Terraform or OpenTofu in their CRDs, it would be better to be informed before a runner is spawned.

It can be more intuitive to the user (searching through runner logs is not obvious), maybe it can be checked by the Layer controller or the Run controller ?

Comment on lines 15 to +16
Terraform *terraform.Terraform
OpenTofu *opentofu.OpenTofu
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can abstract the tool used to have only one property. For Terragrunt, we only need the execution path of the tool.

I see 2 solutions:

  1. We add another function to the TerraformExec interface to obtain the execution path of the tool
  2. We just give a string BaseToolPath to the Terragrunt struct instead of a pointer to an object

@corrieriluca
Copy link
Member

Overall very great Pull Request! 👏
It opens Burrito to the world of OpenTofu 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants