Skip to content

Commit

Permalink
[ignore] Changed go template format
Browse files Browse the repository at this point in the history
  • Loading branch information
shrsr committed Mar 28, 2024
1 parent 55faada commit c6dca43
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 66 deletions.
132 changes: 67 additions & 65 deletions gen/templates/resource.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,6 @@
// In order to regenerate this file execute `go generate` from the repository root.
// More details can be found in the [README](https://github.com/CiscoDevNet/terraform-provider-aci/blob/master/README.md).

{{- define "child_attributes" }}
"{{- .ResourceName}}": schema.SetNestedAttribute{
MarkdownDescription: `{{.Comment}}`,
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Set{
setplanmodifier.UseStateForUnknown(),
},
{{- if not .IdentifiedBy}}
Validators: []validator.Set{
setvalidator.SizeAtMost(1),
},
{{- end}}
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
{{- range .Properties}}
{{- if eq .ValueType "bitmask"}}
"{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}": schema.SetAttribute{
MarkdownDescription: `{{.Comment}}`,
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Set{
setplanmodifier.UseStateForUnknown(),
},
{{- if .ValidValues}}
Validators: []validator.Set{
setvalidator.SizeAtMost({{ len .ValidValues }}),
setvalidator.ValueStringsAre(
stringvalidator.OneOf({{- validatorString .ValidValues}}),
),
},
{{- end}}
ElementType: types.StringType,
},
{{- else}}
"{{overwriteProperty .PkgName .SnakeCaseName $.Definitions}}": schema.StringAttribute{
{{- if or .IsNaming .IsRequired}}
Required: true,
{{- else }}
Optional: true,
Computed: true,
{{- end}}
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
{{- if .ValidValues}}
Validators: []validator.String{
stringvalidator.OneOf({{- validatorString .ValidValues}}),
},
{{- end}}
MarkdownDescription: `{{.Comment}}`,
},
{{- end}}
{{- end}}
{{- range .Children}}
{{- template "child_attributes" . }}
},
},
},
{{- end}}
{{- end}}

package provider

Expand Down Expand Up @@ -249,13 +188,12 @@ func (r *{{.ResourceClassName}}Resource) Schema(ctx context.Context, req resourc
{{- end}}
{{- range .Children}}
{{- template "child_attributes" . }}

},
},
},
},
},

{{- end}}
},
},
}
tflog.Debug(ctx, "End schema of resource: aci_{{.ResourceName}}")
}
Expand Down Expand Up @@ -773,3 +711,67 @@ func get{{.ResourceClassName}}CreateJsonPayload(ctx context.Context, diags *diag
}
return jsonPayload
}

{{- define "child_attributes" }}
"{{ .ResourceName }}": schema.SetNestedAttribute{
MarkdownDescription: `{{ .Comment }}`,
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Set{
setplanmodifier.UseStateForUnknown(),
},
{{- if not .IdentifiedBy }}
Validators: []validator.Set{
setvalidator.SizeAtMost(1),
},
{{- end }}
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
{{- range .Properties }}
{{- if eq .ValueType "bitmask" }}
"{{ overwriteProperty .PkgName .SnakeCaseName $.Definitions }}": schema.SetAttribute{
MarkdownDescription: `{{ .Comment }}`,
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Set{
setplanmodifier.UseStateForUnknown(),
},
{{- if .ValidValues }}
Validators: []validator.Set{
setvalidator.SizeAtMost({{ len .ValidValues }}),
setvalidator.ValueStringsAre(
stringvalidator.OneOf({{ validatorString .ValidValues }}),
),
},
{{- end }}
ElementType: types.StringType,
},
{{- else }}
"{{ overwriteProperty .PkgName .SnakeCaseName $.Definitions }}": schema.StringAttribute{
{{- if or .IsNaming .IsRequired }}
Required: true,
{{- else }}
Optional: true,
Computed: true,
{{- end }}
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
{{- if .ValidValues }}
Validators: []validator.String{
stringvalidator.OneOf({{ validatorString .ValidValues }}),
},
{{- end }}
MarkdownDescription: `{{ .Comment }}`,
},
{{- end }}
{{- end }}
},
{{- range .Children }}
"{{ .ResourceName }}": {
{{- template "child_attributes" . }}
},
{{- end }}
},
},
{{- end }}

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

0 comments on commit c6dca43

Please sign in to comment.