From 2c9d8d27350f31593574d881c2f9bd8a8e3106df Mon Sep 17 00:00:00 2001 From: danischm Date: Mon, 22 Jan 2024 13:09:52 +0100 Subject: [PATCH] Fix import operation of nested resources --- CHANGELOG.md | 4 ++++ docs/guides/changelog.md | 4 ++++ .../device_admin_authentication_rule.md | 2 +- ...vice_admin_authorization_exception_rule.md | 2 +- .../device_admin_authorization_rule.md | 2 +- .../network_access_authentication_rule.md | 2 +- ...ork_access_authorization_exception_rule.md | 2 +- .../network_access_authorization_rule.md | 2 +- .../import.sh | 2 +- .../import.sh | 2 +- .../import.sh | 2 +- .../import.sh | 2 +- .../import.sh | 2 +- .../import.sh | 2 +- gen/generator.go | 20 +++++++++++++++++++ gen/templates/import.sh | 2 +- gen/templates/model.go | 2 +- gen/templates/resource.go | 19 ++++++++++++++++++ ...el_ise_device_admin_authentication_rule.go | 3 --- ...vice_admin_authorization_exception_rule.go | 3 --- ...del_ise_device_admin_authorization_rule.go | 3 --- ..._ise_network_access_authentication_rule.go | 3 --- ...ork_access_authorization_exception_rule.go | 3 --- ...l_ise_network_access_authorization_rule.go | 3 --- ...ce_ise_device_admin_authentication_rule.go | 12 ++++++++++- ...vice_admin_authorization_exception_rule.go | 12 ++++++++++- ...rce_ise_device_admin_authorization_rule.go | 12 ++++++++++- ..._ise_network_access_authentication_rule.go | 12 ++++++++++- ...ork_access_authorization_exception_rule.go | 12 ++++++++++- ...e_ise_network_access_authorization_rule.go | 12 ++++++++++- templates/guides/changelog.md.tmpl | 4 ++++ 31 files changed, 131 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7cbce4c..b3d3ab8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/guides/changelog.md b/docs/guides/changelog.md index 2db74c23..495f50ab 100644 --- a/docs/guides/changelog.md +++ b/docs/guides/changelog.md @@ -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 diff --git a/docs/resources/device_admin_authentication_rule.md b/docs/resources/device_admin_authentication_rule.md index 2c264d0c..f61c269f 100644 --- a/docs/resources/device_admin_authentication_rule.md +++ b/docs/resources/device_admin_authentication_rule.md @@ -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" ``` diff --git a/docs/resources/device_admin_authorization_exception_rule.md b/docs/resources/device_admin_authorization_exception_rule.md index 0113e069..c2997778 100644 --- a/docs/resources/device_admin_authorization_exception_rule.md +++ b/docs/resources/device_admin_authorization_exception_rule.md @@ -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" ``` diff --git a/docs/resources/device_admin_authorization_rule.md b/docs/resources/device_admin_authorization_rule.md index 68626900..0cb66777 100644 --- a/docs/resources/device_admin_authorization_rule.md +++ b/docs/resources/device_admin_authorization_rule.md @@ -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" ``` diff --git a/docs/resources/network_access_authentication_rule.md b/docs/resources/network_access_authentication_rule.md index e15add23..cbd52dac 100644 --- a/docs/resources/network_access_authentication_rule.md +++ b/docs/resources/network_access_authentication_rule.md @@ -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" ``` diff --git a/docs/resources/network_access_authorization_exception_rule.md b/docs/resources/network_access_authorization_exception_rule.md index 894bdd8d..2a0f84b7 100644 --- a/docs/resources/network_access_authorization_exception_rule.md +++ b/docs/resources/network_access_authorization_exception_rule.md @@ -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" ``` diff --git a/docs/resources/network_access_authorization_rule.md b/docs/resources/network_access_authorization_rule.md index d114f072..7bf5cc76 100644 --- a/docs/resources/network_access_authorization_rule.md +++ b/docs/resources/network_access_authorization_rule.md @@ -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" ``` diff --git a/examples/resources/ise_device_admin_authentication_rule/import.sh b/examples/resources/ise_device_admin_authentication_rule/import.sh index 510746a8..a89f8c22 100644 --- a/examples/resources/ise_device_admin_authentication_rule/import.sh +++ b/examples/resources/ise_device_admin_authentication_rule/import.sh @@ -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" diff --git a/examples/resources/ise_device_admin_authorization_exception_rule/import.sh b/examples/resources/ise_device_admin_authorization_exception_rule/import.sh index 0b092907..c3d24484 100644 --- a/examples/resources/ise_device_admin_authorization_exception_rule/import.sh +++ b/examples/resources/ise_device_admin_authorization_exception_rule/import.sh @@ -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" diff --git a/examples/resources/ise_device_admin_authorization_rule/import.sh b/examples/resources/ise_device_admin_authorization_rule/import.sh index 29ec71bd..bf51ef63 100644 --- a/examples/resources/ise_device_admin_authorization_rule/import.sh +++ b/examples/resources/ise_device_admin_authorization_rule/import.sh @@ -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" diff --git a/examples/resources/ise_network_access_authentication_rule/import.sh b/examples/resources/ise_network_access_authentication_rule/import.sh index 4799714e..554e15ad 100644 --- a/examples/resources/ise_network_access_authentication_rule/import.sh +++ b/examples/resources/ise_network_access_authentication_rule/import.sh @@ -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" diff --git a/examples/resources/ise_network_access_authorization_exception_rule/import.sh b/examples/resources/ise_network_access_authorization_exception_rule/import.sh index 5f6ff306..55021029 100644 --- a/examples/resources/ise_network_access_authorization_exception_rule/import.sh +++ b/examples/resources/ise_network_access_authorization_exception_rule/import.sh @@ -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" diff --git a/examples/resources/ise_network_access_authorization_rule/import.sh b/examples/resources/ise_network_access_authorization_rule/import.sh index ea62ed87..bf6493fa 100644 --- a/examples/resources/ise_network_access_authorization_rule/import.sh +++ b/examples/resources/ise_network_access_authorization_rule/import.sh @@ -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" diff --git a/gen/generator.go b/gen/generator.go index 3077bda3..2d7ac496 100644 --- a/gen/generator.go +++ b/gen/generator.go @@ -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") { @@ -238,6 +256,8 @@ var functions = template.FuncMap{ "path": BuildPath, "hasId": HasId, "hasReference": HasReference, + "importParts": ImportParts, + "subtract": Subtract, "isErs": IsErs, } diff --git a/gen/templates/import.sh b/gen/templates/import.sh index 3b1f5461..1c7fe664 100644 --- a/gen/templates/import.sh +++ b/gen/templates/import.sh @@ -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}}" diff --git a/gen/templates/model.go b/gen/templates/model.go index a77f834a..8396512d 100644 --- a/gen/templates/model.go +++ b/gen/templates/model.go @@ -529,7 +529,7 @@ func (data *{{camelCase .Name}}) updateFromBody(ctx context.Context, res gjson.R //template:begin isNull func (data *{{camelCase .Name}}) isNull(ctx context.Context, res gjson.Result) bool { {{- range .Attributes}} - {{- if not .Value}} + {{- if and (not .Value) (not .Reference)}} {{- if or (eq .Type "List") (eq .Type "Set")}} if len(data.{{toGoName .TfName}}) > 0 { return false diff --git a/gen/templates/resource.go b/gen/templates/resource.go index 92e38b01..1f354093 100644 --- a/gen/templates/resource.go +++ b/gen/templates/resource.go @@ -532,6 +532,25 @@ func (r *{{camelCase .Name}}Resource) Delete(ctx context.Context, req resource.D //template:begin import func (r *{{camelCase .Name}}Resource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + {{- if hasReference .Attributes}} + idParts := strings.Split(req.ID, ",") + + if len(idParts) != {{importParts .Attributes}}{{range $index, $attr := .Attributes}}{{if $attr.Reference}} || idParts[{{$index}}] == ""{{end}}{{end}} || idParts[{{subtract (importParts .Attributes) 1}}] == "" { + resp.Diagnostics.AddError( + "Unexpected Import Identifier", + fmt.Sprintf("Expected import identifier with format: {{range $index, $attr := .Attributes}}{{if $attr.Reference}}{{if $index}},{{end}}<{{$attr.TfName}}>{{end}}{{end}},. Got: %q", req.ID), + ) + return + } + + {{- range $index, $attr := .Attributes}} + {{- if or $attr.Reference $attr.Id}} + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("{{$attr.TfName}}"), idParts[{{$index}}])...) + {{- end}} + {{- end}} + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), idParts[{{subtract (importParts .Attributes) 1}}])...) + {{- else}} resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + {{- end}} } //template:end import diff --git a/internal/provider/model_ise_device_admin_authentication_rule.go b/internal/provider/model_ise_device_admin_authentication_rule.go index bc88ec2a..eb396871 100644 --- a/internal/provider/model_ise_device_admin_authentication_rule.go +++ b/internal/provider/model_ise_device_admin_authentication_rule.go @@ -603,9 +603,6 @@ func (data *DeviceAdminAuthenticationRule) updateFromBody(ctx context.Context, r //template:begin isNull func (data *DeviceAdminAuthenticationRule) isNull(ctx context.Context, res gjson.Result) bool { - if !data.PolicySetId.IsNull() { - return false - } if !data.Name.IsNull() { return false } diff --git a/internal/provider/model_ise_device_admin_authorization_exception_rule.go b/internal/provider/model_ise_device_admin_authorization_exception_rule.go index ebc2a863..3a1b6420 100644 --- a/internal/provider/model_ise_device_admin_authorization_exception_rule.go +++ b/internal/provider/model_ise_device_admin_authorization_exception_rule.go @@ -578,9 +578,6 @@ func (data *DeviceAdminAuthorizationExceptionRule) updateFromBody(ctx context.Co //template:begin isNull func (data *DeviceAdminAuthorizationExceptionRule) isNull(ctx context.Context, res gjson.Result) bool { - if !data.PolicySetId.IsNull() { - return false - } if !data.Name.IsNull() { return false } diff --git a/internal/provider/model_ise_device_admin_authorization_rule.go b/internal/provider/model_ise_device_admin_authorization_rule.go index f183e115..840c8ef4 100644 --- a/internal/provider/model_ise_device_admin_authorization_rule.go +++ b/internal/provider/model_ise_device_admin_authorization_rule.go @@ -578,9 +578,6 @@ func (data *DeviceAdminAuthorizationRule) updateFromBody(ctx context.Context, re //template:begin isNull func (data *DeviceAdminAuthorizationRule) isNull(ctx context.Context, res gjson.Result) bool { - if !data.PolicySetId.IsNull() { - return false - } if !data.Name.IsNull() { return false } diff --git a/internal/provider/model_ise_network_access_authentication_rule.go b/internal/provider/model_ise_network_access_authentication_rule.go index a53bde0e..039436fb 100644 --- a/internal/provider/model_ise_network_access_authentication_rule.go +++ b/internal/provider/model_ise_network_access_authentication_rule.go @@ -603,9 +603,6 @@ func (data *NetworkAccessAuthenticationRule) updateFromBody(ctx context.Context, //template:begin isNull func (data *NetworkAccessAuthenticationRule) isNull(ctx context.Context, res gjson.Result) bool { - if !data.PolicySetId.IsNull() { - return false - } if !data.Name.IsNull() { return false } diff --git a/internal/provider/model_ise_network_access_authorization_exception_rule.go b/internal/provider/model_ise_network_access_authorization_exception_rule.go index a384f9b3..1e4a2442 100644 --- a/internal/provider/model_ise_network_access_authorization_exception_rule.go +++ b/internal/provider/model_ise_network_access_authorization_exception_rule.go @@ -578,9 +578,6 @@ func (data *NetworkAccessAuthorizationExceptionRule) updateFromBody(ctx context. //template:begin isNull func (data *NetworkAccessAuthorizationExceptionRule) isNull(ctx context.Context, res gjson.Result) bool { - if !data.PolicySetId.IsNull() { - return false - } if !data.Name.IsNull() { return false } diff --git a/internal/provider/model_ise_network_access_authorization_rule.go b/internal/provider/model_ise_network_access_authorization_rule.go index 5b82ff81..ede4c09f 100644 --- a/internal/provider/model_ise_network_access_authorization_rule.go +++ b/internal/provider/model_ise_network_access_authorization_rule.go @@ -578,9 +578,6 @@ func (data *NetworkAccessAuthorizationRule) updateFromBody(ctx context.Context, //template:begin isNull func (data *NetworkAccessAuthorizationRule) isNull(ctx context.Context, res gjson.Result) bool { - if !data.PolicySetId.IsNull() { - return false - } if !data.Name.IsNull() { return false } diff --git a/internal/provider/resource_ise_device_admin_authentication_rule.go b/internal/provider/resource_ise_device_admin_authentication_rule.go index f4da9531..9522ce38 100644 --- a/internal/provider/resource_ise_device_admin_authentication_rule.go +++ b/internal/provider/resource_ise_device_admin_authentication_rule.go @@ -395,7 +395,17 @@ func (r *DeviceAdminAuthenticationRuleResource) Delete(ctx context.Context, req //template:begin import func (r *DeviceAdminAuthenticationRuleResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + idParts := strings.Split(req.ID, ",") + + if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" { + resp.Diagnostics.AddError( + "Unexpected Import Identifier", + fmt.Sprintf("Expected import identifier with format: ,. Got: %q", req.ID), + ) + return + } + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("policy_set_id"), idParts[0])...) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), idParts[1])...) } //template:end import diff --git a/internal/provider/resource_ise_device_admin_authorization_exception_rule.go b/internal/provider/resource_ise_device_admin_authorization_exception_rule.go index 4f624ddc..734c6854 100644 --- a/internal/provider/resource_ise_device_admin_authorization_exception_rule.go +++ b/internal/provider/resource_ise_device_admin_authorization_exception_rule.go @@ -379,7 +379,17 @@ func (r *DeviceAdminAuthorizationExceptionRuleResource) Delete(ctx context.Conte //template:begin import func (r *DeviceAdminAuthorizationExceptionRuleResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + idParts := strings.Split(req.ID, ",") + + if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" { + resp.Diagnostics.AddError( + "Unexpected Import Identifier", + fmt.Sprintf("Expected import identifier with format: ,. Got: %q", req.ID), + ) + return + } + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("policy_set_id"), idParts[0])...) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), idParts[1])...) } //template:end import diff --git a/internal/provider/resource_ise_device_admin_authorization_rule.go b/internal/provider/resource_ise_device_admin_authorization_rule.go index 1cca8575..cadda8bc 100644 --- a/internal/provider/resource_ise_device_admin_authorization_rule.go +++ b/internal/provider/resource_ise_device_admin_authorization_rule.go @@ -379,7 +379,17 @@ func (r *DeviceAdminAuthorizationRuleResource) Delete(ctx context.Context, req r //template:begin import func (r *DeviceAdminAuthorizationRuleResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + idParts := strings.Split(req.ID, ",") + + if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" { + resp.Diagnostics.AddError( + "Unexpected Import Identifier", + fmt.Sprintf("Expected import identifier with format: ,. Got: %q", req.ID), + ) + return + } + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("policy_set_id"), idParts[0])...) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), idParts[1])...) } //template:end import diff --git a/internal/provider/resource_ise_network_access_authentication_rule.go b/internal/provider/resource_ise_network_access_authentication_rule.go index 1e0b324d..cfbcfafa 100644 --- a/internal/provider/resource_ise_network_access_authentication_rule.go +++ b/internal/provider/resource_ise_network_access_authentication_rule.go @@ -395,7 +395,17 @@ func (r *NetworkAccessAuthenticationRuleResource) Delete(ctx context.Context, re //template:begin import func (r *NetworkAccessAuthenticationRuleResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + idParts := strings.Split(req.ID, ",") + + if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" { + resp.Diagnostics.AddError( + "Unexpected Import Identifier", + fmt.Sprintf("Expected import identifier with format: ,. Got: %q", req.ID), + ) + return + } + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("policy_set_id"), idParts[0])...) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), idParts[1])...) } //template:end import diff --git a/internal/provider/resource_ise_network_access_authorization_exception_rule.go b/internal/provider/resource_ise_network_access_authorization_exception_rule.go index 169b3607..dcef907d 100644 --- a/internal/provider/resource_ise_network_access_authorization_exception_rule.go +++ b/internal/provider/resource_ise_network_access_authorization_exception_rule.go @@ -379,7 +379,17 @@ func (r *NetworkAccessAuthorizationExceptionRuleResource) Delete(ctx context.Con //template:begin import func (r *NetworkAccessAuthorizationExceptionRuleResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + idParts := strings.Split(req.ID, ",") + + if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" { + resp.Diagnostics.AddError( + "Unexpected Import Identifier", + fmt.Sprintf("Expected import identifier with format: ,. Got: %q", req.ID), + ) + return + } + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("policy_set_id"), idParts[0])...) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), idParts[1])...) } //template:end import diff --git a/internal/provider/resource_ise_network_access_authorization_rule.go b/internal/provider/resource_ise_network_access_authorization_rule.go index e7f962e3..bbf440cc 100644 --- a/internal/provider/resource_ise_network_access_authorization_rule.go +++ b/internal/provider/resource_ise_network_access_authorization_rule.go @@ -379,7 +379,17 @@ func (r *NetworkAccessAuthorizationRuleResource) Delete(ctx context.Context, req //template:begin import func (r *NetworkAccessAuthorizationRuleResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { - resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) + idParts := strings.Split(req.ID, ",") + + if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" { + resp.Diagnostics.AddError( + "Unexpected Import Identifier", + fmt.Sprintf("Expected import identifier with format: ,. Got: %q", req.ID), + ) + return + } + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("policy_set_id"), idParts[0])...) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), idParts[1])...) } //template:end import diff --git a/templates/guides/changelog.md.tmpl b/templates/guides/changelog.md.tmpl index 2db74c23..495f50ab 100644 --- a/templates/guides/changelog.md.tmpl +++ b/templates/guides/changelog.md.tmpl @@ -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