From 176a6cb5d3a77812509d31d474ecaf5133172141 Mon Sep 17 00:00:00 2001 From: Gaspard Micol Date: Fri, 16 Aug 2024 09:35:56 -0400 Subject: [PATCH] [ignore] Fix resourceName set to singular when max class allowed set to one. Modify Logic for generating Rs class set to one max class allowed. --- .../data-sources/access_interface_override.md | 2 +- docs/resources/access_interface_override.md | 4 ++-- .../resource-all-attributes.tf | 2 +- gen/generator.go | 8 +++---- gen/templates/provider.go.tmpl | 4 ++-- gen/testvars/infraHPathS.yaml | 2 +- ...ta_source_aci_access_interface_override.go | 2 +- .../resource_aci_access_interface_override.go | 4 ++-- ...urce_aci_access_interface_override_test.go | 22 +++++++++---------- 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/docs/data-sources/access_interface_override.md b/docs/data-sources/access_interface_override.md index c18a68bb2..98a5963ab 100644 --- a/docs/data-sources/access_interface_override.md +++ b/docs/data-sources/access_interface_override.md @@ -59,7 +59,7 @@ data "aci_access_interface_override" "example" { * `owner_key` (ownerKey) - (string) The key for enabling clients to own their data for entity correlation. * `owner_tag` (ownerTag) - (string) A tag for enabling clients to add their own data. For example, to indicate who created this object. -* `relation_to_host_paths` - (list) A list of Relation To Host Paths (ACI object [infraRsHPathAtt](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/infraRsHPathAtt/overview)) pointing to (ACI Object [fabricPathEp](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fabricPathEp/overview)). +* `relation_to_host_path` - (list) A list of Relation To Host Path (ACI object [infraRsHPathAtt](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/infraRsHPathAtt/overview)) pointing to (ACI Object [fabricPathEp](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fabricPathEp/overview)). * `annotation` (annotation) - (string) The annotation of the Relation To Host Path object. * `target_dn` (tDn) - (string) The distinguished name of the target. diff --git a/docs/resources/access_interface_override.md b/docs/resources/access_interface_override.md index 9f124b902..6c84d70b7 100644 --- a/docs/resources/access_interface_override.md +++ b/docs/resources/access_interface_override.md @@ -54,7 +54,7 @@ resource "aci_access_interface_override" "full_example" { name_alias = "name_alias_1" owner_key = "owner_key_1" owner_tag = "owner_tag_1" - relation_to_host_paths = [ + relation_to_host_path = [ { annotation = "annotation_1" target_dn = "topology/pod-1/paths-101/pathep-[eth1/1]" @@ -108,7 +108,7 @@ All examples for the Access Interface Override resource can be found in the [exa * `owner_key` (ownerKey) - (string) The key for enabling clients to own their data for entity correlation. * `owner_tag` (ownerTag) - (string) A tag for enabling clients to add their own data. For example, to indicate who created this object. -* `relation_to_host_paths` - (list) A list of Relation To Host Paths (ACI object [infraRsHPathAtt](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/infraRsHPathAtt/overview)) pointing to (ACI Object [fabricPathEp](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fabricPathEp/overview)). +* `relation_to_host_path` - (list) A list of Relation To Host Path (ACI object [infraRsHPathAtt](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/infraRsHPathAtt/overview)) pointing to (ACI Object [fabricPathEp](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fabricPathEp/overview)). - Max Items: 1 #### Required #### diff --git a/examples/resources/aci_access_interface_override/resource-all-attributes.tf b/examples/resources/aci_access_interface_override/resource-all-attributes.tf index 08c7d691a..142c2d6de 100644 --- a/examples/resources/aci_access_interface_override/resource-all-attributes.tf +++ b/examples/resources/aci_access_interface_override/resource-all-attributes.tf @@ -6,7 +6,7 @@ resource "aci_access_interface_override" "full_example" { name_alias = "name_alias_1" owner_key = "owner_key_1" owner_tag = "owner_tag_1" - relation_to_host_paths = [ + relation_to_host_path = [ { annotation = "annotation_1" target_dn = "topology/pod-1/paths-101/pathep-[eth1/1]" diff --git a/gen/generator.go b/gen/generator.go index 37cdb42d3..22f389cab 100644 --- a/gen/generator.go +++ b/gen/generator.go @@ -712,9 +712,9 @@ func main() { for _, model := range classModels { // Only render resources and datasources when the class has a unique identifier or is marked as include in the classes definitions YAML file - // And only render when the class is also not a Rs object and is not set to max one class allowed - // TODO might need to extend this last condition in the future - if (len(model.IdentifiedBy) > 0 || model.Include) && !(strings.HasPrefix(model.RnFormat, "rs") && model.MaxOneClassAllowed) { + // And if the class has a unique identifier, only render when the class is also not a Rs object and is not set to max one class allowed + // TODO might need to modify this last condition in the future + if (len(model.IdentifiedBy) > 0 && !(strings.HasPrefix(model.RnFormat, "rs") && model.MaxOneClassAllowed)) || model.Include { // All classmodels have been read, thus now the model, child and relational resources names can be set // When done before additional files would need to be opened and read which would slow down the generation process @@ -726,7 +726,7 @@ func main() { childMap := make(map[string]Model, 0) for childName, childModel := range model.Children { childModel.ChildResourceName = GetResourceName(childModel.PkgName, definitions) - if len(childModel.IdentifiedBy) > 0 { + if len(childModel.IdentifiedBy) > 0 && !(strings.HasPrefix(childModel.RnFormat, "rs") && childModel.MaxOneClassAllowed) { // TODO add logic to determine the naming for plural child resources childModel.ResourceNameDocReference = childModel.ChildResourceName childModel.ResourceName = fmt.Sprintf("%ss", childModel.ChildResourceName) diff --git a/gen/templates/provider.go.tmpl b/gen/templates/provider.go.tmpl index 4d4b0ee7d..d6c2440bc 100644 --- a/gen/templates/provider.go.tmpl +++ b/gen/templates/provider.go.tmpl @@ -204,7 +204,7 @@ func (p *AciProvider) Configure(ctx context.Context, req provider.ConfigureReque func (p *AciProvider) Resources(ctx context.Context) []func() resource.Resource { return []func() resource.Resource{ {{- range . }} - {{- if and (or .IdentifiedBy .Include) (not (and .MaxOneClassAllowed (hasPrefix .RnFormat "rs")))}} + {{- if or (and .IdentifiedBy (not (and .MaxOneClassAllowed (hasPrefix .RnFormat "rs")))) .Include}} New{{.ResourceClassName}}Resource, {{- end }} {{- end }} @@ -215,7 +215,7 @@ func (p *AciProvider) Resources(ctx context.Context) []func() resource.Resource func (p *AciProvider) DataSources(ctx context.Context) []func() datasource.DataSource { return []func() datasource.DataSource{ {{- range . }} - {{- if and (or .IdentifiedBy .Include) (not (and .MaxOneClassAllowed (hasPrefix .RnFormat "rs")))}} + {{- if or (and .IdentifiedBy (not (and .MaxOneClassAllowed (hasPrefix .RnFormat "rs")))) .Include}} New{{.ResourceClassName}}DataSource, {{- end }} {{- end }} diff --git a/gen/testvars/infraHPathS.yaml b/gen/testvars/infraHPathS.yaml index f6695b83c..762f04161 100644 --- a/gen/testvars/infraHPathS.yaml +++ b/gen/testvars/infraHPathS.yaml @@ -26,7 +26,7 @@ all: owner_tag: "owner_tag_1" children: - relation_to_host_paths: + relation_to_host_path: - annotation: "annotation_1" target_dn: "target_dn_0" deletable_child: true diff --git a/internal/provider/data_source_aci_access_interface_override.go b/internal/provider/data_source_aci_access_interface_override.go index 7ffc28cb4..7169293f2 100644 --- a/internal/provider/data_source_aci_access_interface_override.go +++ b/internal/provider/data_source_aci_access_interface_override.go @@ -73,7 +73,7 @@ func (d *InfraHPathSDataSource) Schema(ctx context.Context, req datasource.Schem Computed: true, MarkdownDescription: `A tag for enabling clients to add their own data. For example, to indicate who created this object.`, }, - "relation_to_host_paths": schema.SetNestedAttribute{ + "relation_to_host_path": schema.SetNestedAttribute{ MarkdownDescription: ``, Computed: true, NestedObject: schema.NestedAttributeObject{ diff --git a/internal/provider/resource_aci_access_interface_override.go b/internal/provider/resource_aci_access_interface_override.go index ab6d5c99d..e0034b32d 100644 --- a/internal/provider/resource_aci_access_interface_override.go +++ b/internal/provider/resource_aci_access_interface_override.go @@ -52,7 +52,7 @@ type InfraHPathSResourceModel struct { NameAlias types.String `tfsdk:"name_alias"` OwnerKey types.String `tfsdk:"owner_key"` OwnerTag types.String `tfsdk:"owner_tag"` - InfraRsHPathAtt types.Set `tfsdk:"relation_to_host_paths"` + InfraRsHPathAtt types.Set `tfsdk:"relation_to_host_path"` InfraRsPathToAccBaseGrp types.Set `tfsdk:"relation_to_access_interface_policy_group"` TagAnnotation types.Set `tfsdk:"annotations"` TagTag types.Set `tfsdk:"tags"` @@ -261,7 +261,7 @@ func (r *InfraHPathSResource) Schema(ctx context.Context, req resource.SchemaReq }, MarkdownDescription: `A tag for enabling clients to add their own data. For example, to indicate who created this object.`, }, - "relation_to_host_paths": schema.SetNestedAttribute{ + "relation_to_host_path": schema.SetNestedAttribute{ MarkdownDescription: ``, Optional: true, Computed: true, diff --git a/internal/provider/resource_aci_access_interface_override_test.go b/internal/provider/resource_aci_access_interface_override_test.go index 27dd976b3..013c13939 100644 --- a/internal/provider/resource_aci_access_interface_override_test.go +++ b/internal/provider/resource_aci_access_interface_override_test.go @@ -152,9 +152,9 @@ func TestAccResourceInfraHPathS(t *testing.T) { resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_access_interface_policy_group.0.annotation", "annotation_1"), resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_access_interface_policy_group.0.target_dn", "uni/infra/funcprof/accportgrp-access_interface_policy_group"), resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_access_interface_policy_group.#", "1"), - resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_host_paths.0.annotation", "annotation_1"), - resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_host_paths.0.target_dn", "topology/pod-1/paths-101/pathep-[eth1/1]"), - resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_host_paths.#", "1"), + resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_host_path.0.annotation", "annotation_1"), + resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_host_path.0.target_dn", "topology/pod-1/paths-101/pathep-[eth1/1]"), + resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_host_path.#", "1"), resource.TestCheckResourceAttr("aci_access_interface_override.test", "tags.0.key", "key_0"), resource.TestCheckResourceAttr("aci_access_interface_override.test", "tags.0.value", "value_1"), resource.TestCheckResourceAttr("aci_access_interface_override.test", "tags.1.key", "key_1"), @@ -179,9 +179,9 @@ func TestAccResourceInfraHPathS(t *testing.T) { resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_access_interface_policy_group.0.annotation", "annotation_1"), resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_access_interface_policy_group.0.target_dn", "uni/infra/funcprof/accportgrp-access_interface_policy_group"), resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_access_interface_policy_group.#", "1"), - resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_host_paths.0.annotation", "annotation_1"), - resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_host_paths.0.target_dn", "topology/pod-1/paths-101/pathep-[eth1/1]"), - resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_host_paths.#", "1"), + resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_host_path.0.annotation", "annotation_1"), + resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_host_path.0.target_dn", "topology/pod-1/paths-101/pathep-[eth1/1]"), + resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_host_path.#", "1"), resource.TestCheckResourceAttr("aci_access_interface_override.test", "tags.0.key", "key_0"), resource.TestCheckResourceAttr("aci_access_interface_override.test", "tags.0.value", "value_1"), resource.TestCheckResourceAttr("aci_access_interface_override.test", "tags.1.key", "key_1"), @@ -202,7 +202,7 @@ func TestAccResourceInfraHPathS(t *testing.T) { resource.TestCheckResourceAttr("aci_access_interface_override.test", "annotations.0.value", "test_value"), resource.TestCheckResourceAttr("aci_access_interface_override.test", "annotations.#", "1"), resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_access_interface_policy_group.#", "0"), - resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_host_paths.#", "0"), + resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_host_path.#", "0"), resource.TestCheckResourceAttr("aci_access_interface_override.test", "tags.0.key", "key_1"), resource.TestCheckResourceAttr("aci_access_interface_override.test", "tags.0.value", "test_value"), resource.TestCheckResourceAttr("aci_access_interface_override.test", "tags.#", "1"), @@ -219,7 +219,7 @@ func TestAccResourceInfraHPathS(t *testing.T) { resource.TestCheckResourceAttr("aci_access_interface_override.test", "owner_tag", ""), resource.TestCheckResourceAttr("aci_access_interface_override.test", "annotations.#", "0"), resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_access_interface_policy_group.#", "0"), - resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_host_paths.#", "0"), + resource.TestCheckResourceAttr("aci_access_interface_override.test", "relation_to_host_path.#", "0"), resource.TestCheckResourceAttr("aci_access_interface_override.test", "tags.#", "0"), ), }, @@ -286,7 +286,7 @@ resource "aci_access_interface_override" "test" { target_dn = "uni/infra/funcprof/accportgrp-access_interface_policy_group" }, ] - relation_to_host_paths = [ + relation_to_host_path = [ { annotation = "annotation_1" target_dn = "topology/pod-1/paths-101/pathep-[eth1/1]" @@ -321,7 +321,7 @@ resource "aci_access_interface_override" "test" { }, ] relation_to_access_interface_policy_group = [] - relation_to_host_paths = [] + relation_to_host_path = [] tags = [ { key = "key_1" @@ -336,7 +336,7 @@ resource "aci_access_interface_override" "test" { name = "host_path_selector" annotations = [] relation_to_access_interface_policy_group = [] - relation_to_host_paths = [] + relation_to_host_path = [] tags = [] } `