Skip to content

Commit

Permalink
feat: Create Waypoint resources with module ID.
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The no-code module ID is required when creating a template or add-on definition for Waypoint.
  • Loading branch information
paladin-devops committed Dec 3, 2024
1 parent f1fa1c4 commit eaf3830
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 24 deletions.
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
32 changes: 22 additions & 10 deletions internal/commands/waypoint/add-ons/definitions/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,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",
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 +183,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
2 changes: 2 additions & 0 deletions internal/commands/waypoint/add-ons/definitions/create_test.go
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
10 changes: 10 additions & 0 deletions internal/commands/waypoint/templates/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,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 +218,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

0 comments on commit eaf3830

Please sign in to comment.