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

Create Waypoint resources with module ID #198

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/198.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:breaking-change
waypoint: Require no-code module ID for creating templates and add-on defintiions.
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-version v1.7.0
github.com/hashicorp/hcl/v2 v2.23.0
github.com/hashicorp/hcp-sdk-go v0.123.0
github.com/hashicorp/hcp-sdk-go v0.125.0
github.com/lithammer/dedent v1.1.0
github.com/manifoldco/promptui v0.9.0
github.com/mitchellh/cli v1.1.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKe
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/hcl/v2 v2.23.0 h1:Fphj1/gCylPxHutVSEOf2fBOh1VE4AuLV7+kbJf3qos=
github.com/hashicorp/hcl/v2 v2.23.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA=
github.com/hashicorp/hcp-sdk-go v0.123.0 h1:kUf/kSCVkQ4XXyny8GUyUWjvIIIanGRRkhRmgj2lC+4=
github.com/hashicorp/hcp-sdk-go v0.123.0/go.mod h1:vQ4fzdL1AmhIAbCw+4zmFe5Hbpajj3NvRWkJoVuxmAk=
github.com/hashicorp/hcp-sdk-go v0.125.0 h1:pak7lGeNmoQTR5Dkx+CxYF6xLjn1UJ4XPg43ldyle+Y=
github.com/hashicorp/hcp-sdk-go v0.125.0/go.mod h1:vQ4fzdL1AmhIAbCw+4zmFe5Hbpajj3NvRWkJoVuxmAk=
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type AddOnDefinitionOpts struct {
TerraformCloudProjectID string
TerraformExecutionMode string
TerraformAgentPoolID string
TerraformNoCodeModuleID string

VariableOptionsFile string

Expand Down
33 changes: 23 additions & 10 deletions internal/commands/waypoint/add-ons/definitions/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ $ hcp waypoint add-ons definitions create -n=my-add-on-definition \
-d="My Add-on Definition description." \
--readme-markdown-template-file="README.tpl" \
--tfc-no-code-module-source="app.terraform.io/hashicorp/dir/template" \
--tf-no-code-module-id="nocode-123456" \
--tfc-project-name="my-tfc-project" \
--tfc-project-id="prj-123456" \
-l=label1 \
Expand Down Expand Up @@ -135,6 +136,15 @@ $ hcp waypoint add-ons definitions create -n=my-add-on-definition \
"when the execution mode is set to 'agent'.",
Value: flagvalue.Simple("", &opts.TerraformAgentPoolID),
},
{
Name: "tf-no-code-module-id",
Copy link
Contributor

@HenryEstberg HenryEstberg Dec 13, 2024

Choose a reason for hiding this comment

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

Totally nonblocking and more of just a general observation about the Waypoint CLI commands:

With flags like this that have longer names, typing them out can be fairly frustrating in my experience when you have to enter a bunch of them. To alleviate this, I think a useful pattern for us to adopt would be adding many more "shorthand" options to these flags.

Not necessarily something you have to do here as it might be useful to do en masse if we go in this direction, but reading your PR reminded me of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that having shorthand flags for these longer-named flags would be nice shortcuts for users who frequent the CLI!

DisplayValue: "TF_NO_CODE_MODULE_ID",
Description: "The ID of the Terraform no-code module to use for " +
"running Terraform operations. This is in the format " +
"of 'nocode-<ID>'.",
Value: flagvalue.Simple("", &opts.TerraformNoCodeModuleID),
Required: true,
},
},
},
}
Expand Down Expand Up @@ -174,17 +184,20 @@ func addOnDefinitionCreate(opts *AddOnDefinitionOpts) error {
&waypoint_service.WaypointServiceCreateAddOnDefinitionParams{
NamespaceID: ns.ID,
Body: &models.HashicorpCloudWaypointWaypointServiceCreateAddOnDefinitionBody{
Name: opts.Name,
Summary: opts.Summary,
Description: opts.Description,
ReadmeMarkdownTemplate: readmeTpl,
Labels: opts.Labels,
TerraformCloudWorkspaceDetails: &models.HashicorpCloudWaypointTerraformCloudWorkspaceDetails{
Name: opts.TerraformCloudProjectName,
ProjectID: opts.TerraformCloudProjectID,
AddOnDefinition: &models.HashicorpCloudWaypointAddOnDefinition{
Name: opts.Name,
Summary: opts.Summary,
Description: opts.Description,
ReadmeMarkdownTemplate: readmeTpl,
Labels: opts.Labels,
TerraformCloudWorkspaceDetails: &models.HashicorpCloudWaypointTerraformCloudWorkspaceDetails{
Name: opts.TerraformCloudProjectName,
ProjectID: opts.TerraformCloudProjectID,
},
ModuleSource: opts.TerraformNoCodeModuleSource,
VariableOptions: variables,
ModuleID: opts.TerraformNoCodeModuleID,
},
ModuleSource: opts.TerraformNoCodeModuleSource,
VariableOptions: variables,
},
Context: opts.Ctx,
}, nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestCmdAddOnDefinitionCreate(t *testing.T) {
"--tf-execution-mode", "agent",
"--tf-agent-pool-id", "pool-abc123",
"--variable-options-file", "vars.hcl",
"--tf-no-code-module-id", "nocode-abc123",
},
Expect: &AddOnDefinitionOpts{
Name: "cli-test",
Expand All @@ -69,6 +70,7 @@ func TestCmdAddOnDefinitionCreate(t *testing.T) {
TerraformExecutionMode: "agent",
TerraformAgentPoolID: "pool-abc123",
VariableOptionsFile: "vars.hcl",
TerraformNoCodeModuleID: "nocode-abc123",
},
},
}
Expand Down
1 change: 1 addition & 0 deletions internal/commands/waypoint/add-ons/definitions/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func addOnDefinitionRead(opts *AddOnDefinitionOpts) error {
format.NewField("Execution Mode", "{{ .TfExecutionMode }}"),
format.NewField("Agent Pool ID", "{{ .TfAgentPoolID }}"),
format.NewField("Variable Options", optionNamesStr),
format.NewField("Terraform No-code Module ID", "{{ .ModuleID }}"),
}

return opts.Output.Display(format.NewDisplayer(addOnDef, format.Pretty, fields))
Expand Down
22 changes: 12 additions & 10 deletions internal/commands/waypoint/add-ons/definitions/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,19 @@ func addOnDefinitionUpdate(opts *AddOnDefinitionOpts) error {
Context: opts.Ctx,
ExistingAddOnDefinitionName: opts.Name,
Body: &models.HashicorpCloudWaypointWaypointServiceUpdateAddOnDefinitionBody{
Summary: opts.Summary,
Description: opts.Description,
ReadmeMarkdownTemplate: readmeTpl,
Labels: opts.Labels,
TerraformCloudWorkspaceDetails: &models.HashicorpCloudWaypointTerraformCloudWorkspaceDetails{
ProjectID: opts.TerraformCloudProjectID,
Name: opts.TerraformCloudProjectName,
AddOnDefinition: &models.HashicorpCloudWaypointAddOnDefinition{
Summary: opts.Summary,
Description: opts.Description,
ReadmeMarkdownTemplate: readmeTpl,
Labels: opts.Labels,
TerraformCloudWorkspaceDetails: &models.HashicorpCloudWaypointTerraformCloudWorkspaceDetails{
ProjectID: opts.TerraformCloudProjectID,
Name: opts.TerraformCloudProjectName,
},
TfExecutionMode: opts.TerraformExecutionMode,
TfAgentPoolID: opts.TerraformAgentPoolID,
VariableOptions: variables,
},
TfExecutionMode: opts.TerraformExecutionMode,
TfAgentPoolID: opts.TerraformAgentPoolID,
VariableOptions: variables,
},
}, nil,
)
Expand Down
11 changes: 11 additions & 0 deletions internal/commands/waypoint/templates/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ $ hcp waypoint templates create -n=my-template \
-d="My Template Description" \
--readme-markdown-template-file "README.tpl" \
--tfc-no-code-module-source="app.terraform.io/hashicorp/dir/template" \
--tf-no-code-module-id="nocode-123456" \
--tfc-project-name="my-tfc-project" \
--tfc-project-id="prj-123456" \
-l="label1" \
Expand Down Expand Up @@ -146,6 +147,15 @@ $ hcp waypoint templates create -n=my-template \
"when the execution mode is set to 'agent'.",
Value: flagvalue.Simple("", &opts.TerraformAgentPoolID),
},
{
Name: "tf-no-code-module-id",
DisplayValue: "TF_NO_CODE_MODULE_ID",
Description: "The ID of the Terraform no-code module to use for " +
"running Terraform operations. This is in the format " +
"of 'nocode-<ID>'.",
Value: flagvalue.Simple("", &opts.TerraformNoCodeModuleID),
Required: true,
},
},
},
}
Expand Down Expand Up @@ -209,6 +219,7 @@ func templateCreate(opts *TemplateOpts) error {
VariableOptions: variables,
TfExecutionMode: opts.TerraformExecutionMode,
TfAgentPoolID: opts.TerraformAgentPoolID,
ModuleID: opts.TerraformNoCodeModuleID,
},
},
Context: opts.Ctx,
Expand Down
5 changes: 5 additions & 0 deletions internal/commands/waypoint/templates/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestCmdTemplateCreate(t *testing.T) {
"--readme-markdown-template-file", "readme_test.txt",
"--tf-execution-mode", "agent",
"--tf-agent-pool-id", "pool-abc123",
"--tf-no-code-module-id", "nocode-abc123",
},
Expect: &TemplateOpts{
Name: "cli-test",
Expand All @@ -69,6 +70,7 @@ func TestCmdTemplateCreate(t *testing.T) {
Tags: map[string]string{"cli": "true"},
TerraformExecutionMode: "agent",
TerraformAgentPoolID: "pool-abc123",
TerraformNoCodeModuleID: "nocode-abc123",
},
},
{
Expand All @@ -87,6 +89,7 @@ func TestCmdTemplateCreate(t *testing.T) {
"-l", "cli",
"-t", "cli=true",
"--variable-options-file", "variable_options.hcl",
"--tf-no-code-module-id", "nocode-abc123",
},
Expect: &TemplateOpts{
Name: "cli-test",
Expand All @@ -99,6 +102,7 @@ func TestCmdTemplateCreate(t *testing.T) {
VariableOptionsFile: "variable_options.hcl",
Labels: []string{"cli"},
Tags: map[string]string{"cli": "true"},
TerraformNoCodeModuleID: "nocode-abc123",
},
},
}
Expand Down Expand Up @@ -142,6 +146,7 @@ func TestCmdTemplateCreate(t *testing.T) {
r.Equal(c.Expect.VariableOptionsFile, tplOpts.VariableOptionsFile)
r.Equal(c.Expect.Labels, tplOpts.Labels)
r.Equal(c.Expect.Tags, tplOpts.Tags)
r.Equal(c.Expect.TerraformNoCodeModuleID, tplOpts.TerraformNoCodeModuleID)
}
})
}
Expand Down
3 changes: 2 additions & 1 deletion internal/commands/waypoint/templates/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ func templateRead(opts *TemplateOpts) error {
format.NewField("Labels", "{{ .Labels }}"),
format.NewField("Readme Template", "{{ .ReadmeTemplate }}"),
format.NewField("Tags", "{{ .Tags}}"),
format.NewField("Terraform Nocode Source", "{{ .ModuleSource}}"),
format.NewField("Terraform No-Code Module Source", "{{ .ModuleSource}}"),
format.NewField("Execution Mode", "{{ .TfExecutionMode}}"),
format.NewField("Agent Pool ID", "{{ .TfAgentPoolID}}"),
format.NewField("Variable Options", optionNamesStr),
format.NewField("Terraform No-code Module ID", "{{ .ModuleID }}"),
}

// Display the created project
Expand Down
1 change: 1 addition & 0 deletions internal/commands/waypoint/templates/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type TemplateOpts struct {
TerraformCloudProjectID string
TerraformExecutionMode string
TerraformAgentPoolID string
TerraformNoCodeModuleID string

VariableOptionsFile string

Expand Down
Loading
Loading