Skip to content

Commit 54ea409

Browse files
authored
Bug: fix waypoint_template.variable_options when no options is included (#1242)
* Do not call ElementAs when parsing variable_options.options * modify existing test to validate no `options` works * changelog: waypoint_template bug fix * changelog: waypoint_template bug fix * update test to include new ncm variable * using fun variable names out of positive peer pressure * Add test changes to waypoint resources * options not required for variablesets * update docs to show options is optional * fix test input * include changelog entry for fix on addon_definition
1 parent 88fdfd6 commit 54ea409

10 files changed

+64
-14
lines changed

.changelog/1242.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:bug
2+
Fixed a bug when `tfe_waypoint_template.variable_options` did not specify `options` list.
3+
```
4+
5+
```release-note:bug
6+
Fixed a bug for `hcp_waypoint_add_on_definition.variable_options` which incorrectly required `options`.
7+
```

docs/resources/waypoint_add_on_definition.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ Required:
7777
Required:
7878

7979
- `name` (String) Variable name
80-
- `options` (List of String) List of options
8180
- `variable_type` (String) Variable type
8281

8382
Optional:
8483

84+
- `options` (List of String) List of options
8585
- `user_editable` (Boolean) Whether the variable is editable by the user creating an add-on. If options are provided, then the user may only use those options, regardless of this setting.

internal/provider/waypoint/data_source_waypoint_add_on_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestAcc_Waypoint_AddOn_DataSource_WithInputVars(t *testing.T) {
7676
Config: testDataAddOnWithInputVarsConfig(templateName, appName, defName, addOnName),
7777
Check: resource.ComposeTestCheckFunc(
7878
resource.TestCheckResourceAttr(dataSourceName, "name", addOnName),
79-
resource.TestCheckResourceAttr(dataSourceName, "input_variables.#", "5"),
79+
resource.TestCheckResourceAttr(dataSourceName, "input_variables.#", "6"),
8080
),
8181
},
8282
},

internal/provider/waypoint/data_source_waypoint_application_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func TestAcc_Waypoint_Application_DataSource_WithInputVars(t *testing.T) {
7575
Config: testDataApplicationWithInputVarsConfig(templateName, applicationName),
7676
Check: resource.ComposeTestCheckFunc(
7777
resource.TestCheckResourceAttr(dataSourceName, "name", applicationName),
78-
resource.TestCheckResourceAttr(dataSourceName, "input_variables.#", "3"),
78+
resource.TestCheckResourceAttr(dataSourceName, "input_variables.#", "4"),
7979
),
8080
},
8181
},

internal/provider/waypoint/data_source_waypoint_template_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,13 @@ func TestAcc_Waypoint_Data_template_with_variable_options(t *testing.T) {
8888
Config: testDataAppTemplateWithVariablesWithOptionsConfig(name),
8989
Check: resource.ComposeTestCheckFunc(
9090
resource.TestCheckResourceAttr(dataSourceName, "name", name),
91-
resource.TestCheckResourceAttr(dataSourceName, "variable_options.#", "2"),
91+
resource.TestCheckResourceAttr(dataSourceName, "variable_options.#", "3"),
9292
resource.TestCheckResourceAttr(dataSourceName, "variable_options.0.name", "faction"),
9393
resource.TestCheckResourceAttr(dataSourceName, "variable_options.0.variable_type", "string"),
9494
resource.TestCheckResourceAttr(dataSourceName, "variable_options.1.name", "vault_dweller_name"),
9595
resource.TestCheckResourceAttr(dataSourceName, "variable_options.1.variable_type", "string"),
96+
resource.TestCheckResourceAttr(dataSourceName, "variable_options.2.name", "vault_dweller_shelter"),
97+
resource.TestCheckResourceAttr(dataSourceName, "variable_options.2.variable_type", "string"),
9698
),
9799
},
98100
},

internal/provider/waypoint/resource_waypoint_add_on_definition.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ func (r *AddOnDefinitionResource) Schema(ctx context.Context, req resource.Schem
161161
},
162162
"options": &schema.ListAttribute{
163163
ElementType: types.StringType,
164-
Required: true,
164+
Optional: true,
165+
Computed: true,
165166
Description: "List of options",
166167
},
167168
"user_editable": &schema.BoolAttribute{
@@ -244,10 +245,13 @@ func (r *AddOnDefinitionResource) Create(ctx context.Context, req resource.Creat
244245
var varOpts []*waypoint_models.HashicorpCloudWaypointTFModuleVariable
245246
for _, v := range plan.TerraformVariableOptions {
246247
strOpts := []string{}
247-
diags := v.Options.ElementsAs(ctx, &strOpts, false)
248-
if diags.HasError() {
249-
resp.Diagnostics.Append(diags...)
250-
return
248+
if len(v.Options.Elements()) != 0 {
249+
250+
diags := v.Options.ElementsAs(ctx, &strOpts, false)
251+
if diags.HasError() {
252+
resp.Diagnostics.Append(diags...)
253+
return
254+
}
251255
}
252256

253257
varOpts = append(varOpts, &waypoint_models.HashicorpCloudWaypointTFModuleVariable{

internal/provider/waypoint/resource_waypoint_add_on_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func TestAcc_Waypoint_AddOnInputVariables(t *testing.T) {
6666
testAccCheckWaypointAddOnExists(t, resourceName, &addOnModel),
6767
testAccCheckWaypointAddOnName(t, &addOnModel, addOnName),
6868
resource.TestCheckResourceAttr(resourceName, "name", addOnName),
69-
resource.TestCheckResourceAttr(resourceName, "add_on_input_variables.#", "2"),
69+
resource.TestCheckResourceAttr(resourceName, "add_on_input_variables.#", "3"),
7070
resource.TestCheckResourceAttr(resourceName, "add_on_input_variables.0.name", "faction"),
7171
resource.TestCheckResourceAttr(resourceName, "add_on_input_variables.0.value", "brotherhood-of-steel"),
7272
resource.TestCheckResourceAttr(resourceName, "add_on_input_variables.0.variable_type", "string"),
@@ -289,6 +289,11 @@ resource "hcp_waypoint_add_on_definition" "test_var_opts" {
289289
"institute"
290290
]
291291
},
292+
{
293+
name = "vault_dweller_shelter"
294+
variable_type = "string"
295+
user_editable = true
296+
}
292297
]
293298
}
294299
@@ -307,6 +312,11 @@ resource "hcp_waypoint_add_on" "test_var_opts" {
307312
name = "vault_dweller_name"
308313
variable_type = "string"
309314
value = "courier"
315+
},
316+
{
317+
name = "vault_dweller_shelter"
318+
variable_type = "string"
319+
value = "value101"
310320
}
311321
]
312322
}
@@ -365,6 +375,11 @@ resource "hcp_waypoint_add_on_definition" "test_var_opts" {
365375
"brotherhood-of-steel",
366376
]
367377
},
378+
{
379+
name = "vault_dweller_shelter"
380+
variable_type = "string"
381+
user_editable = true
382+
}
368383
]
369384
}
370385

internal/provider/waypoint/resource_waypoint_application_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestAcc_Waypoint_ApplicationInputVariables(t *testing.T) {
6161
testAccCheckWaypointApplicationExists(t, resourceName, &applicationModel),
6262
testAccCheckWaypointApplicationName(t, &applicationModel, applicationName),
6363
resource.TestCheckResourceAttr(resourceName, "name", applicationName),
64-
resource.TestCheckResourceAttr(resourceName, "application_input_variables.#", "2"),
64+
resource.TestCheckResourceAttr(resourceName, "application_input_variables.#", "3"),
6565
resource.TestCheckResourceAttr(resourceName, "application_input_variables.0.name", "faction"),
6666
resource.TestCheckResourceAttr(resourceName, "application_input_variables.0.value", "brotherhood-of-steel"),
6767
resource.TestCheckResourceAttr(resourceName, "application_input_variables.0.variable_type", "string"),
@@ -305,6 +305,11 @@ resource "hcp_waypoint_template" "test_var_opts" {
305305
"institute"
306306
]
307307
},
308+
{
309+
name = "vault_dweller_shelter"
310+
variable_type = "string"
311+
user_editable = true
312+
}
308313
]
309314
}
310315
@@ -322,6 +327,11 @@ resource "hcp_waypoint_application" "test_var_opts" {
322327
name = "vault_dweller_name"
323328
variable_type = "string"
324329
value = "courier"
330+
},
331+
{
332+
name = "vault_dweller_shelter"
333+
variable_type = "string"
334+
value = "vault101"
325335
}
326336
]
327337
}`, tempName, appName)
@@ -358,6 +368,11 @@ resource "hcp_waypoint_template" "test_var_opts" {
358368
"brotherhood-of-steel",
359369
]
360370
},
371+
{
372+
name = "vault_dweller_shelter"
373+
variable_type = "string"
374+
user_editable = true
375+
}
361376
]
362377
}
363378

internal/provider/waypoint/resource_waypoint_template.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,11 @@ func (r *TemplateResource) Create(ctx context.Context, req resource.CreateReques
286286
var varOpts []*waypoint_models.HashicorpCloudWaypointTFModuleVariable
287287
for _, v := range plan.TerraformVariableOptions {
288288
strOpts := []string{}
289-
diags = v.Options.ElementsAs(ctx, &strOpts, false)
290-
if diags.HasError() {
291-
return
289+
if len(v.Options.Elements()) != 0 {
290+
diags = v.Options.ElementsAs(ctx, &strOpts, false)
291+
if diags.HasError() {
292+
return
293+
}
292294
}
293295

294296
varOpts = append(varOpts, &waypoint_models.HashicorpCloudWaypointTFModuleVariable{

internal/provider/waypoint/resource_waypoint_template_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,11 @@ resource "hcp_waypoint_template" "var_opts_test" {
292292
"raiders",
293293
"institute"
294294
]
295+
},
296+
{
297+
name = "vault_dweller_shelter"
298+
variable_type = "string"
299+
user_editable = true
295300
}
296301
]
297302
}`, name)

0 commit comments

Comments
 (0)