From 6390bd320d2a5642a43c4cc5d766a904bde0ddf2 Mon Sep 17 00:00:00 2001
From: paladin-devops <83741749+paladin-devops@users.noreply.github.com>
Date: Mon, 29 Apr 2024 13:23:46 -0500
Subject: [PATCH] [WAYP-2172] waypoint: Make var opts user editable on add-on
definitions.
Also fix required vs. computed property on variable options field for data source.
---
.../waypoint_add_on_definition.md | 23 ++++++++++---------
.../waypoint_application_template.md | 2 +-
docs/resources/waypoint_add_on_definition.md | 1 +
.../waypoint_application_template.md | 2 +-
.../data_source_waypoint_add_on_definition.go | 13 +++++++----
..._source_waypoint_add_on_definition_test.go | 2 ++
.../resource_waypoint_add_on_definition.go | 11 +++++++--
...esource_waypoint_add_on_definition_test.go | 3 +++
.../resource_waypoint_application_template.go | 2 +-
9 files changed, 39 insertions(+), 20 deletions(-)
diff --git a/docs/data-sources/waypoint_add_on_definition.md b/docs/data-sources/waypoint_add_on_definition.md
index 8f3a0dc83..89d65e038 100644
--- a/docs/data-sources/waypoint_add_on_definition.md
+++ b/docs/data-sources/waypoint_add_on_definition.md
@@ -19,7 +19,6 @@ The Waypoint Add-on Definition data source retrieves information on a given Add-
- `id` (String) The ID of the Add-on Definition.
- `name` (String) The name of the Add-on Definition.
- `project_id` (String) The ID of the HCP project where the Waypoint Add-on Definition is located.
-- `variable_options` (Attributes List) List of variable options for the template (see [below for nested schema](#nestedatt--variable_options))
### Read-Only
@@ -30,16 +29,7 @@ The Waypoint Add-on Definition data source retrieves information on a given Add-
- `summary` (String) A short summary of the Add-on Definition.
- `terraform_cloud_workspace_details` (Attributes) Terraform Cloud Workspace details. (see [below for nested schema](#nestedatt--terraform_cloud_workspace_details))
- `terraform_no_code_module` (Attributes) Terraform Cloud no-code Module details. (see [below for nested schema](#nestedatt--terraform_no_code_module))
-
-
-### Nested Schema for `variable_options`
-
-Required:
-
-- `name` (String) Variable name
-- `options` (List of String) List of options
-- `variable_type` (String) Variable type
-
+- `variable_options` (Attributes List) List of variable options for the template (see [below for nested schema](#nestedatt--variable_options))
### Nested Schema for `terraform_cloud_workspace_details`
@@ -57,3 +47,14 @@ Read-Only:
- `source` (String) Terraform Cloud no-code Module Source
- `version` (String) Terraform Cloud no-code Module Version
+
+
+
+### Nested Schema for `variable_options`
+
+Read-Only:
+
+- `name` (String) Variable name
+- `options` (List of String) List of options
+- `user_editable` (Boolean) Whether the variable is editable by the user creating an add-on
+- `variable_type` (String) Variable type
diff --git a/docs/data-sources/waypoint_application_template.md b/docs/data-sources/waypoint_application_template.md
index c0f0e5561..a8f96cf8e 100644
--- a/docs/data-sources/waypoint_application_template.md
+++ b/docs/data-sources/waypoint_application_template.md
@@ -52,7 +52,7 @@ Read-Only:
### Nested Schema for `variable_options`
-Read-Only:
+Required:
- `name` (String) Variable name
- `options` (List of String) List of options
diff --git a/docs/resources/waypoint_add_on_definition.md b/docs/resources/waypoint_add_on_definition.md
index 2501266d6..87ab4ee48 100644
--- a/docs/resources/waypoint_add_on_definition.md
+++ b/docs/resources/waypoint_add_on_definition.md
@@ -59,4 +59,5 @@ Required:
- `name` (String) Variable name
- `options` (List of String) List of options
+- `user_editable` (Boolean) Whether the variable is editable by the user creating an add-on
- `variable_type` (String) Variable type
diff --git a/docs/resources/waypoint_application_template.md b/docs/resources/waypoint_application_template.md
index 7b4f7d516..dc8df8dac 100644
--- a/docs/resources/waypoint_application_template.md
+++ b/docs/resources/waypoint_application_template.md
@@ -63,4 +63,4 @@ Required:
Optional:
-- `user_editable` (Boolean) Whether the variable is editable by the user creating an application.
+- `user_editable` (Boolean) Whether the variable is editable by the user creating an application
diff --git a/internal/provider/waypoint/data_source_waypoint_add_on_definition.go b/internal/provider/waypoint/data_source_waypoint_add_on_definition.go
index 4a13cdf36..d05c52d3f 100644
--- a/internal/provider/waypoint/data_source_waypoint_add_on_definition.go
+++ b/internal/provider/waypoint/data_source_waypoint_add_on_definition.go
@@ -125,23 +125,27 @@ func (d *DataSourceAddOnDefinition) Schema(ctx context.Context, req datasource.S
},
},
"variable_options": schema.ListNestedAttribute{
- Optional: true,
+ Computed: true,
Description: "List of variable options for the template",
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"name": &schema.StringAttribute{
- Required: true,
+ Computed: true,
Description: "Variable name",
},
"variable_type": &schema.StringAttribute{
- Required: true,
+ Computed: true,
Description: "Variable type",
},
"options": &schema.ListAttribute{
ElementType: types.StringType,
- Required: true,
+ Computed: true,
Description: "List of options",
},
+ "user_editable": &schema.BoolAttribute{
+ Computed: true,
+ Description: "Whether the variable is editable by the user creating an add-on",
+ },
},
},
},
@@ -249,6 +253,7 @@ func (d *DataSourceAddOnDefinition) Read(ctx context.Context, req datasource.Rea
varOptsState := &tfcVariableOption{
Name: types.StringValue(v.Name),
VariableType: types.StringValue(v.VariableType),
+ UserEditable: types.BoolValue(v.UserEditable),
}
vOpts, diags := types.ListValueFrom(ctx, types.StringType, v.Options)
diff --git a/internal/provider/waypoint/data_source_waypoint_add_on_definition_test.go b/internal/provider/waypoint/data_source_waypoint_add_on_definition_test.go
index 7bfbd029b..78dc76b71 100644
--- a/internal/provider/waypoint/data_source_waypoint_add_on_definition_test.go
+++ b/internal/provider/waypoint/data_source_waypoint_add_on_definition_test.go
@@ -44,6 +44,7 @@ func TestAccWaypointData_Add_On_Definition_basic(t *testing.T) {
resource.TestCheckResourceAttr(dataSourceName, "variable_options.0.variable_type", "string"),
resource.TestCheckResourceAttr(dataSourceName, "variable_options.0.options.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "variable_options.0.options.0", "b"),
+ resource.TestCheckResourceAttr(dataSourceName, "variable_options.0.user_editable", "false"),
),
},
{
@@ -56,6 +57,7 @@ func TestAccWaypointData_Add_On_Definition_basic(t *testing.T) {
resource.TestCheckResourceAttr(dataSourceName, "variable_options.0.variable_type", "string"),
resource.TestCheckResourceAttr(dataSourceName, "variable_options.0.options.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "variable_options.0.options.0", "b"),
+ resource.TestCheckResourceAttr(dataSourceName, "variable_options.0.user_editable", "false"),
),
},
},
diff --git a/internal/provider/waypoint/resource_waypoint_add_on_definition.go b/internal/provider/waypoint/resource_waypoint_add_on_definition.go
index 321226b34..a31c76c3f 100644
--- a/internal/provider/waypoint/resource_waypoint_add_on_definition.go
+++ b/internal/provider/waypoint/resource_waypoint_add_on_definition.go
@@ -154,6 +154,10 @@ func (r *AddOnDefinitionResource) Schema(ctx context.Context, req resource.Schem
Required: true,
Description: "List of options",
},
+ "user_editable": &schema.BoolAttribute{
+ Required: true,
+ Description: "Whether the variable is editable by the user creating an add-on",
+ },
},
},
},
@@ -243,7 +247,7 @@ func (r *AddOnDefinitionResource) Create(ctx context.Context, req resource.Creat
Name: v.Name.ValueString(),
VariableType: v.VariableType.ValueString(),
Options: strOpts,
- UserEditable: false,
+ UserEditable: v.UserEditable.ValueBool(),
})
}
@@ -329,6 +333,7 @@ func (r *AddOnDefinitionResource) Create(ctx context.Context, req resource.Creat
varOptsState := &tfcVariableOption{
Name: types.StringValue(v.Name),
VariableType: types.StringValue(v.VariableType),
+ UserEditable: types.BoolValue(v.UserEditable),
}
varOptsState.Options, diags = types.ListValueFrom(ctx, types.StringType, v.Options)
@@ -429,6 +434,7 @@ func (r *AddOnDefinitionResource) Read(ctx context.Context, req resource.ReadReq
varOptsState := &tfcVariableOption{
Name: types.StringValue(v.Name),
VariableType: types.StringValue(v.VariableType),
+ UserEditable: types.BoolValue(v.UserEditable),
}
vOpts, diags := types.ListValueFrom(ctx, types.StringType, v.Options)
@@ -511,7 +517,7 @@ func (r *AddOnDefinitionResource) Update(ctx context.Context, req resource.Updat
Name: v.Name.ValueString(),
VariableType: v.VariableType.ValueString(),
Options: strOpts,
- UserEditable: false,
+ UserEditable: v.UserEditable.ValueBool(),
})
}
@@ -599,6 +605,7 @@ func (r *AddOnDefinitionResource) Update(ctx context.Context, req resource.Updat
varOptsState := &tfcVariableOption{
Name: types.StringValue(v.Name),
VariableType: types.StringValue(v.VariableType),
+ UserEditable: types.BoolValue(v.UserEditable),
}
varOptsState.Options, diags = types.ListValueFrom(ctx, types.StringType, v.Options)
diff --git a/internal/provider/waypoint/resource_waypoint_add_on_definition_test.go b/internal/provider/waypoint/resource_waypoint_add_on_definition_test.go
index a82c8e92d..ebd5378b7 100644
--- a/internal/provider/waypoint/resource_waypoint_add_on_definition_test.go
+++ b/internal/provider/waypoint/resource_waypoint_add_on_definition_test.go
@@ -39,6 +39,7 @@ func TestAccWaypoint_Add_On_Definition_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "variable_options.0.variable_type", "string"),
resource.TestCheckResourceAttr(resourceName, "variable_options.0.options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "variable_options.0.options.0", "b"),
+ resource.TestCheckResourceAttr(resourceName, "variable_options.0.user_editable", "false"),
),
},
{
@@ -51,6 +52,7 @@ func TestAccWaypoint_Add_On_Definition_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "variable_options.0.variable_type", "string"),
resource.TestCheckResourceAttr(resourceName, "variable_options.0.options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "variable_options.0.options.0", "b"),
+ resource.TestCheckResourceAttr(resourceName, "variable_options.0.user_editable", "false"),
),
},
},
@@ -155,6 +157,7 @@ resource "hcp_waypoint_add_on_definition" "test" {
options = [
"b"
]
+ user_editable = false
}
]
}`, name)
diff --git a/internal/provider/waypoint/resource_waypoint_application_template.go b/internal/provider/waypoint/resource_waypoint_application_template.go
index 7f7c51c89..2729abb2c 100644
--- a/internal/provider/waypoint/resource_waypoint_application_template.go
+++ b/internal/provider/waypoint/resource_waypoint_application_template.go
@@ -176,7 +176,7 @@ func (r *ApplicationTemplateResource) Schema(ctx context.Context, req resource.S
"user_editable": &schema.BoolAttribute{
Optional: true,
Description: "Whether the variable is editable by the user " +
- "creating an application.",
+ "creating an application",
},
},
},