Skip to content

Commit

Permalink
[ignore] Add conditions to not render resources and datasources for R…
Browse files Browse the repository at this point in the history
…s classes set to one max class allowed.
  • Loading branch information
gmicol committed Aug 15, 2024
1 parent 96bb856 commit 91f4e04
Show file tree
Hide file tree
Showing 17 changed files with 20 additions and 1,430 deletions.
61 changes: 0 additions & 61 deletions docs/data-sources/relation_to_host_path.md

This file was deleted.

120 changes: 0 additions & 120 deletions docs/resources/relation_to_host_path.md

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions examples/data-sources/aci_relation_to_host_path/provider.tf

This file was deleted.

14 changes: 0 additions & 14 deletions examples/resources/aci_relation_to_host_path/provider.tf

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions examples/resources/aci_relation_to_host_path/resource.tf

This file was deleted.

4 changes: 3 additions & 1 deletion gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +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
if len(model.IdentifiedBy) > 0 || model.Include {
// 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) {

// 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 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 or .IdentifiedBy .Include}}
{{- if and (or .IdentifiedBy .Include) (not (and .MaxOneClassAllowed (hasPrefix .RnFormat "rs")))}}
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 or .IdentifiedBy .Include}}
{{- if and (or .IdentifiedBy .Include) (not (and .MaxOneClassAllowed (hasPrefix .RnFormat "rs")))}}
New{{.ResourceClassName}}DataSource,
{{- end }}
{{- end }}
Expand Down
13 changes: 10 additions & 3 deletions gen/templates/resource.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ func get{{$.ResourceClassName}}{{ .ResourceClassName }}ChildPayloads(ctx context

childPayloads := []map[string]interface{}{}
if !data.{{ .ResourceClassName }}.IsUnknown() {
{{- if .IdentifiedBy}}
{{- if and .IdentifiedBy (not (and .MaxOneClassAllowed (hasPrefix .RnFormat "rs")))}}
{{ .PkgName }}Identifiers := []{{ .ResourceClassName }}Identifier{}
{{- end}}
for _, {{ .PkgName }} := range {{ .PkgName }}Plan {
Expand All @@ -1485,7 +1485,7 @@ func get{{$.ResourceClassName}}{{ .ResourceClassName }}ChildPayloads(ctx context
} {{- end}}
{{- end}}
childPayloads = append(childPayloads, map[string]interface{}{"{{ .PkgName }}": childMap})
{{- if .IdentifiedBy}}
{{- if and .IdentifiedBy (not (and .MaxOneClassAllowed (hasPrefix .RnFormat "rs")))}}
{{ .PkgName }}Identifier := {{ .ResourceClassName }}Identifier{}
{{- range .Properties}}
{{- if .IsNaming}}
Expand All @@ -1495,7 +1495,7 @@ func get{{$.ResourceClassName}}{{ .ResourceClassName }}ChildPayloads(ctx context
{{ .PkgName }}Identifiers = append({{ .PkgName }}Identifiers, {{ .PkgName }}Identifier)
{{- end}}
}
{{- if .IdentifiedBy}}
{{- if and .IdentifiedBy (not (and .MaxOneClassAllowed (hasPrefix .RnFormat "rs")))}}
for _, {{ .PkgName }} := range {{ .PkgName }}State {
delete := true
for _, {{ .PkgName }}Identifier := range {{ .PkgName }}Identifiers { {{$i := 1}}{{$length := len .IdentifiedBy}}
Expand Down Expand Up @@ -1525,6 +1525,13 @@ func get{{$.ResourceClassName}}{{ .ResourceClassName }}ChildPayloads(ctx context
{{- if .AllowDelete}}
childMap := map[string]map[string]interface{}{"attributes": {}}
childMap["attributes"]["status"] = "deleted"
{{- if .IdentifiedBy}}
{{- range .Properties}}
{{- if .IsNaming }}
childMap["attributes"]["{{.PropertyName}}"] = {{ .PkgName }}State[0].{{- if eq .Name "Id"}}{{.ResourceClassName}}{{ .Name }}{{- else}}{{.Name}}{{- end}}.ValueString()
{{- end}}
{{- end}}
{{- end}}
childPayloads = append(childPayloads, map[string]interface{}{"{{ .PkgName }}": childMap})
{{- else}}
diags.AddError(
Expand Down
52 changes: 0 additions & 52 deletions gen/testvars/infraRsHPathAtt.yaml

This file was deleted.

Loading

0 comments on commit 91f4e04

Please sign in to comment.