Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions gen/templates/provider.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ var globalAllowExistingOnCreate bool
var _ provider.Provider = &AciProvider{}
var _ provider.ProviderWithFunctions = &AciProvider{}

// Struct model for identity data handling
type IdentityModel struct {
Id types.String `tfsdk:"id"`
}

// Generic identity schema for each resource
func getIdentitySchema() identityschema.Schema {
return identityschema.Schema{
Attributes: map[string]identityschema.Attribute{
"id": identityschema.StringAttribute{
RequiredForImport: true,
},
},
}
}

// AciProvider defines the provider implementation.
type AciProvider struct {
version string
Expand Down
21 changes: 18 additions & 3 deletions gen/templates/resource.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ import (

// Ensure provider defined types fully satisfy framework interfaces.
var _ resource.Resource = &{{.ResourceClassName}}Resource{}
var _ resource.ResourceWithIdentity = &{{.ResourceClassName}}Resource{}
var _ resource.ResourceWithImportState = &{{.ResourceClassName}}Resource{}

func New{{.ResourceClassName}}Resource() resource.Resource {
return &{{.ResourceClassName}}Resource{}
}

func (r {{.ResourceClassName}}Resource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) {
resp.IdentitySchema = getIdentitySchema()
}

// {{.ResourceClassName}}Resource defines the resource implementation.
type {{.ResourceClassName}}Resource struct {
client *client.Client
Expand Down Expand Up @@ -1846,6 +1851,7 @@ func (r *{{.ResourceClassName}}Resource) Create(ctx context.Context, req resourc

// Save data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...)
tflog.Debug(ctx, fmt.Sprintf("End create of resource aci_{{.ResourceName}} with id '%s'", data.Id.ValueString()))
}

Expand All @@ -1870,6 +1876,7 @@ func (r *{{.ResourceClassName}}Resource) Read(ctx context.Context, req resource.
resp.Diagnostics.Append(resp.State.Set(ctx, &emptyData)...)
} else {
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...)
}

tflog.Debug(ctx, fmt.Sprintf("End read of resource aci_{{.ResourceName}} with id '%s'", data.Id.ValueString()))
Expand Down Expand Up @@ -1992,6 +1999,7 @@ tflog.Debug(ctx, fmt.Sprintf("Update of resource aci_{{ .ResourceName }} with id

// Save updated data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: data.Id})...)
tflog.Debug(ctx, fmt.Sprintf("End update of resource aci_{{.ResourceName}} with id '%s'", data.Id.ValueString()))
}

Expand Down Expand Up @@ -2034,10 +2042,11 @@ func (r *{{.ResourceClassName}}Resource) Delete(ctx context.Context, req resourc

func (r *{{.ResourceClassName}}Resource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
tflog.Debug(ctx, "Start import state of resource: aci_{{.ResourceName}}")
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
resource.ImportStatePassthroughWithIdentity(ctx, path.Root("id"), path.Root("id"), req, resp)

var stateData *{{.ResourceClassName}}ResourceModel
resp.Diagnostics.Append(resp.State.Get(ctx, &stateData)...)
resp.Diagnostics.Append(resp.Identity.Set(ctx, IdentityModel{Id: stateData.Id})...)
tflog.Debug(ctx, fmt.Sprintf("Import state of resource aci_{{.ResourceName}} with id '%s'", stateData.Id.ValueString()))

tflog.Debug(ctx, "End import of state resource: aci_{{.ResourceName}}")
Expand All @@ -2050,11 +2059,17 @@ func getAndSet{{.ResourceClassName}}Attributes(ctx context.Context, diags *diag.
requestData := DoRestRequest(ctx, diags, client, fmt.Sprintf("api/mo/%s.json", data.Id.ValueString()), "GET", nil)
{{- end}}

readData := getEmpty{{.ResourceClassName}}ResourceModel()

if diags.HasError() {
return
}

set{{.ResourceClassName}}Attributes(ctx, diags, data, requestData)
}

func set{{.ResourceClassName}}Attributes(ctx context.Context, diags *diag.Diagnostics, data *{{.ResourceClassName}}ResourceModel, requestData *container.Container) {

readData := getEmpty{{.ResourceClassName}}ResourceModel()

if requestData.Search("imdata").Search("{{.PkgName}}").Data() != nil {
classReadInfo := requestData.Search("imdata").Search("{{.PkgName}}").Data().([]interface{})
if len(classReadInfo) == 1 {
Expand Down
17 changes: 17 additions & 0 deletions internal/provider/provider.go

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

21 changes: 18 additions & 3 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.

21 changes: 18 additions & 3 deletions internal/provider/resource_aci_access_port_block.go

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

21 changes: 18 additions & 3 deletions internal/provider/resource_aci_access_port_selector.go

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

Loading
Loading