feat: enhance database resource model with additional attributes and refactor data source schema
This commit is contained in:
parent
c4891b770d
commit
1284bcc8a3
6 changed files with 66 additions and 80 deletions
|
|
@ -42,14 +42,7 @@ var (
|
|||
)
|
||||
|
||||
// ResourceModel describes the resource data model.
|
||||
type ResourceModel struct {
|
||||
postgresflexalpha2.DatabaseModel
|
||||
ProjectID types.String `tfsdk:"project_id"`
|
||||
Region types.String `tfsdk:"region"`
|
||||
InstanceID types.String `tfsdk:"instance_id"`
|
||||
DatabaseID types.Int64 `tfsdk:"database_id"`
|
||||
TerraformID types.String `tfsdk:"id"`
|
||||
}
|
||||
type ResourceModel = postgresflexalpha2.DatabaseModel
|
||||
|
||||
// DatabaseResourceIdentityModel describes the resource's identity attributes.
|
||||
type DatabaseResourceIdentityModel struct {
|
||||
|
|
@ -289,9 +282,21 @@ func (r *databaseResource) Create(
|
|||
)
|
||||
return
|
||||
}
|
||||
|
||||
// Write identity attributes to state
|
||||
identityData.ProjectID = types.StringValue(projectId)
|
||||
identityData.Region = types.StringValue(region)
|
||||
identityData.InstanceID = types.StringValue(instanceId)
|
||||
identityData.DatabaseID = types.Int64Value(databaseId)
|
||||
|
||||
resp.Diagnostics.Append(resp.Identity.Set(ctx, &identityData)...)
|
||||
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
// Set state to fully populated data
|
||||
diags = resp.State.Set(ctx, model)
|
||||
resp.Diagnostics.Append(diags...)
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, model)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
|
@ -589,8 +594,8 @@ func (r *databaseResource) extractIdentityData(
|
|||
model ResourceModel,
|
||||
identity DatabaseResourceIdentityModel,
|
||||
) (projectId, region, instanceId string, databaseId int64, err error) {
|
||||
if !model.DatabaseID.IsNull() && !model.DatabaseID.IsUnknown() {
|
||||
databaseId = model.DatabaseID.ValueInt64()
|
||||
if !model.DatabaseId.IsNull() && !model.DatabaseId.IsUnknown() {
|
||||
databaseId = model.DatabaseId.ValueInt64()
|
||||
} else {
|
||||
if identity.DatabaseID.IsNull() || identity.DatabaseID.IsUnknown() {
|
||||
return "", "", "", 0, fmt.Errorf("database_id not found in config")
|
||||
|
|
@ -598,8 +603,8 @@ func (r *databaseResource) extractIdentityData(
|
|||
databaseId = identity.DatabaseID.ValueInt64()
|
||||
}
|
||||
|
||||
if !model.ProjectID.IsNull() && !model.ProjectID.IsUnknown() {
|
||||
projectId = model.ProjectID.ValueString()
|
||||
if !model.ProjectId.IsNull() && !model.ProjectId.IsUnknown() {
|
||||
projectId = model.ProjectId.ValueString()
|
||||
} else {
|
||||
if identity.ProjectID.IsNull() || identity.ProjectID.IsUnknown() {
|
||||
return "", "", "", 0, fmt.Errorf("project_id not found in config")
|
||||
|
|
@ -616,8 +621,8 @@ func (r *databaseResource) extractIdentityData(
|
|||
region = r.providerData.GetRegionWithOverride(identity.Region)
|
||||
}
|
||||
|
||||
if !model.InstanceID.IsNull() && !model.InstanceID.IsUnknown() {
|
||||
instanceId = model.InstanceID.ValueString()
|
||||
if !model.InstanceId.IsNull() && !model.InstanceId.IsUnknown() {
|
||||
instanceId = model.InstanceId.ValueString()
|
||||
} else {
|
||||
if identity.InstanceID.IsNull() || identity.InstanceID.IsUnknown() {
|
||||
return "", "", "", 0, fmt.Errorf("instance_id not found in config")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue