Skip to content

Commit

Permalink
[ignore] Fix resourceName set to singular when max class allowed set …
Browse files Browse the repository at this point in the history
…to one. Modify Logic for generating Rs class set to one max class allowed.
  • Loading branch information
gmicol authored and lhercot committed Aug 20, 2024
1 parent fb93cb5 commit 176a6cb
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docs/data-sources/access_interface_override.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/access_interface_override.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand Down Expand Up @@ -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 ####
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand Down
8 changes: 4 additions & 4 deletions gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions gen/templates/provider.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion gen/testvars/infraHPathS.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

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

4 changes: 2 additions & 2 deletions internal/provider/resource_aci_access_interface_override.go

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

22 changes: 11 additions & 11 deletions internal/provider/resource_aci_access_interface_override_test.go

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

0 comments on commit 176a6cb

Please sign in to comment.