Skip to content

Commit

Permalink
add composite templates suppot to catalystcenter_template resource
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba-mazurkiewicz committed Oct 8, 2024
1 parent 8ccaca1 commit 5600066
Show file tree
Hide file tree
Showing 12 changed files with 302 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 0.1.13 (unreleased)

- Add composite templates support to `catalystcenter_template` resource
- Fix issue with catalystcenter_ip_pool forces replacement on `catalystcenter_ip_pool` resource, [link](https://github.com/CiscoDevNet/terraform-provider-catalystcenter/issues/125)

## 0.1.12
Expand Down
14 changes: 14 additions & 0 deletions docs/data-sources/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,29 @@ data "catalystcenter_template" "example" {

### Read-Only

- `composite` (Boolean) Is it composite template
- `containing_templates` (Attributes List) Containing templates for composite template (see [below for nested schema](#nestedatt--containing_templates))
- `description` (String) Description
- `device_types` (Attributes List) List of device types (see [below for nested schema](#nestedatt--device_types))
- `language` (String) Language of the template
- `project_name` (String) ProjectName
- `software_type` (String) Software type
- `software_variant` (String) Software variant
- `software_version` (String) Software version
- `template_content` (String) Template content
- `template_params` (Attributes List) List of template parameters (see [below for nested schema](#nestedatt--template_params))

<a id="nestedatt--containing_templates"></a>
### Nested Schema for `containing_templates`

Read-Only:

- `id` (String) ID of the template
- `language` (String) Language of the template
- `name` (String) Name of the template
- `project_name` (String) Project name


<a id="nestedatt--device_types"></a>
### Nested Schema for `device_types`

Expand Down
1 change: 1 addition & 0 deletions docs/guides/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ description: |-

## 0.1.13 (unreleased)

- Add composite templates support to `catalystcenter_template` resource
- Fix issue with catalystcenter_ip_pool forces replacement on `catalystcenter_ip_pool` resource, [link](https://github.com/CiscoDevNet/terraform-provider-catalystcenter/issues/125)

## 0.1.12
Expand Down
26 changes: 23 additions & 3 deletions docs/resources/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ This resource can manage a Template.

```terraform
resource "catalystcenter_template" "example" {
project_id = "12345678-1234-1234-1234-123456789012"
name = "Template1"
description = "My description"
project_id = "12345678-1234-1234-1234-123456789012"
name = "Template1"
project_name = "ProjectName"
description = "My description"
device_types = [
{
product_family = "Switches and Hubs"
Expand Down Expand Up @@ -44,6 +45,7 @@ resource "catalystcenter_template" "example" {
selection_values = { host1 = "host1" }
}
]
composite = false
}
```

Expand All @@ -61,7 +63,10 @@ resource "catalystcenter_template" "example" {

### Optional

- `composite` (Boolean) Is it composite template
- `containing_templates` (Attributes List) Containing templates for composite template (see [below for nested schema](#nestedatt--containing_templates))
- `description` (String) Description
- `project_name` (String) ProjectName
- `software_variant` (String) Software variant
- `software_version` (String) Software version
- `template_content` (String) Template content
Expand All @@ -84,6 +89,21 @@ Optional:
- `product_type` (String) Product type


<a id="nestedatt--containing_templates"></a>
### Nested Schema for `containing_templates`

Required:

- `language` (String) Language of the template
- Choices: `JINJA`, `VELOCITY`
- `name` (String) Name of the template
- `project_name` (String) Project name

Optional:

- `id` (String) ID of the template


<a id="nestedatt--template_params"></a>
### Nested Schema for `template_params`

Expand Down
8 changes: 5 additions & 3 deletions examples/resources/catalystcenter_template/resource.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
resource "catalystcenter_template" "example" {
project_id = "12345678-1234-1234-1234-123456789012"
name = "Template1"
description = "My description"
project_id = "12345678-1234-1234-1234-123456789012"
name = "Template1"
project_name = "ProjectName"
description = "My description"
device_types = [
{
product_family = "Switches and Hubs"
Expand Down Expand Up @@ -29,4 +30,5 @@ resource "catalystcenter_template" "example" {
selection_values = { host1 = "host1" }
}
]
composite = false
}
35 changes: 35 additions & 0 deletions gen/definitions/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ attributes:
data_source_query: true
description: Name of the template
example: Template1
- model_name: projectName
type: String
description: ProjectName
example: ProjectName
- model_name: description
type: String
description: Description
Expand Down Expand Up @@ -156,6 +160,37 @@ attributes:
type: Map
description: Selection values
example: "{host1 = \"host1\"}"
- model_name: composite
type: Bool
description: Is it composite template
example: false
- model_name: containingTemplates
type: List
description: Containing templates for composite template
exclude_test: true
attributes:
- model_name: name
type: String
id: true
description: Name of the template
example: CompositeTemplate1
- model_name: id
type: String
description: ID of the template
example: 12345678-1234-1234-1234-123456789012
- model_name: projectName
type: String
mandatory: true
description: Project name
example: Project1
- model_name: language
type: String
enum_values:
- JINJA
- VELOCITY
mandatory: true
description: Language of the template
example: JINJA
test_prerequisites: |
resource "catalystcenter_project" "test" {
name = "Project1"
Expand Down
32 changes: 32 additions & 0 deletions internal/provider/data_source_catalystcenter_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ func (d *TemplateDataSource) Schema(ctx context.Context, req datasource.SchemaRe
Optional: true,
Computed: true,
},
"project_name": schema.StringAttribute{
MarkdownDescription: "ProjectName",
Computed: true,
},
"description": schema.StringAttribute{
MarkdownDescription: "Description",
Computed: true,
Expand Down Expand Up @@ -197,6 +201,34 @@ func (d *TemplateDataSource) Schema(ctx context.Context, req datasource.SchemaRe
},
},
},
"composite": schema.BoolAttribute{
MarkdownDescription: "Is it composite template",
Computed: true,
},
"containing_templates": schema.ListNestedAttribute{
MarkdownDescription: "Containing templates for composite template",
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"name": schema.StringAttribute{
MarkdownDescription: "Name of the template",
Computed: true,
},
"id": schema.StringAttribute{
MarkdownDescription: "ID of the template",
Computed: true,
},
"project_name": schema.StringAttribute{
MarkdownDescription: "Project name",
Computed: true,
},
"language": schema.StringAttribute{
MarkdownDescription: "Language of the template",
Computed: true,
},
},
},
},
},
}
}
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/data_source_catalystcenter_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
func TestAccDataSourceCcTemplate(t *testing.T) {
var checks []resource.TestCheckFunc
checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_template.test", "name", "Template1"))
checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_template.test", "project_name", "ProjectName"))
checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_template.test", "description", "My description"))
checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_template.test", "device_types.0.product_family", "Switches and Hubs"))
checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_template.test", "device_types.0.product_series", "Cisco Catalyst 9300 Series Switches"))
Expand All @@ -49,6 +50,7 @@ func TestAccDataSourceCcTemplate(t *testing.T) {
checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_template.test", "template_params.0.parameter_name", "hostname"))
checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_template.test", "template_params.0.required", "false"))
checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_template.test", "template_params.0.selection_type", "SINGLE_SELECT"))
checks = append(checks, resource.TestCheckResourceAttr("data.catalystcenter_template.test", "composite", "false"))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Expand Down Expand Up @@ -78,6 +80,7 @@ func testAccDataSourceCcTemplateConfig() string {
config := `resource "catalystcenter_template" "test" {` + "\n"
config += ` project_id = catalystcenter_project.test.id` + "\n"
config += ` name = "Template1"` + "\n"
config += ` project_name = "ProjectName"` + "\n"
config += ` description = "My description"` + "\n"
config += ` device_types = [{` + "\n"
config += ` product_family = "Switches and Hubs"` + "\n"
Expand All @@ -102,6 +105,7 @@ func testAccDataSourceCcTemplateConfig() string {
config += ` selection_type = "SINGLE_SELECT"` + "\n"
config += ` selection_values = {host1 = "host1"}` + "\n"
config += ` }]` + "\n"
config += ` composite = false` + "\n"
config += `}` + "\n"

config += `
Expand Down
Loading

0 comments on commit 5600066

Please sign in to comment.