func()

in internal/provider/cloudcredential_data_source.go [131:177]


func (d *cloudCredentialDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {

	var state cloudCredentialResourceModel
	// Read Terraform configuration data into the model
	resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)

	cc, res, err := d.client.DefaultApi.GetCredential(d.authCtx, state.ID.ValueString())
	if err != nil {
		resp.Diagnostics.AddError(
			"Unable to Read CloudCredential",
			err.Error(),
		)
		return
	}

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

	// Map response body to model
	state = cloudCredentialResourceModel{
		ID:             types.StringValue(cc.Id),
		Href:           types.StringValue(cc.Href),
		Stale:          types.BoolValue(cc.Stale),
		ClusterID:      types.Int64Value(cc.ClusterId),
		Serviceaccount: types.StringValue(cc.Serviceaccount),
		Projectid:      types.StringValue(cc.Projectid),
		Region:         types.StringValue(cc.Region),
		Name:           types.StringValue(cc.Name),
		Usedefaultsa:   types.BoolValue(cc.Usedefaultsa),
		Immutable:      types.BoolValue(cc.Immutable),
		Cloudtype:      types.StringValue(cc.Cloudtype),
		Domain:         types.StringValue(cc.Domain),
		SrcID:          types.Int64Value(cc.SrcId),
		Endpoint:       types.StringValue(cc.Endpoint),
		Clientid:       types.StringValue(cc.Clientid),
	}

	// Save data into Terraform state
	resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
	if resp.Diagnostics.HasError() {
		return
	}
}