Skip to content

Commit

Permalink
[ignore] Made changes to resource template by providing indentations
Browse files Browse the repository at this point in the history
  • Loading branch information
shrsr committed Apr 23, 2024
1 parent 57faee2 commit cfdeeaa
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 75 deletions.
1 change: 0 additions & 1 deletion docs/data-sources/annotation.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ data "aci_annotation" "example_application_epg" {
- [aci_route_control_profile](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/route_control_profile) ([rtctrlProfile](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/rtctrlProfile/overview))
- [aci_contract_interface](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/contract_interface) ([vzCPIf](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/vzCPIf/overview))
- [aci_out_of_band_contract](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/out_of_band_contract) ([vzOOBBrCP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/vzOOBBrCP/overview))
- Too many classes to display, see model documentation for all possible classes of [tagAnnotation](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagAnnotation/overview).
* `key` (key) - (string) The key used to uniquely identify this configuration object.

### Read-Only ###
Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/certificate_authority.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ data "aci_certificate_authority" "example_tenant" {
### Optional ###

* `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources:
- [aci_tenant](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/fvTenant) ([fvTenant](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvTenant/overview))
- [aci_tenant](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/fvTenant) ([fvTenant](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvTenant/overview))

### Read-Only ###

Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/key_ring.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ data "aci_key_ring" "example_tenant" {
### Optional ###

* `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources:
- [aci_tenant](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/fvTenant) ([fvTenant](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvTenant/overview))
- [aci_tenant](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/fvTenant) ([fvTenant](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvTenant/overview))

### Read-Only ###

Expand Down
1 change: 0 additions & 1 deletion docs/data-sources/tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ data "aci_tag" "example_application_epg" {
- [aci_route_control_profile](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/route_control_profile) ([rtctrlProfile](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/rtctrlProfile/overview))
- [aci_contract_interface](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/contract_interface) ([vzCPIf](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/vzCPIf/overview))
- [aci_out_of_band_contract](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/out_of_band_contract) ([vzOOBBrCP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/vzOOBBrCP/overview))
- Too many classes to display, see model documentation for all possible classes of [tagTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagTag/overview).
* `key` (key) - (string) The key used to uniquely identify this configuration object.

### Read-Only ###
Expand Down
1 change: 0 additions & 1 deletion docs/resources/annotation.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ All examples for the Annotation resource can be found in the [examples](https://
- [aci_route_control_profile](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/route_control_profile) ([rtctrlProfile](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/rtctrlProfile/overview))
- [aci_contract_interface](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/contract_interface) ([vzCPIf](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/vzCPIf/overview))
- [aci_out_of_band_contract](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/out_of_band_contract) ([vzOOBBrCP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/vzOOBBrCP/overview))
- Too many classes to display, see model documentation for all possible classes of [tagAnnotation](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagAnnotation/overview).
* `key` (key) - (string) The key used to uniquely identify this configuration object.
* `value` (value) - (string) The value of the property.

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/certificate_authority.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ All examples for the Certificate Authority resource can be found in the [example
### Optional ###

* `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources:
- [aci_tenant](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/fvTenant) ([fvTenant](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvTenant/overview))
- [aci_tenant](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/fvTenant) ([fvTenant](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvTenant/overview))
* `annotation` (annotation) - (string) The annotation of the Certificate Authority object.
- Default: `orchestrator:terraform`
* `description` (descr) - (string) The description of the Certificate Authority object.
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/key_ring.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ All examples for the Key Ring resource can be found in the [examples](https://gi
### Optional ###

* `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources:
- [aci_tenant](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/fvTenant) ([fvTenant](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvTenant/overview))
- [aci_tenant](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/fvTenant) ([fvTenant](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/fvTenant/overview))
* `admin_state` (adminState) - (string) The current administrative state of the certificate request process.
- Default: `started`
- Valid Values: `completed`, `created`, `reqCreated`, `started`, `tpSet`.
Expand Down
1 change: 0 additions & 1 deletion docs/resources/tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ All examples for the Tag resource can be found in the [examples](https://github.
- [aci_route_control_profile](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/route_control_profile) ([rtctrlProfile](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/rtctrlProfile/overview))
- [aci_contract_interface](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/contract_interface) ([vzCPIf](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/vzCPIf/overview))
- [aci_out_of_band_contract](https://registry.terraform.io/providers/CiscoDevNet/aci/latest/docs/resources/out_of_band_contract) ([vzOOBBrCP](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/vzOOBBrCP/overview))
- Too many classes to display, see model documentation for all possible classes of [tagTag](https://pubhub.devnetcloud.com/media/model-doc-latest/docs/app/index.html#/objects/tagTag/overview).
* `key` (key) - (string) The key used to uniquely identify this configuration object.
* `value` (value) - (string) The value of the property.

Expand Down
5 changes: 2 additions & 3 deletions gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
"go/format"
"io"
"log"
"math"
"net/http"
"os"
"path"
Expand Down Expand Up @@ -1765,10 +1764,10 @@ func setDocumentationData(m *Model, definitions Definitions) {
}
}

if len(resourcesNotFound) != 0 {
if len(resourcesNotFound) != 0 && len(resourcesFound) < docsParentDnAmount {
if len(resourcesNotFound) > docsParentDnAmount-len(resourcesFound) {
// TODO catch default classes and add to documentation
resourcesNotFound = resourcesNotFound[0:int(math.Abs(float64((docsParentDnAmount - len(resourcesFound)))))]
resourcesNotFound = resourcesNotFound[0:(docsParentDnAmount - len(resourcesFound))]
m.DocumentationParentDns = append(m.DocumentationParentDns, fmt.Sprintf("Too many classes to display, see model documentation for all possible classes of %s.", GetDevnetDocForClass(m.PkgName)))
} else {
var resourceDetails string
Expand Down
2 changes: 1 addition & 1 deletion gen/templates/datasource.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Data source for {{.ResourceNameAsDescription}}
* `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources:
{{- if .MultiParentFormats }}
{{- range .DocumentationParentDns }}
- {{ . }}
- {{ . }}
{{- end }}
{{- end }}
{{ end }}
Expand Down
123 changes: 61 additions & 62 deletions gen/templates/resource.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -284,74 +284,74 @@ func (r *{{.ResourceClassName}}Resource) Configure(ctx context.Context, req reso
func (r *{{.ResourceClassName}}Resource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
tflog.Debug(ctx, "Start create of resource: aci_{{.ResourceName}}")

{{- if .HasChild }}
// On create retrieve information on current state prior to making any changes in order to determine child delete operations
var stateData *{{ .ResourceClassName }}ResourceModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &stateData)...)
set{{ .ResourceClassName }}Id(ctx, stateData)
getAndSet{{ .ResourceClassName }}Attributes(ctx, &resp.Diagnostics, r.client, stateData)
{{- end }}
{{- if .HasChild }}
// On create retrieve information on current state prior to making any changes in order to determine child delete operations
var stateData *{{ .ResourceClassName }}ResourceModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &stateData)...)
set{{ .ResourceClassName }}Id(ctx, stateData)
getAndSet{{ .ResourceClassName }}Attributes(ctx, &resp.Diagnostics, r.client, stateData)
{{- end }}

var data *{{ .ResourceClassName }}ResourceModel
var data *{{ .ResourceClassName }}ResourceModel

// Read Terraform plan data into the model
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
// Read Terraform plan data into the model
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)

if resp.Diagnostics.HasError() {
return
}
if resp.Diagnostics.HasError() {
return
}

set{{ .ResourceClassName }}Id(ctx, data)
set{{ .ResourceClassName }}Id(ctx, data)

tflog.Debug(ctx, fmt.Sprintf("Create of resource aci_{{ .ResourceName }} with id '%s'", data.Id.ValueString()))
tflog.Debug(ctx, fmt.Sprintf("Create of resource aci_{{ .ResourceName }} with id '%s'", data.Id.ValueString()))

{{ if .MultiParentFormats }}
{{- if .HasChild }}
{{- range .Children }}
var {{ .PkgName }}Plan, {{ .PkgName }}State []{{ .ResourceClassName }}{{ $.ResourceClassName }}ResourceModel
data.{{ .ResourceClassName }}.ElementsAs(ctx, &{{ .PkgName }}Plan, false)
stateData.{{ .ResourceClassName }}.ElementsAs(ctx, &{{ .PkgName }}State, false)
{{- end }}
jsonPayload := get{{ .ResourceClassName }}CreateJsonPayload(ctx, &resp.Diagnostics, data, stateData{{- range .Children }}, {{ .PkgName }}Plan, {{ .PkgName }}State{{- end }})
{{- else }}
jsonPayload := get{{ .ResourceClassName }}CreateJsonPayload(ctx, &resp.Diagnostics, data, stateData)
{{- end }}
{{ if .MultiParentFormats }}
{{- if .HasChild }}
{{- range .Children }}
var {{ .PkgName }}Plan, {{ .PkgName }}State []{{ .ResourceClassName }}{{ $.ResourceClassName }}ResourceModel
data.{{ .ResourceClassName }}.ElementsAs(ctx, &{{ .PkgName }}Plan, false)
stateData.{{ .ResourceClassName }}.ElementsAs(ctx, &{{ .PkgName }}State, false)
{{- end }}
jsonPayload := get{{ .ResourceClassName }}CreateJsonPayload(ctx, &resp.Diagnostics, data, stateData{{- range .Children }}, {{ .PkgName }}Plan, {{ .PkgName }}State{{- end }})
{{- else }}
jsonPayload := get{{ .ResourceClassName }}CreateJsonPayload(ctx, &resp.Diagnostics, data, stateData)
{{- end }}

if resp.Diagnostics.HasError() {
return
}
if resp.Diagnostics.HasError() {
return
}

wrapperClassMap := map[string]string{ {{- range $key, $value := .MultiParentFormats }} "{{ $value.RnPrepend }}": "{{ $value.WrapperClass }}", {{- end }} }
for rnPrepend, wrapperClass := range wrapperClassMap {
if strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass != "" {
DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s%s.json", strings.Split(data.Id.ValueString(), rnPrepend)[0], rnPrepend), "POST", jsonPayload)
} else if strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass == "" {
DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload)
}
}
{{- else }}
{{- if .HasChild }}
{{- range .Children }}
var {{ .PkgName }}Plan, {{ .PkgName }}State []{{ .ResourceClassName }}{{ $.ResourceClassName }}ResourceModel
data.{{ .ResourceClassName }}.ElementsAs(ctx, &{{ .PkgName }}Plan, false)
stateData.{{ .ResourceClassName }}.ElementsAs(ctx, &{{ .PkgName }}State, false)
{{- end }}
jsonPayload := get{{ .ResourceClassName }}CreateJsonPayload(ctx, &resp.Diagnostics, data{{- range .Children }}, {{ .PkgName }}Plan, {{ .PkgName }}State{{- end }})
{{- else }}
jsonPayload := get{{ .ResourceClassName }}CreateJsonPayload(ctx, &resp.Diagnostics, data)
{{- end }}
wrapperClassMap := map[string]string{ {{- range $key, $value := .MultiParentFormats }} "{{ $value.RnPrepend }}": "{{ $value.WrapperClass }}", {{- end }} }
for rnPrepend, wrapperClass := range wrapperClassMap {
if strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass != "" {
DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s%s.json", strings.Split(data.Id.ValueString(), rnPrepend)[0], rnPrepend), "POST", jsonPayload)
} else if strings.Contains(data.Id.ValueString(), rnPrepend) && wrapperClass == "" {
DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload)
}
}
{{- else }}
{{- if .HasChild }}
{{- range .Children }}
var {{ .PkgName }}Plan, {{ .PkgName }}State []{{ .ResourceClassName }}{{ $.ResourceClassName }}ResourceModel
data.{{ .ResourceClassName }}.ElementsAs(ctx, &{{ .PkgName }}Plan, false)
stateData.{{ .ResourceClassName }}.ElementsAs(ctx, &{{ .PkgName }}State, false)
{{- end }}
jsonPayload := get{{ .ResourceClassName }}CreateJsonPayload(ctx, &resp.Diagnostics, data{{- range .Children }}, {{ .PkgName }}Plan, {{ .PkgName }}State{{- end }})
{{- else }}
jsonPayload := get{{ .ResourceClassName }}CreateJsonPayload(ctx, &resp.Diagnostics, data)
{{- end }}

if resp.Diagnostics.HasError() {
return
}
if resp.Diagnostics.HasError() {
return
}

DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload)
if resp.Diagnostics.HasError() {
return
}
{{- end }}
DoRestRequest(ctx, &resp.Diagnostics, r.client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "POST", jsonPayload)
if resp.Diagnostics.HasError() {
return
}
{{- end }}

getAndSet{{.ResourceClassName}}Attributes(ctx, &resp.Diagnostics, r.client, data)
getAndSet{{.ResourceClassName}}Attributes(ctx, &resp.Diagnostics, r.client, data)

// Save data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
Expand Down Expand Up @@ -512,7 +512,7 @@ func (r *{{.ResourceClassName}}Resource) ImportState(ctx context.Context, req re

func getAndSet{{.ResourceClassName}}Attributes(ctx context.Context, diags *diag.Diagnostics, client *client.Client, data *{{.ResourceClassName}}ResourceModel) {
{{- if .HasChild}}
requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "{{- .PkgName}},{{- listToString .ChildClasses}}"), "GET", nil)
requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json?rsp-subtree=children&rsp-subtree-class=%s", data.Id.ValueString(), "{{- .PkgName}},{{- listToString .ChildClasses}}"), "GET", nil)
{{- else}}
requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "GET", nil)
{{- end}}
Expand Down Expand Up @@ -565,10 +565,9 @@ func getAndSet{{.ResourceClassName}}Attributes(ctx context.Context, diags *diag.
{{- end}}
}


{{- range .Properties}}
if data.{{.Name}}.IsUnknown() {
data.{{.Name}} = types.StringNull()
data.{{.Name}} = types.StringNull()
}
{{- end}}

Expand Down Expand Up @@ -847,13 +846,13 @@ func get{{ .ResourceClassName }}CreateJsonPayload(ctx context.Context, diags *di

{{- if .HasChild }}
childPayloads := []map[string]interface{}{}
{{- range .Children }}
{{- range .Children }}
{{ .ResourceClassName }}childPayloads := get{{ $.ResourceClassName }}{{ .ResourceClassName }}ChildPayloads(ctx, diags, data, {{ .PkgName }}Plan, {{ .PkgName }}State)
if {{ .ResourceClassName }}childPayloads == nil {
return nil
}
childPayloads = append(childPayloads, {{ .ResourceClassName }}childPayloads...)
{{- end }}
{{- end }}
payloadMap["children"] = childPayloads
{{- end }}

Expand Down
2 changes: 1 addition & 1 deletion gen/templates/resource.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ All examples for the {{.ResourceNameAsDescription}} resource can be found in the
* `parent_dn` - (string) The distinguished name (DN) of the parent object, possible resources:
{{- if .MultiParentFormats }}
{{- range .DocumentationParentDns}}
- {{ . }}
- {{ . }}
{{- end}}
{{- end}}
{{- end -}}
Expand Down

0 comments on commit cfdeeaa

Please sign in to comment.