Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(provisioner/terraform/tfparse): implement WorkspaceTagDefaultsFromFile #15236

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

Merged
merged 14 commits into from
Nov 14, 2024

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented Oct 25, 2024

Relates to #15087 and #15427

Adds functionality to provisioner/terraform/tfparse to extract the default values for a coder_workspace_tags data source from a given file.

A subsequent PR will hook this into the template creation flow.

Update: I've since found that Trivy uses its own Terraform parser to perform static analysis.
This will allow us to support things like function calls in future.
For now, I'm keeping our existing approach but I would like to leverage this package in future.

@johnstcn johnstcn self-assigned this Oct 25, 2024
@johnstcn johnstcn requested review from Emyrk and f0ssel October 25, 2024 18:06
Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

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

I don't have familiarity with the terraform parse library. I'll need to spend some time playing with this to get a better review.

@github-actions github-actions bot added the stale This issue is like stale bread. label Nov 2, 2024
@mtojek mtojek self-requested a review November 4, 2024 09:02
@github-actions github-actions bot removed the stale This issue is like stale bread. label Nov 5, 2024
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

I focused on high level of this solution.

What I like here:

  • we're trying to construct the build context first and use it as a source of truth for ParseExpression
  • There is a potential of introducing a "super parser" that can natively guess (support) placeholder values for provisioner tags

Open questions:

  • how does it work when coder_parameter does not have a default value? maybe I missed it in code
  • is there any risk of breaking the build context if a template author pushes another template version with renamed parameters or variables?
  • when exactly this solution does not work?

I'm happy to discuss this solution in 1-1. I think you're on the right path but we may need to patch some loopholes.

@johnstcn
Copy link
Member Author

johnstcn commented Nov 6, 2024

Thanks for all the comments! I'm going to take a pass now and address them.

@johnstcn johnstcn force-pushed the cj/15087-extract-workspace-tags branch from 9214bd4 to 3db3e6b Compare November 11, 2024 14:04
@johnstcn johnstcn requested review from mtojek and Emyrk November 11, 2024 14:04
}

if _, ok := resContent.Attributes["default"]; !ok {
defaultsM[dataResource.Name] = ""
Copy link
Member

Choose a reason for hiding this comment

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

Should we specify if the default is "" or actually not present?

This would make a tag "" if no default is provided. Should we error instead? Is that a breaking change if we error?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point. The whole reason for doing this is to make sure that we have some default defined for the workspace_tags data source. So it probably should be an error.

Copy link
Member Author

Choose a reason for hiding this comment

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

Upon closer inspection, this is only for parsing coder_parameters. It is legit to have an empty default value for a coder_parameter. We do not want to block this behaviour.
However, when using that coder_parameter as a transitive source for a coder_workspace_tags value, we want to ensure that that tag is set. This is checked in WorkspaceTagDefaults and has its own corresponding unit test.

@johnstcn johnstcn requested a review from Emyrk November 14, 2024 11:35
@johnstcn johnstcn requested a review from mtojek November 14, 2024 11:35
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

I assume this to be in good shape to get merged and play with it 👍 Nice work!

// parseHCLFiler is the actual interface of *hclparse.Parser we use
// to parse HCL. This is extracted to an interface so we can more
// easily swap this out for an alternative implementation later on.
type parseHCLFiler interface {
Copy link
Member

Choose a reason for hiding this comment

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

nit: funny name :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I know :D I'm just following the Go convention of <function name>er.

@johnstcn johnstcn merged commit bebc38e into main Nov 14, 2024
26 checks passed
@johnstcn johnstcn deleted the cj/15087-extract-workspace-tags branch November 14, 2024 12:24
johnstcn added a commit that referenced this pull request Nov 25, 2024
…#15578)

Relates to #15087 and
#15427

- Extracts provisioner job tags from `coder_workspace_tags` on template
version creation using `provisioner/terraform/tfparse` added in
#15236
- Drops a WARN log in coderd if no matching provisioners found.
- Also drops a warning message in the CLI if no provisioners are found.
- To support both CLI and UI warnings, added a
`codersdk.MatchedProvisioners` struct to the `TemplateVersion` response
containing details of how many provisioners were around at the time of
the insert.

Co-authored-by: Mathias Fredriksson <[email protected]>
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.

3 participants