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

Add moved block into terraform schema #2318

Merged
merged 5 commits into from
Mar 1, 2023
Merged

Conversation

lyonsden
Copy link
Contributor

Adding moved as a valid block type into the terraformSchemaV012 schema to prevent a silent failure.

Previous behavior would result in "no cloud resources were detected" if there was a moved declaration in the terraform file. By adding it to the schema normal processing is allowed to continue.

This block has no impact on the cost calculations so no additional processing is necessary.

Copy link
Contributor

@hugorut hugorut left a comment

Choose a reason for hiding this comment

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

Thanks for finding this @lyonsden, great work!

Comment on lines 34 to 38
moved {
from = aws_lambda_function.hola_mundo
to = aws_lambda_function.hello_world
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
moved {
from = aws_lambda_function.hola_mundo
to = aws_lambda_function.hello_world
}

can we remove this from the examples/terraform file as this is used as a getting started point for many users.

Perhaps we can add this moved block to cmd/infracost/testdata/breakdown_multi_project_autodetect/dev/main.tf instead as this will be covered by one of the breadkdown tests.

But in this case it would need to be >

moved {
  from = aws_instance.foo
  to   = aws_lambda_function.web_app
}

@@ -49,6 +49,9 @@ var (
Type: "data",
LabelNames: []string{"type", "name"},
},
{
Copy link
Contributor

Choose a reason for hiding this comment

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

I think maybe a better solution would be to change loadBlocksFromFile to use PartialContent over Content, as we don't actually support type moved

contents, diags := file.hclFile.Body.Content(schema)

e.g:

	contents, _, diags := file.hclFile.Body.PartialContent(schema)
	if diags != nil && diags.HasErrors() {
		return nil, diags
	}

PartialContent is like Content except that it permits the configuration to contain additional blocks or attributes not specified in the schema. This means we don't break in the future on new block type additions.

@CLAassistant
Copy link

CLAassistant commented Feb 28, 2023

CLA assistant check
All committers have signed the CLA.

@hugorut hugorut self-requested a review March 1, 2023 10:14
Copy link
Contributor

@hugorut hugorut left a comment

Choose a reason for hiding this comment

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

LGTM

@hugorut hugorut merged commit 9b06946 into infracost:master Mar 1, 2023
@tim775
Copy link
Member

tim775 commented Mar 7, 2023

@lyonsden @Clete2 this is released in v0.10.18

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.

None yet

4 participants