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

Modify regex to detect other legitimate forms of provider block declaration #265

Merged
merged 4 commits into from
Jan 9, 2024

Conversation

bendbennett
Copy link
Contributor

Closes: #264

@bendbennett bendbennett added the bug Something isn't working label Jan 8, 2024
@bendbennett bendbennett requested a review from a team as a code owner January 8, 2024 15:36
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me 🚀

internal/teststep/config.go Outdated Show resolved Hide resolved
@@ -21,7 +21,7 @@ const (
)

var (
providerConfigBlockRegex = regexp.MustCompile(`provider "?[a-zA-Z0-9_-]+"? {`)
providerConfigBlockRegex = regexp.MustCompile(`provider(\s*"[a-zA-Z0-9_-]+"\s*|\s+[a-zA-Z0-9_-]+\s*){`)
terraformConfigBlockRegex = regexp.MustCompile(`terraform {`)
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI: I presume the same whitespace problem can occur with terraform{ as well, although terraform validate may not raise an error and Terraform may instead merge the terraform configuration block... configurations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. I can verify that having duplicate terraform blocks can lead to issues. For example:

        Error: Duplicate required providers configuration
        
          on terraform_plugin_test.tf line 13, in terraform:
          13:   required_providers {
        
        A module may have only one required providers configuration. The required
        providers were previously configured at terraform_plugin_test.tf:3,3-21.
    testing_new.go:80: Error retrieving state, there may be dangling resources: exit status 1

Have modified the regex for detection of terraform block, and updated the tests.

Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

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

awesome! 🚀

@bendbennett bendbennett merged commit 5291d75 into main Jan 9, 2024
26 checks passed
@bendbennett bendbennett deleted the bendbennett/issues-264 branch January 9, 2024 10:04
Copy link

github-actions bot commented Feb 9, 2024

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 Feb 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Modify detection of provider blocks in configuration
3 participants