Skip to content

Commit

Permalink
Fix import operation of nested resources
Browse files Browse the repository at this point in the history
  • Loading branch information
danischm committed Jan 22, 2024
1 parent 4f88170 commit 2c9d8d2
Show file tree
Hide file tree
Showing 31 changed files with 131 additions and 38 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.11 (unreleased)

- Fix import operation of nested resources (e.g. `ise_network_access_authentication_rule`)

## 0.1.10

- Retry on 400 and 500 HTTP errors when creating or updating objects
Expand Down
4 changes: 4 additions & 0 deletions docs/guides/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ description: |-

# Changelog

## 0.1.11 (unreleased)

- Fix import operation of nested resources (e.g. `ise_network_access_authentication_rule`)

## 0.1.10

- Retry on 400 and 500 HTTP errors when creating or updating objects
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/device_admin_authentication_rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,5 @@ Optional:
Import is supported using the following syntax:

```shell
terraform import ise_device_admin_authentication_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470"
terraform import ise_device_admin_authentication_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470,76d24097-41c4-4558-a4d0-a8c07ac08470"
```
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,5 @@ Optional:
Import is supported using the following syntax:

```shell
terraform import ise_device_admin_authorization_exception_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470"
terraform import ise_device_admin_authorization_exception_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470,76d24097-41c4-4558-a4d0-a8c07ac08470"
```
2 changes: 1 addition & 1 deletion docs/resources/device_admin_authorization_rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,5 @@ Optional:
Import is supported using the following syntax:

```shell
terraform import ise_device_admin_authorization_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470"
terraform import ise_device_admin_authorization_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470,76d24097-41c4-4558-a4d0-a8c07ac08470"
```
2 changes: 1 addition & 1 deletion docs/resources/network_access_authentication_rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,5 @@ Optional:
Import is supported using the following syntax:

```shell
terraform import ise_network_access_authentication_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470"
terraform import ise_network_access_authentication_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470,76d24097-41c4-4558-a4d0-a8c07ac08470"
```
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,5 @@ Optional:
Import is supported using the following syntax:

```shell
terraform import ise_network_access_authorization_exception_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470"
terraform import ise_network_access_authorization_exception_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470,76d24097-41c4-4558-a4d0-a8c07ac08470"
```
2 changes: 1 addition & 1 deletion docs/resources/network_access_authorization_rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,5 @@ Optional:
Import is supported using the following syntax:

```shell
terraform import ise_network_access_authorization_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470"
terraform import ise_network_access_authorization_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470,76d24097-41c4-4558-a4d0-a8c07ac08470"
```
Original file line number Diff line number Diff line change
@@ -1 +1 @@
terraform import ise_device_admin_authentication_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470"
terraform import ise_device_admin_authentication_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470,76d24097-41c4-4558-a4d0-a8c07ac08470"
Original file line number Diff line number Diff line change
@@ -1 +1 @@
terraform import ise_device_admin_authorization_exception_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470"
terraform import ise_device_admin_authorization_exception_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470,76d24097-41c4-4558-a4d0-a8c07ac08470"
Original file line number Diff line number Diff line change
@@ -1 +1 @@
terraform import ise_device_admin_authorization_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470"
terraform import ise_device_admin_authorization_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470,76d24097-41c4-4558-a4d0-a8c07ac08470"
Original file line number Diff line number Diff line change
@@ -1 +1 @@
terraform import ise_network_access_authentication_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470"
terraform import ise_network_access_authentication_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470,76d24097-41c4-4558-a4d0-a8c07ac08470"
Original file line number Diff line number Diff line change
@@ -1 +1 @@
terraform import ise_network_access_authorization_exception_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470"
terraform import ise_network_access_authorization_exception_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470,76d24097-41c4-4558-a4d0-a8c07ac08470"
Original file line number Diff line number Diff line change
@@ -1 +1 @@
terraform import ise_network_access_authorization_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470"
terraform import ise_network_access_authorization_rule.example "76d24097-41c4-4558-a4d0-a8c07ac08470,76d24097-41c4-4558-a4d0-a8c07ac08470"
20 changes: 20 additions & 0 deletions gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,24 @@ func HasReference(attributes []YamlConfigAttribute) bool {
return false
}

// Templating helper function to return number of import parts
func ImportParts(attributes []YamlConfigAttribute) int {
parts := 1
for _, attr := range attributes {
if attr.Reference {
parts += 1
} else if attr.Id {
parts += 1
}
}
return parts
}

// Templating helper function to subtract one number from another
func Subtract(a, b int) int {
return a - b
}

// Templating helper function to return true if ERS API endpoint
func IsErs(endpoint string) bool {
if strings.HasPrefix(endpoint, "/ers") {
Expand All @@ -238,6 +256,8 @@ var functions = template.FuncMap{
"path": BuildPath,
"hasId": HasId,
"hasReference": HasReference,
"importParts": ImportParts,
"subtract": Subtract,
"isErs": IsErs,
}

Expand Down
2 changes: 1 addition & 1 deletion gen/templates/import.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
terraform import ise_{{snakeCase .Name}}.example "{{$id := false}}{{range .Attributes}}{{if .Id}}{{$id = true}}{{.Example}}{{end}}{{end}}{{if not $id}}76d24097-41c4-4558-a4d0-a8c07ac08470{{end}}"
terraform import ise_{{snakeCase .Name}}.example "{{$id := false}}{{range .Attributes}}{{if .Id}}{{$id = true}}{{.Example}}{{end}}{{end}}{{if not $id}}{{range .Attributes}}{{if .Reference}}76d24097-41c4-4558-a4d0-a8c07ac08470,{{end}}{{end}}76d24097-41c4-4558-a4d0-a8c07ac08470{{end}}"
2 changes: 1 addition & 1 deletion gen/templates/model.go

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4 changes: 4 additions & 0 deletions templates/guides/changelog.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ description: |-

# Changelog

## 0.1.11 (unreleased)

- Fix import operation of nested resources (e.g. `ise_network_access_authentication_rule`)

## 0.1.10

- Retry on 400 and 500 HTTP errors when creating or updating objects
Expand Down

0 comments on commit 2c9d8d2

Please sign in to comment.