feat: add database_id attribute to resource model and update related functions
This commit is contained in:
parent
502b2f5e0a
commit
91913c3446
6 changed files with 90 additions and 65 deletions
|
|
@ -26,6 +26,7 @@ type DataSourceModel struct {
|
|||
ProjectId types.String `tfsdk:"project_id"`
|
||||
InstanceId types.String `tfsdk:"instance_id"`
|
||||
Region types.String `tfsdk:"region"`
|
||||
DatabaseID types.Int64 `tfsdk:"database_id"`
|
||||
TerraformID types.String `tfsdk:"tf_id"`
|
||||
}
|
||||
|
||||
|
|
@ -93,11 +94,17 @@ func (r *databaseDataSource) Schema(ctx context.Context, _ datasource.SchemaRequ
|
|||
MarkdownDescription: "Region of the PostgresFlex instance.",
|
||||
Optional: true,
|
||||
}
|
||||
s.Attributes["tf_id"] = schema.StringAttribute{
|
||||
Description: "Terraform's internal resource ID. It is structured as \\\"`project_id`,`region`,`instance_id`,`id`\\\".\",",
|
||||
s.Attributes["database_id"] = schema.Int64Attribute{
|
||||
Description: "The ID of the database.",
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
}
|
||||
s.Attributes["tf_id"] = schema.StringAttribute{
|
||||
Description: "Terraform's internal resource ID. It is structured as \\\"`project_id`,`region`,`instance_id`," +
|
||||
"`database_id`\\\".\",",
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
}
|
||||
|
||||
resp.Schema = s
|
||||
}
|
||||
|
|
@ -164,7 +171,7 @@ func (r *databaseDataSource) getDatabaseByNameOrID(
|
|||
projectId, region, instanceId string,
|
||||
diags *diag.Diagnostics,
|
||||
) (*postgresflexalpha.ListDatabase, error) {
|
||||
isIdSet := !model.Id.IsNull() && !model.Id.IsUnknown()
|
||||
isIdSet := !model.DatabaseID.IsNull() && !model.DatabaseID.IsUnknown()
|
||||
isNameSet := !model.Name.IsNull() && !model.Name.IsUnknown()
|
||||
|
||||
if (isIdSet && isNameSet) || (!isIdSet && !isNameSet) {
|
||||
|
|
@ -176,8 +183,8 @@ func (r *databaseDataSource) getDatabaseByNameOrID(
|
|||
}
|
||||
|
||||
if isIdSet {
|
||||
databaseId := model.Id.ValueInt64()
|
||||
ctx = tflog.SetField(ctx, "id", databaseId)
|
||||
databaseId := model.DatabaseID.ValueInt64()
|
||||
ctx = tflog.SetField(ctx, "database_id", databaseId)
|
||||
return getDatabaseById(ctx, r.client, projectId, region, instanceId, databaseId)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue