in internal/provider/bitbucketserver_connection_resource.go [112:162]
func (r *bitbucketServerConnectionResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
// Retrieve values from plan
var plan bitbucketServerConnectionResourceModel
diags := req.Plan.Get(ctx, &plan)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
now := time.Now().Format(time.RFC850)
// Generate API request body from plan
var bitbucketServerConnectionCreate = client.BitbucketServerConnection{
CreatedAt: now,
Endpoint: plan.Endpoint.ValueString(),
Name: plan.Name.ValueString(),
Password: plan.Password.ValueString(),
Proxy: plan.Proxy.ValueString(),
RateLimitPerHour: int(plan.RateLimitPerHour.ValueInt64()),
UpdatedAt: now,
Username: plan.Username.ValueString(),
}
// Create new bitbucketserverconnection
bitbucketServerConnection, err := r.client.CreateBitbucketServerConnection(bitbucketServerConnectionCreate)
if err != nil {
resp.Diagnostics.AddError(
"Error creating bitbucketServerConnection",
"Could not create bitbucketServerConnection, unexpected error: "+err.Error(),
)
return
}
// Map response body to schema and populate Computed attribute values
plan.ID = types.StringValue(strconv.Itoa(bitbucketServerConnection.ID))
plan.LastUpdated = types.StringValue(now)
plan.CreatedAt = types.StringValue(bitbucketServerConnection.CreatedAt)
plan.Endpoint = types.StringValue(bitbucketServerConnection.Endpoint)
plan.Name = types.StringValue(bitbucketServerConnection.Name)
plan.Proxy = types.StringValue(bitbucketServerConnection.Proxy)
plan.RateLimitPerHour = types.Int64Value(int64(bitbucketServerConnection.RateLimitPerHour))
plan.UpdatedAt = types.StringValue(bitbucketServerConnection.UpdatedAt)
plan.Username = types.StringValue(bitbucketServerConnection.Username)
// Set state to fully populated data
diags = resp.State.Set(ctx, plan)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
}