Skip to content

Commit

Permalink
[WAYP-2172] waypoint: Make var opts user editable on add-on definitions.
Browse files Browse the repository at this point in the history
Also fix required vs. computed property on variable options field for data source.
  • Loading branch information
paladin-devops committed Apr 29, 2024
1 parent 800aab3 commit 6390bd3
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 20 deletions.
23 changes: 12 additions & 11 deletions docs/data-sources/waypoint_add_on_definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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))

<a id="nestedatt--variable_options"></a>
### 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))

<a id="nestedatt--terraform_cloud_workspace_details"></a>
### Nested Schema for `terraform_cloud_workspace_details`
Expand All @@ -57,3 +47,14 @@ Read-Only:

- `source` (String) Terraform Cloud no-code Module Source
- `version` (String) Terraform Cloud no-code Module Version


<a id="nestedatt--variable_options"></a>
### 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
2 changes: 1 addition & 1 deletion docs/data-sources/waypoint_application_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Read-Only:
<a id="nestedatt--variable_options"></a>
### Nested Schema for `variable_options`

Read-Only:
Required:

- `name` (String) Variable name
- `options` (List of String) List of 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 @@ -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
2 changes: 1 addition & 1 deletion docs/resources/waypoint_application_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
},
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
{
Expand All @@ -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"),
),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
},
Expand Down Expand Up @@ -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(),
})
}

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(),
})
}

Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
{
Expand All @@ -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"),
),
},
},
Expand Down Expand Up @@ -155,6 +157,7 @@ resource "hcp_waypoint_add_on_definition" "test" {
options = [
"b"
]
user_editable = false
}
]
}`, name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
Expand Down

0 comments on commit 6390bd3

Please sign in to comment.