Skip to content

Commit

Permalink
Add hidden field.
Browse files Browse the repository at this point in the history
  • Loading branch information
gigerdo committed Mar 21, 2024
1 parent 30fe508 commit 01b81c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/data-sources/deployment_templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Use this data source to retrieve a list of available deployment templates.
Read-Only:

- `description` (String) The description of the deployment template.
- `hidden` (Boolean) If the template is visible by default. (Outdated templates are hidden, but can still be used)
- `id` (String) The id of the deployment template.
- `min_stack_version` (String) The minimum stack version that can used with this deployment template.
- `name` (String) The name of the deployment template.
Expand Down
9 changes: 8 additions & 1 deletion ec/ecdatasource/deploymenttemplates/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func deploymentTemplatesListSchema() schema.ListNestedAttribute {
Description: "The minimum stack version that can used with this deployment template.",
Computed: true,
},
"hidden": schema.BoolAttribute{
Description: "If the template is visible by default. (Outdated templates are hidden, but can still be used)",
Computed: true,
},
},
},
}
Expand Down Expand Up @@ -144,14 +148,16 @@ func (d DataSource) Read(ctx context.Context, request datasource.ReadRequest, re
func mapResponseToModel(response []*models.DeploymentTemplateInfoV2, showHidden bool) []deploymentTemplateModel {
templates := make([]deploymentTemplateModel, 0, len(response))
for _, template := range response {
if !showHidden && isHidden(template) {
hidden := isHidden(template)
if !showHidden && hidden {
continue
}
templateModel := deploymentTemplateModel{
ID: types.StringValue(*template.ID),
Name: types.StringValue(*template.Name),
Description: types.StringValue(template.Description),
MinStackVersion: types.StringValue(template.MinVersion),
Hidden: types.BoolValue(hidden),
}
templates = append(templates, templateModel)
}
Expand Down Expand Up @@ -184,4 +190,5 @@ type deploymentTemplateModel struct {
Name types.String `tfsdk:"name"`
Description types.String `tfsdk:"description"`
MinStackVersion types.String `tfsdk:"min_stack_version"`
Hidden types.Bool `tfsdk:"hidden"`
}
3 changes: 3 additions & 0 deletions ec/ecdatasource/deploymenttemplates/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func Test_mapResponseToModel(t *testing.T) {
Name: types.StringValue("name-nonhidden"),
Description: types.StringValue("description nonhidden"),
MinStackVersion: types.StringValue(""),
Hidden: types.BoolValue(false),
},
},
},
Expand Down Expand Up @@ -103,12 +104,14 @@ func Test_mapResponseToModel(t *testing.T) {
Name: types.StringValue("name-nonhidden"),
Description: types.StringValue("description nonhidden"),
MinStackVersion: types.StringValue(""),
Hidden: types.BoolValue(false),
},
{
ID: types.StringValue("id-hidden"),
Name: types.StringValue("name-hidden"),
Description: types.StringValue("description hidden"),
MinStackVersion: types.StringValue("7.17.0"),
Hidden: types.BoolValue(true),
},
},
},
Expand Down

0 comments on commit 01b81c0

Please sign in to comment.