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

[WAYP-3107] Add module ID to Waypoint resources #1146

Merged
merged 5 commits into from
Dec 19, 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
4 changes: 4 additions & 0 deletions .changelog/1146.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:breaking-change
waypoint: Add new required field for no-code module ID to Waypoint template and
add-on definition resources.
```
1 change: 1 addition & 0 deletions docs/data-sources/waypoint_add_on_definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The Waypoint Add-on Definition data source retrieves information on a given Add-
- `terraform_agent_pool_id` (String) The ID of the Terraform agent pool.
- `terraform_cloud_workspace_details` (Attributes) Terraform Cloud Workspace details. (see [below for nested schema](#nestedatt--terraform_cloud_workspace_details))
- `terraform_execution_mode` (String) The execution mode for the Terraform Cloud workspace.
- `terraform_no_code_module_id` (String) The ID of the Terraform no-code module to use for running Terraform operations
- `terraform_no_code_module_source` (String) Terraform No Code Module source
- `variable_options` (Attributes List) List of variable options for the Add-on Definition. (see [below for nested schema](#nestedatt--variable_options))

Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/waypoint_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The Waypoint Template data source retrieves information on a given Template.
- `terraform_agent_pool_id` (String) Terraform agent pool ID
- `terraform_cloud_workspace_details` (Attributes) Terraform Cloud Workspace details (see [below for nested schema](#nestedatt--terraform_cloud_workspace_details))
- `terraform_execution_mode` (String) Terraform execution mode
- `terraform_no_code_module_id` (String) The ID of the Terraform no-code module to use for running Terraform operations
- `terraform_no_code_module_source` (String) Terraform No Code Module source
- `variable_options` (Attributes List) List of variable options for the template (see [below for nested schema](#nestedatt--variable_options))

Expand Down
1 change: 1 addition & 0 deletions docs/resources/waypoint_add_on_definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Waypoint Add-on Definition resource
- `description` (String) A longer description of the Add-on Definition.
- `name` (String) The name of the Add-on Definition.
- `summary` (String) A short summary of the Add-on Definition.
- `terraform_no_code_module_id` (String) The ID of the Terraform no-code module to use for running Terraform operations. This is in the format of 'nocode-<ID>'.
- `terraform_no_code_module_source` (String) Terraform Cloud no-code Module Source, expected to be in one of the following formats: "app.terraform.io/hcp_waypoint_example/ecs-advanced-microservice/aws" or "private/hcp_waypoint_example/ecs-advanced-microservice/aws".
- `terraform_project_id` (String) The ID of the Terraform Cloud Project to create workspaces in. The ID is found on the Terraform Cloud Project settings page.

Expand Down
1 change: 1 addition & 0 deletions docs/resources/waypoint_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Waypoint Template resource

- `name` (String) The name of the Template.
- `summary` (String) A brief description of the template, up to 110 characters.
- `terraform_no_code_module_id` (String) The ID of the Terraform no-code module to use for running Terraform operations. This is in the format of 'nocode-<ID>'.
- `terraform_no_code_module_source` (String) Terraform Cloud No-Code Module details
- `terraform_project_id` (String) The ID of the Terraform Cloud Project to create workspaces in. The ID is found on the Terraform Cloud Project settings page.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type DataSourceAddOnDefinitionModel struct {

TerraformCloudWorkspace *tfcWorkspace `tfsdk:"terraform_cloud_workspace_details"`
TerraformNoCodeModuleSource types.String `tfsdk:"terraform_no_code_module_source"`
TerraformNoCodeModuleID types.String `tfsdk:"terraform_no_code_module_id"`
TerraformVariableOptions []*tfcVariableOption `tfsdk:"variable_options"`
TerraformExecutionMode types.String `tfsdk:"terraform_execution_mode"`
TerraformAgentPoolID types.String `tfsdk:"terraform_agent_pool_id"`
Expand Down Expand Up @@ -150,6 +151,10 @@ func (d *DataSourceAddOnDefinition) Schema(ctx context.Context, req datasource.S
Computed: true,
Description: "The ID of the Terraform agent pool.",
},
"terraform_no_code_module_id": schema.StringAttribute{
Computed: true,
Description: "The ID of the Terraform no-code module to use for running Terraform operations",
},
},
}
}
Expand Down Expand Up @@ -212,6 +217,9 @@ func (d *DataSourceAddOnDefinition) Read(ctx context.Context, req datasource.Rea
state.Summary = types.StringValue(definition.Summary)
state.Description = types.StringValue(definition.Description)
state.TerraformNoCodeModuleSource = types.StringValue(definition.ModuleSource)
state.TerraformNoCodeModuleID = types.StringValue(definition.ModuleID)
state.TerraformExecutionMode = types.StringValue(definition.TfExecutionMode)
state.TerraformAgentPoolID = types.StringValue(definition.TfAgentPoolID)

if definition.TerraformCloudWorkspaceDetails != nil {
tfcWorkspace := &tfcWorkspace{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestAccWaypointData_Add_On_Definition_basic(t *testing.T) {
Config: testDataAddOnDefinitionConfig(name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "name", name),
resource.TestCheckResourceAttr(dataSourceName, "terraform_no_code_module_id", "nocode-7ZQjQoaPXvzs6Hvp"),
resource.TestCheckResourceAttr(dataSourceName, "terraform_execution_mode", "remote"),
),
},
Expand Down
6 changes: 6 additions & 0 deletions internal/provider/waypoint/data_source_waypoint_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type DataSourceTemplateModel struct {

TerraformCloudWorkspace *tfcWorkspace `tfsdk:"terraform_cloud_workspace_details"`
TerraformNoCodeModuleSource types.String `tfsdk:"terraform_no_code_module_source"`
TerraformNoCodeModuleID types.String `tfsdk:"terraform_no_code_module_id"`
VariableOptions []*tfcVariableOption `tfsdk:"variable_options"`
TerraformExecutionMode types.String `tfsdk:"terraform_execution_mode"`
TerraformAgentPoolID types.String `tfsdk:"terraform_agent_pool_id"`
Expand Down Expand Up @@ -150,6 +151,10 @@ func (d *DataSourceTemplate) Schema(ctx context.Context, req datasource.SchemaRe
Computed: true,
Description: "Terraform agent pool ID",
},
"terraform_no_code_module_id": schema.StringAttribute{
Computed: true,
Description: "The ID of the Terraform no-code module to use for running Terraform operations",
},
},
}
}
Expand Down Expand Up @@ -211,6 +216,7 @@ func (d *DataSourceTemplate) Read(ctx context.Context, req datasource.ReadReques
data.ProjectID = types.StringValue(client.Config.ProjectID)
data.Summary = types.StringValue(appTemplate.Summary)
data.TerraformNoCodeModuleSource = types.StringValue(appTemplate.ModuleSource)
data.TerraformNoCodeModuleID = types.StringValue(appTemplate.ModuleID)

if appTemplate.TerraformCloudWorkspaceDetails != nil {
tfcWorkspace := &tfcWorkspace{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestAccWaypointData_Template_basic(t *testing.T) {
Config: testDataAppTemplateConfig(name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "name", name),
resource.TestCheckResourceAttr(dataSourceName, "terraform_no_code_module_id", "nocode-7ZQjQoaPXvzs6Hvp"),
resource.TestCheckResourceAttr(dataSourceName, "terraform_execution_mode", "remote"),
),
},
Expand Down
67 changes: 40 additions & 27 deletions internal/provider/waypoint/resource_waypoint_add_on_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type AddOnDefinitionResourceModel struct {
TerraformProjectID types.String `tfsdk:"terraform_project_id"`
TerraformCloudWorkspace types.Object `tfsdk:"terraform_cloud_workspace_details"`
TerraformNoCodeModuleSource types.String `tfsdk:"terraform_no_code_module_source"`
TerraformNoCodeModuleID types.String `tfsdk:"terraform_no_code_module_id"`
TerraformVariableOptions []*tfcVariableOption `tfsdk:"variable_options"`
TerraformExecutionMode types.String `tfsdk:"terraform_execution_mode"`
TerraformAgentPoolID types.String `tfsdk:"terraform_agent_pool_id"`
Expand Down Expand Up @@ -184,6 +185,10 @@ func (r *AddOnDefinitionResource) Schema(ctx context.Context, req resource.Schem
"running Terraform operations. This is only applicable when" +
" the execution mode is set to 'agent'.",
},
"terraform_no_code_module_id": schema.StringAttribute{
Required: true,
Description: "The ID of the Terraform no-code module to use for running Terraform operations. This is in the format of 'nocode-<ID>'.",
},
},
}
}
Expand Down Expand Up @@ -268,14 +273,17 @@ func (r *AddOnDefinitionResource) Create(ctx context.Context, req resource.Creat
}

modelBody := &waypointModels.HashicorpCloudWaypointWaypointServiceCreateAddOnDefinitionBody{
Name: plan.Name.ValueString(),
Summary: plan.Summary.ValueString(),
Description: plan.Description.ValueString(),
Labels: stringLabels,
ModuleSource: plan.TerraformNoCodeModuleSource.ValueString(),
VariableOptions: varOpts,
TfExecutionMode: plan.TerraformExecutionMode.ValueString(),
TfAgentPoolID: plan.TerraformAgentPoolID.ValueString(),
AddOnDefinition: &waypointModels.HashicorpCloudWaypointAddOnDefinition{
Name: plan.Name.ValueString(),
Summary: plan.Summary.ValueString(),
Description: plan.Description.ValueString(),
Labels: stringLabels,
ModuleSource: plan.TerraformNoCodeModuleSource.ValueString(),
VariableOptions: varOpts,
TfExecutionMode: plan.TerraformExecutionMode.ValueString(),
TfAgentPoolID: plan.TerraformAgentPoolID.ValueString(),
ModuleID: plan.TerraformNoCodeModuleID.ValueString(),
},
}

if !plan.TerraformCloudWorkspace.IsNull() && !plan.TerraformCloudWorkspace.IsUnknown() {
Expand All @@ -294,22 +302,22 @@ func (r *AddOnDefinitionResource) Create(ctx context.Context, req resource.Creat
// Set a default if none provided
workspaceDetails.TerraformProjectID = plan.TerraformProjectID
}
modelBody.TerraformCloudWorkspaceDetails = &waypointModels.HashicorpCloudWaypointTerraformCloudWorkspaceDetails{
modelBody.AddOnDefinition.TerraformCloudWorkspaceDetails = &waypointModels.HashicorpCloudWaypointTerraformCloudWorkspaceDetails{
Name: workspaceDetails.Name.ValueString(),
ProjectID: workspaceDetails.TerraformProjectID.ValueString(),
}
}

// Decode the base64 encoded readme markdown template to see if it is encoded
readmeBytes, err := base64.StdEncoding.DecodeString(plan.ReadmeMarkdownTemplate.ValueString())
// If there is an error, we assume that it is because the string is not encoded. This is ok and
// we will just use the string as is in the ReadmeTemplate field of the model.
// Eventually the ReadMeMarkdownTemplate field will be deprecated, so the default behavior will be to
// If there is an error, we assume that it is because the string is not encoded.
// This is ok, and we will just use the string as is in the ReadmeTemplate field of the model.
// Eventually, the ReadmeMarkdownTemplate field will be deprecated, so the default behavior will be to
// expect the readme to not be encoded
if err != nil {
modelBody.ReadmeTemplate = plan.ReadmeMarkdownTemplate.ValueString()
modelBody.AddOnDefinition.ReadmeTemplate = plan.ReadmeMarkdownTemplate.ValueString()
} else {
modelBody.ReadmeMarkdownTemplate = readmeBytes
modelBody.AddOnDefinition.ReadmeMarkdownTemplate = readmeBytes
}

params := &waypoint_service.WaypointServiceCreateAddOnDefinitionParams{
Expand Down Expand Up @@ -337,6 +345,7 @@ func (r *AddOnDefinitionResource) Create(ctx context.Context, req resource.Creat
plan.OrgID = types.StringValue(orgID)
plan.Summary = types.StringValue(addOnDefinition.Summary)
plan.TerraformNoCodeModuleSource = types.StringValue(addOnDefinition.ModuleSource)
plan.TerraformNoCodeModuleID = types.StringValue(addOnDefinition.ModuleID)

plan.Description = types.StringValue(addOnDefinition.Description)
// set plan.description if it's not null or addOnDefinition.description is not empty
Expand Down Expand Up @@ -431,6 +440,7 @@ func (r *AddOnDefinitionResource) Read(ctx context.Context, req resource.ReadReq
state.ProjectID = types.StringValue(client.Config.ProjectID)
state.Summary = types.StringValue(definition.Summary)
state.TerraformNoCodeModuleSource = types.StringValue(definition.ModuleSource)
state.TerraformNoCodeModuleID = types.StringValue(definition.ModuleID)

state.Description = types.StringValue(definition.Description)
// set plan.description if it's not null or addOnDefinition.description is not empty
Expand Down Expand Up @@ -540,14 +550,17 @@ func (r *AddOnDefinitionResource) Update(ctx context.Context, req resource.Updat

// TODO: add support for Tags
modelBody := &waypointModels.HashicorpCloudWaypointWaypointServiceUpdateAddOnDefinitionBody{
Name: plan.Name.ValueString(),
Summary: plan.Summary.ValueString(),
Description: plan.Description.ValueString(),
Labels: stringLabels,
ModuleSource: plan.TerraformNoCodeModuleSource.ValueString(),
VariableOptions: varOpts,
TfExecutionMode: plan.TerraformExecutionMode.ValueString(),
TfAgentPoolID: plan.TerraformAgentPoolID.ValueString(),
AddOnDefinition: &waypointModels.HashicorpCloudWaypointAddOnDefinition{
Name: plan.Name.ValueString(),
Summary: plan.Summary.ValueString(),
Description: plan.Description.ValueString(),
Labels: stringLabels,
ModuleSource: plan.TerraformNoCodeModuleSource.ValueString(),
ModuleID: plan.TerraformNoCodeModuleSource.ValueString(),
VariableOptions: varOpts,
TfExecutionMode: plan.TerraformExecutionMode.ValueString(),
TfAgentPoolID: plan.TerraformAgentPoolID.ValueString(),
},
}

if !plan.TerraformCloudWorkspace.IsNull() && !plan.TerraformCloudWorkspace.IsUnknown() {
Expand All @@ -566,22 +579,22 @@ func (r *AddOnDefinitionResource) Update(ctx context.Context, req resource.Updat
// Grab the top level project ID if this was not provided
workspaceDetails.TerraformProjectID = plan.TerraformProjectID
}
modelBody.TerraformCloudWorkspaceDetails = &waypointModels.HashicorpCloudWaypointTerraformCloudWorkspaceDetails{
modelBody.AddOnDefinition.TerraformCloudWorkspaceDetails = &waypointModels.HashicorpCloudWaypointTerraformCloudWorkspaceDetails{
Name: workspaceDetails.Name.ValueString(),
ProjectID: workspaceDetails.TerraformProjectID.ValueString(),
}
}

// Decode the base64 encoded readme markdown template to see if it is encoded
readmeBytes, err := base64.StdEncoding.DecodeString(plan.ReadmeMarkdownTemplate.ValueString())
// If there is an error, we assume that it is because the string is not encoded. This is ok and
// If there is an error, we assume that it is because the string is not encoded. This is ok, and
// we will just use the string as is in the ReadmeTemplate field of the model.
// Eventually the ReadMeMarkdownTemplate field will be deprecated, so the default behavior will be to
// Eventually, the ReadMeMarkdownTemplate field will be deprecated, so the default behavior will be to
// expect the readme to not be encoded
if err != nil {
modelBody.ReadmeTemplate = plan.ReadmeMarkdownTemplate.ValueString()
modelBody.AddOnDefinition.ReadmeTemplate = plan.ReadmeMarkdownTemplate.ValueString()
} else {
modelBody.ReadmeMarkdownTemplate = readmeBytes
modelBody.AddOnDefinition.ReadmeMarkdownTemplate = readmeBytes
}

params := &waypoint_service.WaypointServiceUpdateAddOnDefinitionParams{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestAccWaypoint_Add_On_Definition_basic(t *testing.T) {
testAccCheckWaypointAddOnDefinitionExists(t, resourceName, &addOnDefinitionModel),
testAccCheckWaypointAddOnDefinitionName(t, &addOnDefinitionModel, name),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "terraform_no_code_module_id", "nocode-7ZQjQoaPXvzs6Hvp"),
resource.TestCheckResourceAttr(resourceName, "terraform_execution_mode", "remote"),
),
},
Expand Down Expand Up @@ -134,6 +135,7 @@ resource "hcp_waypoint_add_on_definition" "test" {
summary = "some summary for fun"
description = "some description for fun"
terraform_no_code_module_source = "private/waypoint-tfc-testing/waypoint-template-starter/null"
terraform_no_code_module_id = "nocode-7ZQjQoaPXvzs6Hvp"
terraform_project_id = "prj-gfVyPJ2q2Aurn25o"
terraform_cloud_workspace_details = {
name = "Default Project"
Expand Down
6 changes: 6 additions & 0 deletions internal/provider/waypoint/resource_waypoint_add_on_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ resource "hcp_waypoint_template" "test" {
summary = "some summary for fun"
readme_markdown_template = base64encode("# Some Readme")
terraform_no_code_module_source = "private/waypoint-tfc-testing/waypoint-template-starter/null"
terraform_no_code_module_id = "nocode-7ZQjQoaPXvzs6Hvp"
terraform_project_id = "prj-gfVyPJ2q2Aurn25o"
terraform_cloud_workspace_details = {
name = "Default Project"
Expand All @@ -209,6 +210,7 @@ resource "hcp_waypoint_add_on_definition" "test" {
summary = "some summary for fun"
description = "some description for fun"
terraform_no_code_module_source = "private/waypoint-tfc-testing/waypoint-template-starter/null"
terraform_no_code_module_id = "nocode-7ZQjQoaPXvzs6Hvp"
terraform_project_id = "prj-gfVyPJ2q2Aurn25o"
terraform_cloud_workspace_details = {
name = "Default Project"
Expand All @@ -230,6 +232,7 @@ resource "hcp_waypoint_template" "test" {
summary = "some summary for fun"
readme_markdown_template = base64encode("# Some Readme")
terraform_no_code_module_source = "private/waypoint-tfc-testing/waypoint-template-starter/null"
terraform_no_code_module_id = "nocode-7ZQjQoaPXvzs6Hvp"
terraform_project_id = "prj-gfVyPJ2q2Aurn25o"
terraform_cloud_workspace_details = {
name = "Default Project"
Expand All @@ -249,6 +252,7 @@ resource "hcp_waypoint_add_on_definition" "test_var_opts" {
description = "some description for fun"
readme_markdown_template = base64encode("# Some Readme")
terraform_no_code_module_source = "private/waypoint-tfc-testing/waypoint-vault-dweller/null"
terraform_no_code_module_id = "nocode-JSMkg9ztLBYgg1eW"
terraform_project_id = "prj-gfVyPJ2q2Aurn25o"
terraform_cloud_workspace_details = {
name = "Default Project"
Expand Down Expand Up @@ -311,6 +315,7 @@ resource "hcp_waypoint_template" "test" {
summary = "some summary for fun"
readme_markdown_template = base64encode("# Some Readme")
terraform_no_code_module_source = "private/waypoint-tfc-testing/waypoint-template-starter/null"
terraform_no_code_module_id = "nocode-7ZQjQoaPXvzs6Hvp"
terraform_project_id = "prj-gfVyPJ2q2Aurn25o"
terraform_cloud_workspace_details = {
name = "Default Project"
Expand All @@ -330,6 +335,7 @@ resource "hcp_waypoint_add_on_definition" "test_var_opts" {
description = "some description"
readme_markdown_template = base64encode("# Some Readme")
terraform_no_code_module_source = "private/waypoint-tfc-testing/waypoint-vault-dweller/null"
terraform_no_code_module_id = "nocode-JSMkg9ztLBYgg1eW"
terraform_project_id = "prj-gfVyPJ2q2Aurn25o"
terraform_cloud_workspace_details = {
name = "Default Project"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ resource "hcp_waypoint_template" "test" {
summary = "some summary for fun"
readme_markdown_template = base64encode("# Some Readme")
terraform_no_code_module_source = "private/waypoint-tfc-testing/waypoint-template-starter/null"
terraform_no_code_module_id = "nocode-7ZQjQoaPXvzs6Hvp"
terraform_project_id = "prj-gfVyPJ2q2Aurn25o"
terraform_cloud_workspace_details = {
name = "Default Project"
Expand All @@ -214,6 +215,7 @@ resource "hcp_waypoint_template" "test_var_opts" {
summary = "some summary for fun"
readme_markdown_template = base64encode("# Some Readme")
terraform_no_code_module_source = "private/waypoint-tfc-testing/waypoint-vault-dweller/null"
terraform_no_code_module_id = "nocode-JSMkg9ztLBYgg1eW"
terraform_project_id = "prj-gfVyPJ2q2Aurn25o"
terraform_cloud_workspace_details = {
name = "Default Project"
Expand Down Expand Up @@ -273,6 +275,7 @@ resource "hcp_waypoint_template" "test_var_opts" {
summary = "some summary for fun"
readme_markdown_template = base64encode("# Some Readme")
terraform_no_code_module_source = "private/waypoint-tfc-testing/waypoint-vault-dweller/null"
terraform_no_code_module_id = "nocode-JSMkg9ztLBYgg1eW"
terraform_project_id = "prj-gfVyPJ2q2Aurn25o"
terraform_cloud_workspace_details = {
name = "Default Project"
Expand Down
Loading
Loading