func()

in internal/provider/diskpool_resource.go [299:410]


func (r *diskpoolResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
	// Retrieve values from state
	var state diskPoolResourceModel
	diags := req.Plan.Get(ctx, &state)
	resp.Diagnostics.Append(diags...)
	if resp.Diagnostics.HasError() {
		return
	}

	reqDiskpool := backupdr.DiskPoolRest{
		Name:     state.Name.ValueString(),
		Pooltype: state.Pooltype.ValueString(),
		Cluster:  &backupdr.ClusterRest{Clusterid: state.ApplianceClusterID.ValueString()},
	}

	for _, prop := range state.Properties {
		reqDiskpool.Properties = append(reqDiskpool.Properties, backupdr.KeyValueRest{
			Key:   prop.Key.ValueString(),
			Value: prop.Value.ValueString(),
		})
	}

	// Generate API request body from state
	reqBody := backupdr.DiskPoolApiCreateDiskPoolOpts{
		Body: optional.NewInterface(reqDiskpool),
	}

	// Create new diskpool
	respObject, res, err := r.client.DiskPoolApi.CreateDiskPool(r.authCtx, &reqBody)
	if err != nil {
		resp.Diagnostics.AddError(
			"Error creating Diskpool",
			"Could not create Diskpool, unexpected error: "+err.Error(),
		)
		return
	}

	if res.StatusCode != 200 {
		resp.Diagnostics.AddError(
			"Unable to Create BackupDR DiskPool",
			res.Status,
		)
	}

	// Map response body to schema and populate Computed attribute values
	state.ID = types.StringValue(respObject.Id)
	state.Href = types.StringValue(respObject.Href)
	state.Syncdate = types.Int64Value(respObject.Syncdate)
	state.Stale = types.BoolValue(respObject.Stale)
	state.Usedefaultsa = types.BoolValue(respObject.Usedefaultsa)
	state.Immutable = types.BoolValue(respObject.Immutable)
	state.Metadataonly = types.BoolValue(respObject.Metadataonly)
	state.State = types.StringValue(respObject.State)
	state.Srcid = types.StringValue(respObject.Srcid)
	state.Status = types.StringValue(respObject.Status)
	state.Mdiskgrp = types.StringValue(respObject.Mdiskgrp)
	state.Pooltypedisplayname = types.StringValue(respObject.Pooltypedisplayname)
	state.Srcid = types.StringValue(respObject.Srcid)
	state.Warnpct = types.Int64Value(int64(respObject.Warnpct))
	state.Modifydate = types.Int64Value(respObject.Modifydate)
	state.Safepct = types.Int64Value(int64(respObject.Safepct))
	state.Udsuid = types.Int64Value(int64(respObject.Udsuid))
	state.FreeMb = types.Int64Value(respObject.FreeMb)
	state.UsageMb = types.Int64Value(respObject.UsageMb)
	state.CapacityMb = types.Int64Value(respObject.CapacityMb)
	state.Pct = types.Float64Value(respObject.Pct)

	state.ApplianceClusterID = types.StringValue(respObject.Cluster.Clusterid)
	// Set state to fully populated data
	// state.Cluster = &ClusterRest{
	// 	ID:              types.StringValue(respObject.Cluster.Id),
	// 	Href:            types.StringValue(respObject.Cluster.Href),
	// 	Serviceaccount:  types.StringValue(respObject.Cluster.Serviceaccount),
	// 	Zone:            types.StringValue(respObject.Cluster.Zone),
	// 	Region:          types.StringValue(respObject.Cluster.Region),
	// 	Projectid:       types.StringValue(respObject.Cluster.Projectid),
	// 	Version:         types.StringValue(respObject.Cluster.Version),
	// 	Name:            types.StringValue(respObject.Cluster.Name),
	// 	Type:            types.StringValue(respObject.Cluster.Type_),
	// 	Ipaddress:       types.StringValue(respObject.Cluster.Ipaddress),
	// 	Publicip:        types.StringValue(respObject.Cluster.Publicip),
	// 	Secureconnect:   types.BoolValue(respObject.Cluster.Secureconnect),
	// 	PkiBootstrapped: types.BoolValue(respObject.Cluster.PkiBootstrapped),
	// 	Supportstatus:   types.StringValue(respObject.Cluster.Supportstatus),
	// 	Syncdate:        types.Int64Value(respObject.Cluster.Syncdate),
	// 	Stale:           types.BoolValue(respObject.Cluster.Stale),
	// }

	// // state.Cluster.Href = types.StringValue(respObject.Cluster.Href)
	// // state.Cluster.ID = types.StringValue(respObject.Cluster.Id)
	// // state.Cluster.Serviceaccount = types.StringValue(respObject.Cluster.Serviceaccount)
	// // state.Cluster.Zone = types.StringValue(respObject.Cluster.Zone)
	// // state.Cluster.Region = types.StringValue(respObject.Cluster.Region)
	// // state.Cluster.Projectid = types.StringValue(respObject.Cluster.Projectid)
	// // state.Cluster.Version = types.StringValue(respObject.Cluster.Version)
	// // state.Cluster.Name = types.StringValue(respObject.Cluster.Name)
	// // state.Cluster.Type = types.StringValue(respObject.Cluster.Type_)
	// // state.Cluster.Ipaddress = types.StringValue(respObject.Cluster.Ipaddress)
	// // state.Cluster.Publicip = types.StringValue(respObject.Cluster.Publicip)
	// // state.Cluster.Secureconnect = types.BoolValue(respObject.Cluster.Secureconnect)
	// // state.Cluster.PkiBootstrapped = types.BoolValue(respObject.Cluster.PkiBootstrapped)
	// // state.Cluster.Supportstatus = types.StringValue(respObject.Cluster.Supportstatus)
	// // state.Cluster.Syncdate = types.Int64Value(respObject.Cluster.Syncdate)
	// // state.Cluster.Stale = types.BoolValue(respObject.Cluster.Stale)

	// Set state to fully populated data
	diags = resp.State.Set(ctx, state)
	resp.Diagnostics.Append(diags...)
	if resp.Diagnostics.HasError() {
		return
	}
}