Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(coderd/wsbuilder): correctly evaluate dynamic workspace tag values#15897

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
johnstcn merged 10 commits intomainfromcj/fix-gh-15894
Dec 17, 2024

Conversation

johnstcn
Copy link
Member

@johnstcnjohnstcn commentedDec 17, 2024
edited
Loading

Relates to#15894:

  • Addscoderdenttest.NewExternalProvisionerDaemonTerraform
  • Adds integration-style test coverage for creating a workspace withcoder_workspace_tags specified inmain.tf
  • Modifiescoderd/wsbuilder to fetch template version variables and include them in eval context for evaluatingcoder_workspace_tags

@johnstcnjohnstcn changed the titleCj/fix gh 15894fix(coderd/wsbuilder): correctly evaluate dynamic workspace tag valuesDec 17, 2024
@johnstcnjohnstcn marked this pull request as ready for reviewDecember 17, 2024 18:07
@github-actionsGitHub Actions
Copy link

github-actionsbot commentedDec 17, 2024
edited
Loading


✔️ PR 15897 Updated successfully.
🚀 Access the credentialshere.

cc:@johnstcn

github-actions[bot] reacted with rocket emoji

Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for adding this functionality!

}

func (b*Builder)getTemplateVersionVariables() ([]database.TemplateVersionVariable,error) {
ifb.templateVersionVariables!=nil {
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 use a mutex/atomic here?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I don't think the builder is meant to be safe for concurrent use.
Maybe good for a follow-up though, as it could trip someone else up in future.

Copy link
Member

Choose a reason for hiding this comment

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

Yea, we do this pattern everywhere. It's all single threaded

johnstcn reacted with thumbs up emoji
// here. This is the default provisioner for tests and should be fine for
// most use cases. If you need to test terraform-specific behaviors, use
// NewExternalProvisionerDaemonTerraform instead.
funcNewExternalProvisionerDaemon(t testing.TB,client*codersdk.Client,org uuid.UUID,tagsmap[string]string) io.Closer {
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion:NewExternalEchoProvisionerDaemon?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I can rename in a follow-up! It would be a big diff :D

Copy link
Member

Choose a reason for hiding this comment

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

Yea, I think I wrote the original name. I don't think I even considered expected non-echo type in tests 😄

Copy link
Member

@mtojekmtojek left a comment

Choose a reason for hiding this comment

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

LGTM!

// here. This is the default provisioner for tests and should be fine for
// most use cases. If you need to test terraform-specific behaviors, use
// NewExternalProvisionerDaemonTerraform instead.
funcNewExternalProvisionerDaemon(t testing.TB,client*codersdk.Client,org uuid.UUID,tagsmap[string]string) io.Closer {
Copy link
Member

Choose a reason for hiding this comment

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

Yea, I think I wrote the original name. I don't think I even considered expected non-echo type in tests 😄

Comment on lines +367 to +373
assert.NoError(t,terraform.Serve(ctx,&terraform.ServeOptions{
BinaryPath:terraformPath,
CachePath:t.TempDir(),
ServeOptions:&provisionersdk.ServeOptions{
Listener:provisionerSrv,
WorkDirectory:t.TempDir(),
},
Copy link
Member

Choose a reason for hiding this comment

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

So this runs real terraform? Does this mean tests can accidentally provision resources?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Yeah, that's the tricky thing if you're not careful. There's no other real way to test this apart from spinning up a Docker container or manual testing, and wereally need some kind of integration test here.

Comment on lines +1425 to +1430
// TestWorkspaceTagsTerraform tests that a workspace can be created with tags.
// This is an end-to-end-style test, meaning that we actually run the
// real Terraform provisioner and validate that the workspace is created
// successfully. The workspace itself does not specify any resources, and
// this is fine.
funcTestWorkspaceTagsTerraform(t*testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Woah, he did it 🤯

This is a super nice test. Slightly concerned with terraform being executed in tests, would be nice if we could lock it down somehow to prevent it allocating any resources.

Copy link
MemberAuthor

@johnstcnjohnstcnDec 17, 2024
edited
Loading

Choose a reason for hiding this comment

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

I could add a hacky check for the patternresource "[^"]+" "[^"]+" and fail. That would at least make folks think twice before hacking it further to allow certain resources.

EDIT: Actually I'm not even sure I could do that right now due to how provisionerd works. Needs some more thinking. For now... ruleguard? 🤷

Copy link
Member

Choose a reason for hiding this comment

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

I don't think ruleguard would be sufficient. I wonder if we can do something to the executable. Run it another userspace with no perms? Configure aHTTP_PROXY that is broken so any external requests fail? I'm not sure 🤷‍♂️

I'm ok if we let this slide for now, since I don't know a good way. Just an unfortunate consequence.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Yeah I think we may need to think about the best way to prevent misuse of this.

@johnstcnjohnstcn merged commitdcf5153 intomainDec 17, 2024
30 checks passed
@johnstcnjohnstcn deleted the cj/fix-gh-15894 branchDecember 17, 2024 21:57
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsDec 17, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@EmyrkEmyrkEmyrk approved these changes

@mafredrimafredrimafredri approved these changes

@mtojekmtojekmtojek approved these changes

@SasSwartSasSwartAwaiting requested review from SasSwart

Assignees

@johnstcnjohnstcn

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

bug: creating a workspace build withworkspace_tags variable fails with error: 'There is no variable named "var"'

4 participants

@johnstcn@mafredri@Emyrk@mtojek

[8]ページ先頭

©2009-2025 Movatter.jp