Skip to content

Conversation

@sheppard-brandon-bah
Copy link
Contributor

Summary
This PR restructures the repository to support usage with the OpenTofu CLI, ensuring compatibility following Terraform’s transition to the BUSL license.

Background
With the shift from Terraform to OpenTofu, our team — and many others — are adopting OpenTofu to remain aligned with open-source licensing standards. However, OpenTofu enforces stricter parsing behavior across directories, which has introduced issues in the current repo layout.

Problem
The current structure of the repository places all .tf files (including the core module files, test files, and usage examples) in the root directory or subdirectories of the root. When executing OpenTofu commands (e.g., tofu plan, tofu apply) from the root, unrelated .tf files in /test and /examples folders are being picked up and interpreted as part of the configuration.

This results in plan/apply failures due to:

  • Unused or malformed test resources
  • Conflicts between unrelated configurations
  • Errors in examples not intended to be part of actual deployments

Solution
To resolve this, the PR introduces a new folder structure that isolates the core Bedrock Agent module files into a dedicated directory, /module.

All Terraform source files that comprise the main module are moved into this folder. This ensures that:

  • Only module-specific code is processed by OpenTofu
  • Test and example .tf files are excluded from the plan/apply context

Changes

  • Moved all Bedrock Agent Terraform module files into /module
  • Left test and example directories at the root, untouched

Let me know if you'd like to explore a different approach or if you have a preferred convention for module pathing.

Thanks!

@scottschreckengaust
Copy link
Collaborator

Thank you. We will review.

@sheppard-brandon-bah sheppard-brandon-bah changed the title Restructure Module for OpenTofu Compatibility by Isolating Module Files Restructure Module for Compatibility with the Crossplane Terraform & OpenTofu Providers Apr 21, 2025
@sheppard-brandon-bah
Copy link
Contributor Author

Hello, been out for a bit and just getting back to it. But after getting a chance to poke at this a bit more, turns out this is not an issue directly with OpenTofu or Terraform. If applying the module pulled from the Terraform registry, all works as expected with both tools.

For us, the issue arises when needing to use the Crossplane Terraform or OpenTofu providers to deploy using this module. Both of these providers only support the use of git-based remote modules, as shown here starting on line 12, https://github.com/upbound/provider-terraform/blob/main/examples/workspace-remote.yaml.

To use this module with our Crossplane setup, we currently have to maintain a fork of this repo with the module files isolated in a module folder. It would be ideal to have these changes incorporated into this parent repo so we can avoid the overhead of maintaining the fork and instead, use this repo directly.

Hope this extra context helps! Please do let me know if any further questions or issues I can address. Thank you!

@alexa-perlov
Copy link
Collaborator

Hi @sheppard-brandon-bah – I am hesitant to move all the files into a new path as this will be a breaking change. For git based sourcing, are you doing something like source = "git@github.com:aws-ia/terraform-aws-bedrock.git?ref=v0.0.19" ?

@sheppard-brandon-bah
Copy link
Contributor Author

@alexa-perlov close, like this...

git::https://github.com/aws-ia/terraform-aws-bedrock.git//.?ref=v0.0.19

The Terraform CLI does not mind running against the root of the repo like this but OpenTofu and Terragrunt CLIs both pickup files in the /examples and /tests directories which cause them to error out.

@alexa-perlov
Copy link
Collaborator

hmm, interesting... I will look into this because I'm not sure why you're seeing this behavior.

@sheppard-brandon-bah
Copy link
Contributor Author

Thank you and please do let me know how I can assist in this!

@alexa-perlov
Copy link
Collaborator

let me know if you're able to find another way to integrate into your system that doesn't involve moving the main module files into a new path! I'll keep you updated on what I find... thank you for your patience!

@sheppard-brandon-bah
Copy link
Contributor Author

The only thing that came to mind, is being able to provide a list of excluded directories to the tofu/terragrunt plan and apply commands. I have looked and it does not look like this functionality is available.

Without being able to exclude those directories (test and examples in this case), the plan and apply commands pickup the .tf files in those directories and try to include them in part of the deployment plan. At least this has been my experience.

But I will keep thinking on this and I look forward to hearing what you find, thank you!

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.

3 participants