Skip to content

Allow terraform init when only test files are present in directory#36429

Merged
dsa0x merged 5 commits intomainfrom
sams/tf-init-test-no-config
Feb 6, 2025
Merged

Allow terraform init when only test files are present in directory#36429
dsa0x merged 5 commits intomainfrom
sams/tf-init-test-no-config

Conversation

@dsa0x
Copy link
Copy Markdown
Member

@dsa0x dsa0x commented Feb 5, 2025

Fixes #35040

Terraform init is largely a no-op when there is no terraform configuration. However, since we allow users to run terraform test inside a directory which itself may not have configuration, this PR will allow terraform init to proceed.

Target Release

1.11.x

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

@dsa0x dsa0x force-pushed the sams/tf-init-test-no-config branch from a8c22cc to 10f56fc Compare February 5, 2025 09:31
@dsa0x dsa0x marked this pull request as ready for review February 5, 2025 10:01
@dsa0x dsa0x requested a review from a team as a code owner February 5, 2025 10:01
Co-authored-by: Sarah French <15078782+SarahFrench@users.noreply.github.com>
SarahFrench
SarahFrench previously approved these changes Feb 5, 2025
Copy link
Copy Markdown
Member

@SarahFrench SarahFrench left a comment

Choose a reason for hiding this comment

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

From looking through this PR I'm happy that it's addressing the issue, but happy for merging to wait for a +1 from Liam

var diags tfdiags.Diagnostics

empty, err := configs.IsEmptyDir(configPath)
empty, err := configs.IsEmptyDir(configPath, "")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We do also load providers from the testing files - should we also include the testing directory here as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh Yeah. Sounds goog 👍

@dsa0x dsa0x merged commit 7f29df9 into main Feb 6, 2025
@dsa0x dsa0x deleted the sams/tf-init-test-no-config branch February 6, 2025 08:20
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 9, 2025

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can terraform init fully initialize (for tests) if no .tf files exist the current working directory?

3 participants