Skip to content

Commit

Permalink
Add device claim site resource
Browse files Browse the repository at this point in the history
  • Loading branch information
danischm committed Jan 8, 2024
1 parent f4908b9 commit ea2ca16
Show file tree
Hide file tree
Showing 15 changed files with 907 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 0.1.2 (unreleased)

- Fix issue with `catalystcenter_ip_pool_reservation` resource and multiple IP pools under a single site
- Add `catalystcenter_device_claim_site` resource

## 0.1.1

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

- Fix issue with `catalystcenter_ip_pool_reservation` resource and multiple IP pools under a single site
- Add `catalystcenter_device_claim_site` resource

## 0.1.1

Expand Down
69 changes: 69 additions & 0 deletions docs/resources/device_claim_site.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "catalystcenter_device_claim_site Resource - terraform-provider-catalystcenter"
subcategory: "Plug and Play"
description: |-
This resource can manage a Device Claim Site.
---

# catalystcenter_device_claim_site (Resource)

This resource can manage a Device Claim Site.

## Example Usage

```terraform
resource "catalystcenter_device_claim_site" "example" {
device_id = "12345678-1234-1234-1234-123456789012"
site_id = "12345678-1234-1234-1234-123456789012"
type = "Default"
image_id = ""
image_skip = true
config_id = "template1"
config_parameters = [
{
name = "HOSTNAME"
value = "switch1"
}
]
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `device_id` (String) The device ID
- `site_id` (String) The site ID
- `type` (String) The device type
- Choices: `Default`, `StackSwitch`, `AccessPoint`, `Sensor`, `CatalystWLC`, `MobilityExpress`

### Optional

- `config_id` (String) Config (temaplate) ID. Required if `type` is `Default` or `StackSwitch`.
- `config_parameters` (Attributes List) List of config (temaplate) parameters. (see [below for nested schema](#nestedatt--config_parameters))
- `gateway` (String) Gateway IP. Required if `type` is `CatalystWLC` or `MobilityExpress`.
- `image_id` (String) Image ID. Required if `type` is `Default` or `StackSwitch`.
- `image_skip` (Boolean) Skip image provisioning.
- `ip_interface_name` (String) IP interface name. Required for Catalyst 9800 WLC.
- `rf_profile` (String) RF profile. Required if `type` is `AccessPoint`.
- `sensor_profile` (String) Sensor profile. Required if `type` is `Sensor`.
- `static_ip` (String) Static IP address. Required if `type` is `CatalystWLC` or `MobilityExpress`.
- `subnet_mask` (String) Subnet mask. Required if `type` is `CatalystWLC` or `MobilityExpress`.
- `vlan_id` (String) Vlan ID. Required for Catalyst 9800 WLC.

### Read-Only

- `id` (String) The id of the object

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

Required:

- `name` (String) Name of config parameter.

Optional:

- `value` (String) Value of config parameter.
14 changes: 14 additions & 0 deletions examples/resources/catalystcenter_device_claim_site/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resource "catalystcenter_device_claim_site" "example" {
device_id = "12345678-1234-1234-1234-123456789012"
site_id = "12345678-1234-1234-1234-123456789012"
type = "Default"
image_id = ""
image_skip = true
config_id = "template1"
config_parameters = [
{
name = "HOSTNAME"
value = "switch1"
}
]
}
96 changes: 96 additions & 0 deletions gen/definitions/device_claim_site.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
name: Device Claim Site
rest_endpoint: /dna/intent/api/v1/onboarding/pnp-device/site-claim
no_data_source: true
no_read: true
no_delete: true
no_import: true
post_update: true
skip_minimum_test: true
doc_category: Plug and Play
test_tags: [PNP]
attributes:
- model_name: deviceId
type: String
mandatory: true
id: true
description: The device ID
example: 12345678-1234-1234-1234-123456789012
- model_name: siteId
type: String
mandatory: true
description: The site ID
example: 12345678-1234-1234-1234-123456789012
- model_name: type
type: String
mandatory: true
enum_values: [Default, StackSwitch, AccessPoint, Sensor, CatalystWLC, MobilityExpress]
description: The device type
example: Default
- model_name: imageId
data_path: imageInfo
type: String
description: Image ID. Required if `type` is `Default` or `StackSwitch`.
example: ""
- model_name: skip
data_path: imageInfo
tf_name: image_skip
type: Bool
description: Skip image provisioning.
example: true
- model_name: configId
data_path: configInfo
type: String
description: Config (temaplate) ID. Required if `type` is `Default` or `StackSwitch`.
example: template1
- model_name: configParameters
data_path: configInfo
type: List
description: List of config (temaplate) parameters.
attributes:
- model_name: key
tf_name: name
id: true
type: String
description: Name of config parameter.
example: HOSTNAME
- model_name: value
type: String
description: Value of config parameter.
example: switch1
- model_name: rfProfile
type: String
description: RF profile. Required if `type` is `AccessPoint`.
example: profile1
exclude_test: true
- model_name: staticIP
tf_name: static_ip
type: String
description: Static IP address. Required if `type` is `CatalystWLC` or `MobilityExpress`.
example: 1.2.3.4
exclude_test: true
- model_name: subnetMask
type: String
description: Subnet mask. Required if `type` is `CatalystWLC` or `MobilityExpress`.
example: 255.255.255.0
exclude_test: true
- model_name: gateway
type: String
description: Gateway IP. Required if `type` is `CatalystWLC` or `MobilityExpress`.
example: 1.2.3.1
exclude_test: true
- model_name: vlanId
type: String
description: Vlan ID. Required for Catalyst 9800 WLC.
example: "100"
exclude_test: true
- model_name: ipInterfaceName
type: String
description: IP interface name. Required for Catalyst 9800 WLC.
example: GigabitEthernet1
exclude_test: true
- model_name: sensorProfile
type: String
description: Sensor profile. Required if `type` is `Sensor`.
example: profile1
exclude_test: true
10 changes: 8 additions & 2 deletions gen/doc_category.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ const (
)

type YamlConfig struct {
Name string `yaml:"name"`
DocCategory string `yaml:"doc_category"`
Name string `yaml:"name"`
DocCategory string `yaml:"doc_category"`
NoResource bool `yaml:"no_resource"`
NoDataSource bool `yaml:"no_data_source"`
}

var docPaths = []string{"./docs/data-sources/", "./docs/resources/"}
Expand Down Expand Up @@ -74,6 +76,10 @@ func main() {
// Update doc category
for i := range configs {
for _, path := range docPaths {
if (configs[i].NoDataSource && path == "./docs/data-sources/") ||
(configs[i].NoResource && path == "./docs/resources/") {
continue
}
filename := path + SnakeCase(configs[i].Name) + ".md"
content, err := os.ReadFile(filename)
if err != nil {
Expand Down
19 changes: 15 additions & 4 deletions gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ var templates = []t{

type YamlConfig struct {
Name string `yaml:"name"`
NoResource bool `yaml:"no_resource"`
NoDataSource bool `yaml:"no_data_source"`
RestEndpoint string `yaml:"rest_endpoint"`
GetRestEndpoint string `yaml:"get_rest_endpoint"`
PutRestEndpoint string `yaml:"put_rest_endpoint"`
Expand All @@ -104,6 +106,8 @@ type YamlConfig struct {
GetRequiresId bool `yaml:"get_requires_id"`
GetExtraQueryParams string `yaml:"get_extra_query_params"`
NoDelete bool `yaml:"no_delete"`
NoRead bool `yaml:"no_read"`
NoImport bool `yaml:"no_import"`
PostUpdate bool `yaml:"post_update"`
RootList bool `yaml:"root_list"`
NoReadPrefix bool `yaml:"no_read_prefix"`
Expand Down Expand Up @@ -410,8 +414,6 @@ func renderTemplate(templatePath, outputPath string, config interface{}) {
}

func main() {
providerConfig := make([]string, 0)

files, _ := os.ReadDir(definitionsPath)
configs := make([]YamlConfig, len(files))

Expand All @@ -436,13 +438,22 @@ func main() {

// Iterate over templates and render files
for _, t := range templates {
if (configs[i].NoImport && t.path == "./gen/templates/import.sh") ||
(configs[i].NoDataSource && t.path == "./gen/templates/data_source.go") ||
(configs[i].NoDataSource && t.path == "./gen/templates/data_source_test.go") ||
(configs[i].NoDataSource && t.path == "./gen/templates/data-source.tf") ||
(configs[i].NoResource && t.path == "./gen/templates/resource.go") ||
(configs[i].NoResource && t.path == "./gen/templates/resource_test.go") ||
(configs[i].NoResource && t.path == "./gen/templates/resource.tf") ||
(configs[i].NoResource && t.path == "./gen/templates/import.sh") {
continue
}
renderTemplate(t.path, t.prefix+SnakeCase(configs[i].Name)+t.suffix, configs[i])
}
providerConfig = append(providerConfig, configs[i].Name)
}

// render provider.go
renderTemplate(providerTemplate, providerLocation, providerConfig)
renderTemplate(providerTemplate, providerLocation, configs)

changelog, err := os.ReadFile(changelogOriginal)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions gen/schema/schema.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
name: str() # Name of the resource
no_resource: bool(required=False) # Set to true if no resource should be created
no_data_source: bool(required=False) # Set to true if no data source should be created
rest_endpoint: str() # REST endpoint path
get_rest_endpoint: str(required=False) # Override GET REST endpoint path
put_rest_endpoint: str(required=False) # Override PUT REST endpoint path
Expand All @@ -9,6 +11,8 @@ get_from_all: bool(required=False) # Set to true if GET does not support queryin
get_requires_id: bool(required=False) # Set to true if the GET request requires an ID in the URL path
get_extra_query_params: str(required=False) # Additional query parameters for GET request
no_delete: bool(required=False) # Set to true if the DELETE request is not supported
no_read: bool(required=False) # Set to true if the GET request is not supported
no_import: bool(required=False) # Set to true if the resource does not support importing
post_update: bool(required=False) # Set to true if the POST request is used for update
root_list: bool(required=False) # Set to true if the root element of the data structure is a list
no_read_prefix: bool(required=False) # Set to true if it is an Open API endpoint put the response is not embeeded into a "response" element
Expand Down
8 changes: 6 additions & 2 deletions gen/templates/provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions gen/templates/resource.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ea2ca16

Please sign in to comment.