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

Allow evaluation of resources including count and for_each #151

Closed
janritter opened this issue Mar 29, 2022 · 5 comments · Fixed by #160
Closed

Allow evaluation of resources including count and for_each #151

janritter opened this issue Mar 29, 2022 · 5 comments · Fixed by #160
Labels
enhancement New feature or request

Comments

@janritter
Copy link

We have created an internal tflint plugin which checks checks for our naming convention on all resources in a state. With the update to the new v10 plugin sdk I noticed that some resources are skipped when they include for example a count.

In the following example only the aws_eip.two is evaluated:

variable "test" {
  type = number
}

resource "aws_eip" "one" {
  count    = var.test
  vpc      = true
  instance = "i-123456789"
}

resource "aws_eip" "two" {
  vpc      = true
  instance = "i-123456789"
}

aws_eip.one is skipped with the following warning:

16:40:36 runner.go:317: [WARN] Skip walking `aws_eip.one` because it may not be created

I'm getting a list of resources via GetModuleContent, this list doesn't include the skipped resources:

func (r *TerraformMyRule) Check(runner tflint.Runner) error {
	content, err := runner.GetModuleContent(&hclext.BodySchema{
		Blocks: []hclext.BlockSchema{
			{
				Type:       "resource",
				LabelNames: []string{"type", "name"},
			},
		},
	}, nil)

Is there any option to disable this skipping behaviour for specific plugins?

Similar issue in tflint: terraform-linters/tflint#1068

@wata727
Copy link
Member

wata727 commented Mar 29, 2022

Unfortunately, there is currently no way to do that, but we could add an option to control whether GetModuleContent returns resources that aren't created.

// GetModuleContentOption is an option that controls the behavior when getting a module content.
type GetModuleContentOption struct {
// Specify the module to be acquired.
ModuleCtx ModuleCtxType
// Hint is info for optimizing a query. This is an advanced option and it is not intended to be used directly from plugins.
Hint GetModuleContentHint
}

As far as I remember, this should have had the same problem in v0.9. The major API update in v0.10 is just to resolve these problems.

@wata727 wata727 added the enhancement New feature or request label Mar 29, 2022
@janritter
Copy link
Author

Interesting, then I just noticed this by testing the 0.10 update 😄

Adding an option to GetModuleContent sounds like a good idea.

@janritter
Copy link
Author

I updated to the plugin-sdk version 0.11.0 including the new GetModuleContent option.
With the following code snippet, I still get the "Skip walking aws_eip.one because it may not be created` warning":

	content, err := runner.GetModuleContent(
		&hclext.BodySchema{
			Blocks: []hclext.BlockSchema{
				{
					Type:       "resource",
					LabelNames: []string{"type", "name"},
				},
			},
		},
		&tflint.GetModuleContentOption{
			IncludeNotCreated: true,
		},
	)

@wata727
Copy link
Member

wata727 commented May 6, 2022

Are you using it with TFLint v0.36.2? In v0.35, this option is simply ignored.

@janritter
Copy link
Author

Thanks, my TFLint version was outdated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

2 participants