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

Skip to content

feat: Add form to modify managed Template variables #6257

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 26 commits into from
Mar 2, 2023

Conversation

mtojek
Copy link
Member

@mtojek mtojek commented Feb 17, 2023

Related: #5980

As this PR is growing, I will keep introducing follow-ups in separate PRs.

This PR introduces a form to modify the Terraform variables. Once a user submits the form, the browser will check the status of the provisioning job every 2 secs, and if the job succeeds, it will redirect to the template view.

Button:
Screenshot 2023-03-01 at 17 47 41

Sample form:
Screenshot 2023-03-01 at 15 52 50

Template:

provider "coder" {
  feature_use_managed_variables = "true"
}

variable "any_dotfiles" {
  description = "Do we have any dotfiles?"
  type        = bool
  default     = false
}

variable "dotfiles_path" {
  description = "Dotfiles path"
  type        = string
  default     = "~/"
}

variable "lucky_number" {
  description = "This is lucky number."
  type        = number
  default     = 33
}

variable "region" {
  description = "This is region."
  type        = string
}

variable "secret_field" {
  description = "This is secret field."
  type        = string
  sensitive   = true
}

Follow-ups:

  • Create a template: prepare a form with TF variables.
  • Create a template: example workflow

@github-actions
Copy link

This Pull Request is becoming stale. In order to minimize WIP, prevent merge conflicts and keep the tracker readable, I'm going close to this PR in 3 days if there isn't more activity.

@github-actions github-actions bot added the stale This issue is like stale bread. label Feb 25, 2023
@github-actions github-actions bot removed the stale This issue is like stale bread. label Feb 28, 2023
@mtojek mtojek changed the title feat: Update site to handle managed Template variables feat: Add form to modify managed Template variables Mar 1, 2023
@mtojek mtojek marked this pull request as ready for review March 1, 2023 17:29
@mtojek mtojek requested a review from kylecarbs March 1, 2023 17:29
@mtojek mtojek requested a review from BrunoQuaresma March 1, 2023 17:29
@BrunoQuaresma
Copy link
Collaborator

What are the diff between this form and the settings form?

@mtojek
Copy link
Member Author

mtojek commented Mar 1, 2023

What are the diff between this form and the settings form?

  1. Custom field component: TemplateVariableField with required and sensitive support.
  2. Submition workflow similar to "create template": create template version, busy-wait loop, then assign the template version to the template.
  3. Variables form contains only string, number, and bool fields without validation (only check if field is required).

I guess that this are the most important parts.

@BrunoQuaresma
Copy link
Collaborator

Why create a diff form for the variables and not use them in the settings one?

@mtojek
Copy link
Member Author

mtojek commented Mar 1, 2023

I'm not sure if I understand your question. Could you please elaborate a bit more?

I created the new form/page as there were many changes between both, and variables are submitted using a different endpoint than Template Settings. Variables are strictly Terraform vars.

const permissions = usePermissions()

if (!template || !templatePermissions) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think those only should be loaded in the page form. You can also use react-query for them. Way easier IMO. But not a blocker.

}
const organizationId = useOrganizationId()
const navigate = useNavigate()
const [state, send] = useMachine(templateVariablesMachine, {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I said that previously but maybe would be interesting to use react-query but no big deal.

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 think that I will leave it for further improvement as I'd like to deliver this PR as is, as it just works. I will try to frame more time for react-query to play with it.

Copy link
Collaborator

@BrunoQuaresma BrunoQuaresma left a comment

Choose a reason for hiding this comment

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

There are a few things in the FE we could improve but not blockers.

About react-query, you can see how we are using it here

const { data, error, queryKey } = useWorkspacesData({
...pagination,
...filter,
})

@mtojek mtojek merged commit 67db36b into coder:main Mar 2, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Mar 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants