-
Notifications
You must be signed in to change notification settings - Fork 523
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
Conversation
There was a problem hiding this 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!
examples/terraform/main.tf
Outdated
moved { | ||
from = aws_lambda_function.hola_mundo | ||
to = aws_lambda_function.hello_world | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
}
internal/hcl/block.go
Outdated
@@ -49,6 +49,9 @@ var ( | |||
Type: "data", | |||
LabelNames: []string{"type", "name"}, | |||
}, | |||
{ |
There was a problem hiding this comment.
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
infracost/internal/hcl/block.go
Line 987 in 2d4a16f
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Adding
moved
as a valid block type into theterraformSchemaV012
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.