diff --git a/CHANGELOG.md b/CHANGELOG.md index b3d3ab8..bc3aa3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 0.1.11 (unreleased) - Fix import operation of nested resources (e.g. `ise_network_access_authentication_rule`) +- Fix name-based queries for `device_admin` and `network_access` data sources ## 0.1.10 diff --git a/docs/guides/changelog.md b/docs/guides/changelog.md index 495f50a..9b4f442 100644 --- a/docs/guides/changelog.md +++ b/docs/guides/changelog.md @@ -10,6 +10,7 @@ description: |- ## 0.1.11 (unreleased) - Fix import operation of nested resources (e.g. `ise_network_access_authentication_rule`) +- Fix name-based queries for `device_admin` and `network_access` data sources ## 0.1.10 diff --git a/gen/generator.go b/gen/generator.go index 8370eb1..722a5d9 100644 --- a/gen/generator.go +++ b/gen/generator.go @@ -247,19 +247,26 @@ func IsErs(endpoint string) bool { return false } +// Templating helper function to remove first path element +func RemoveFirstPathElement(path string) string { + elements := strings.Split(path, ".") + return strings.Join(elements[1:], ".") +} + // Map of templating functions var functions = template.FuncMap{ - "toGoName": ToGoName, - "camelCase": CamelCase, - "snakeCase": SnakeCase, - "sprintf": fmt.Sprintf, - "toLower": strings.ToLower, - "path": BuildPath, - "hasId": HasId, - "hasReference": HasReference, - "importParts": ImportParts, - "subtract": Subtract, - "isErs": IsErs, + "toGoName": ToGoName, + "camelCase": CamelCase, + "snakeCase": SnakeCase, + "sprintf": fmt.Sprintf, + "toLower": strings.ToLower, + "path": BuildPath, + "hasId": HasId, + "hasReference": HasReference, + "importParts": ImportParts, + "subtract": Subtract, + "isErs": IsErs, + "removeFirstPathElement": RemoveFirstPathElement, } func augmentAttribute(attr *YamlConfigAttribute) { diff --git a/gen/templates/data_source.go b/gen/templates/data_source.go index 30e1677..5ef01c3 100644 --- a/gen/templates/data_source.go +++ b/gen/templates/data_source.go @@ -190,8 +190,8 @@ func (d *{{camelCase .Name}}DataSource) Read(ctx context.Context, req datasource } if value := res.Get({{if $openApi}}"response"{{else}}"SearchResult.resources"{{end}}); len(value.Array()) > 0 { value.ForEach(func(k, v gjson.Result) bool { - if config.Name.ValueString() == v.Get("name").String() { - config.Id = types.StringValue(v.Get("id").String()) + if config.Name.ValueString() == v.Get("{{if $openApi}}{{range .Attributes}}{{if eq .TfName "name"}}{{range .DataPath}}{{.}}.{{end}}{{end}}{{end}}{{end}}name").String() { + config.Id = types.StringValue(v.Get("{{if .IdPath}}{{removeFirstPathElement .IdPath}}{{else}}id{{end}}").String()) tflog.Debug(ctx, fmt.Sprintf("%s: Found object with name '%v', id: %v", config.Id.String(), config.Name.ValueString(), config.Id.String())) return false } diff --git a/internal/provider/data_source_ise_device_admin_authentication_rule.go b/internal/provider/data_source_ise_device_admin_authentication_rule.go index 710d7be..e5fd17e 100644 --- a/internal/provider/data_source_ise_device_admin_authentication_rule.go +++ b/internal/provider/data_source_ise_device_admin_authentication_rule.go @@ -259,8 +259,8 @@ func (d *DeviceAdminAuthenticationRuleDataSource) Read(ctx context.Context, req } if value := res.Get("response"); len(value.Array()) > 0 { value.ForEach(func(k, v gjson.Result) bool { - if config.Name.ValueString() == v.Get("name").String() { - config.Id = types.StringValue(v.Get("id").String()) + if config.Name.ValueString() == v.Get("rule.name").String() { + config.Id = types.StringValue(v.Get("rule.id").String()) tflog.Debug(ctx, fmt.Sprintf("%s: Found object with name '%v', id: %v", config.Id.String(), config.Name.ValueString(), config.Id.String())) return false } diff --git a/internal/provider/data_source_ise_device_admin_authorization_exception_rule.go b/internal/provider/data_source_ise_device_admin_authorization_exception_rule.go index f68dba4..21cd2a6 100644 --- a/internal/provider/data_source_ise_device_admin_authorization_exception_rule.go +++ b/internal/provider/data_source_ise_device_admin_authorization_exception_rule.go @@ -252,8 +252,8 @@ func (d *DeviceAdminAuthorizationExceptionRuleDataSource) Read(ctx context.Conte } if value := res.Get("response"); len(value.Array()) > 0 { value.ForEach(func(k, v gjson.Result) bool { - if config.Name.ValueString() == v.Get("name").String() { - config.Id = types.StringValue(v.Get("id").String()) + if config.Name.ValueString() == v.Get("rule.name").String() { + config.Id = types.StringValue(v.Get("rule.id").String()) tflog.Debug(ctx, fmt.Sprintf("%s: Found object with name '%v', id: %v", config.Id.String(), config.Name.ValueString(), config.Id.String())) return false } diff --git a/internal/provider/data_source_ise_device_admin_authorization_global_exception_rule.go b/internal/provider/data_source_ise_device_admin_authorization_global_exception_rule.go index c8e6fbb..2752757 100644 --- a/internal/provider/data_source_ise_device_admin_authorization_global_exception_rule.go +++ b/internal/provider/data_source_ise_device_admin_authorization_global_exception_rule.go @@ -248,8 +248,8 @@ func (d *DeviceAdminAuthorizationGlobalExceptionRuleDataSource) Read(ctx context } if value := res.Get("response"); len(value.Array()) > 0 { value.ForEach(func(k, v gjson.Result) bool { - if config.Name.ValueString() == v.Get("name").String() { - config.Id = types.StringValue(v.Get("id").String()) + if config.Name.ValueString() == v.Get("rule.name").String() { + config.Id = types.StringValue(v.Get("rule.id").String()) tflog.Debug(ctx, fmt.Sprintf("%s: Found object with name '%v', id: %v", config.Id.String(), config.Name.ValueString(), config.Id.String())) return false } diff --git a/internal/provider/data_source_ise_device_admin_authorization_rule.go b/internal/provider/data_source_ise_device_admin_authorization_rule.go index 5a614fc..67292ca 100644 --- a/internal/provider/data_source_ise_device_admin_authorization_rule.go +++ b/internal/provider/data_source_ise_device_admin_authorization_rule.go @@ -252,8 +252,8 @@ func (d *DeviceAdminAuthorizationRuleDataSource) Read(ctx context.Context, req d } if value := res.Get("response"); len(value.Array()) > 0 { value.ForEach(func(k, v gjson.Result) bool { - if config.Name.ValueString() == v.Get("name").String() { - config.Id = types.StringValue(v.Get("id").String()) + if config.Name.ValueString() == v.Get("rule.name").String() { + config.Id = types.StringValue(v.Get("rule.id").String()) tflog.Debug(ctx, fmt.Sprintf("%s: Found object with name '%v', id: %v", config.Id.String(), config.Name.ValueString(), config.Id.String())) return false } diff --git a/internal/provider/data_source_ise_network_access_authentication_rule.go b/internal/provider/data_source_ise_network_access_authentication_rule.go index 694111d..44b9d57 100644 --- a/internal/provider/data_source_ise_network_access_authentication_rule.go +++ b/internal/provider/data_source_ise_network_access_authentication_rule.go @@ -259,8 +259,8 @@ func (d *NetworkAccessAuthenticationRuleDataSource) Read(ctx context.Context, re } if value := res.Get("response"); len(value.Array()) > 0 { value.ForEach(func(k, v gjson.Result) bool { - if config.Name.ValueString() == v.Get("name").String() { - config.Id = types.StringValue(v.Get("id").String()) + if config.Name.ValueString() == v.Get("rule.name").String() { + config.Id = types.StringValue(v.Get("rule.id").String()) tflog.Debug(ctx, fmt.Sprintf("%s: Found object with name '%v', id: %v", config.Id.String(), config.Name.ValueString(), config.Id.String())) return false } diff --git a/internal/provider/data_source_ise_network_access_authorization_exception_rule.go b/internal/provider/data_source_ise_network_access_authorization_exception_rule.go index 9f55af4..8d16194 100644 --- a/internal/provider/data_source_ise_network_access_authorization_exception_rule.go +++ b/internal/provider/data_source_ise_network_access_authorization_exception_rule.go @@ -252,8 +252,8 @@ func (d *NetworkAccessAuthorizationExceptionRuleDataSource) Read(ctx context.Con } if value := res.Get("response"); len(value.Array()) > 0 { value.ForEach(func(k, v gjson.Result) bool { - if config.Name.ValueString() == v.Get("name").String() { - config.Id = types.StringValue(v.Get("id").String()) + if config.Name.ValueString() == v.Get("rule.name").String() { + config.Id = types.StringValue(v.Get("rule.id").String()) tflog.Debug(ctx, fmt.Sprintf("%s: Found object with name '%v', id: %v", config.Id.String(), config.Name.ValueString(), config.Id.String())) return false } diff --git a/internal/provider/data_source_ise_network_access_authorization_global_exception_rule.go b/internal/provider/data_source_ise_network_access_authorization_global_exception_rule.go index 0731e77..e4af4d4 100644 --- a/internal/provider/data_source_ise_network_access_authorization_global_exception_rule.go +++ b/internal/provider/data_source_ise_network_access_authorization_global_exception_rule.go @@ -248,8 +248,8 @@ func (d *NetworkAccessAuthorizationGlobalExceptionRuleDataSource) Read(ctx conte } if value := res.Get("response"); len(value.Array()) > 0 { value.ForEach(func(k, v gjson.Result) bool { - if config.Name.ValueString() == v.Get("name").String() { - config.Id = types.StringValue(v.Get("id").String()) + if config.Name.ValueString() == v.Get("rule.name").String() { + config.Id = types.StringValue(v.Get("rule.id").String()) tflog.Debug(ctx, fmt.Sprintf("%s: Found object with name '%v', id: %v", config.Id.String(), config.Name.ValueString(), config.Id.String())) return false } diff --git a/internal/provider/data_source_ise_network_access_authorization_rule.go b/internal/provider/data_source_ise_network_access_authorization_rule.go index 269b0d8..5f7ed42 100644 --- a/internal/provider/data_source_ise_network_access_authorization_rule.go +++ b/internal/provider/data_source_ise_network_access_authorization_rule.go @@ -252,8 +252,8 @@ func (d *NetworkAccessAuthorizationRuleDataSource) Read(ctx context.Context, req } if value := res.Get("response"); len(value.Array()) > 0 { value.ForEach(func(k, v gjson.Result) bool { - if config.Name.ValueString() == v.Get("name").String() { - config.Id = types.StringValue(v.Get("id").String()) + if config.Name.ValueString() == v.Get("rule.name").String() { + config.Id = types.StringValue(v.Get("rule.id").String()) tflog.Debug(ctx, fmt.Sprintf("%s: Found object with name '%v', id: %v", config.Id.String(), config.Name.ValueString(), config.Id.String())) return false } diff --git a/templates/guides/changelog.md.tmpl b/templates/guides/changelog.md.tmpl index 495f50a..9b4f442 100644 --- a/templates/guides/changelog.md.tmpl +++ b/templates/guides/changelog.md.tmpl @@ -10,6 +10,7 @@ description: |- ## 0.1.11 (unreleased) - Fix import operation of nested resources (e.g. `ise_network_access_authentication_rule`) +- Fix name-based queries for `device_admin` and `network_access` data sources ## 0.1.10