chore: refactorings #60
15 changed files with 8 additions and 25 deletions
|
|
@ -73,7 +73,6 @@ func (r *databaseDataSource) Configure(
|
||||||
|
|
||||||
// Schema defines the schema for the data source.
|
// Schema defines the schema for the data source.
|
||||||
func (r *databaseDataSource) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
func (r *databaseDataSource) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||||
|
|
||||||
s := postgresflexalpha2.DatabaseDataSourceSchema(ctx)
|
s := postgresflexalpha2.DatabaseDataSourceSchema(ctx)
|
||||||
s.Attributes["id"] = schema.StringAttribute{
|
s.Attributes["id"] = schema.StringAttribute{
|
||||||
Description: "Terraform's internal resource ID. It is structured as \\\"`project_id`,`region`,`instance_id`," +
|
Description: "Terraform's internal resource ID. It is structured as \\\"`project_id`,`region`,`instance_id`," +
|
||||||
|
|
|
||||||
|
|
@ -234,7 +234,7 @@ func (r *databaseResource) Create(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
database, err := postgresflexalpha3.GetDatabaseByIdWaitHandler(ctx, r.client, projectId, region, instanceId, databaseId).
|
database, err := postgresflexalpha3.GetDatabaseByIdWaitHandler(ctx, r.client, projectId, instanceId, region, databaseId).
|
||||||
SetTimeout(15 * time.Minute).
|
SetTimeout(15 * time.Minute).
|
||||||
SetSleepBeforeWait(15 * time.Second).
|
SetSleepBeforeWait(15 * time.Second).
|
||||||
WaitWithContext(ctx)
|
WaitWithContext(ctx)
|
||||||
|
|
@ -305,7 +305,7 @@ func (r *databaseResource) Read(
|
||||||
ctx = tflog.SetField(ctx, "region", region)
|
ctx = tflog.SetField(ctx, "region", region)
|
||||||
ctx = tflog.SetField(ctx, "database_id", databaseId)
|
ctx = tflog.SetField(ctx, "database_id", databaseId)
|
||||||
|
|
||||||
databaseResp, err := postgresflexalpha3.GetDatabaseByIdWaitHandler(ctx, r.client, projectId, region, instanceId, databaseId).
|
databaseResp, err := postgresflexalpha3.GetDatabaseByIdWaitHandler(ctx, r.client, projectId, instanceId, region, databaseId).
|
||||||
SetTimeout(15 * time.Minute).
|
SetTimeout(15 * time.Minute).
|
||||||
SetSleepBeforeWait(15 * time.Second).
|
SetSleepBeforeWait(15 * time.Second).
|
||||||
WaitWithContext(ctx)
|
WaitWithContext(ctx)
|
||||||
|
|
@ -437,7 +437,7 @@ func (r *databaseResource) Update(
|
||||||
|
|
||||||
ctx = core.LogResponse(ctx)
|
ctx = core.LogResponse(ctx)
|
||||||
|
|
||||||
databaseResp, err := postgresflexalpha3.GetDatabaseByIdWaitHandler(ctx, r.client, projectId, region, instanceId, databaseId64).
|
databaseResp, err := postgresflexalpha3.GetDatabaseByIdWaitHandler(ctx, r.client, projectId, instanceId, region, databaseId64).
|
||||||
SetTimeout(15 * time.Minute).
|
SetTimeout(15 * time.Minute).
|
||||||
SetSleepBeforeWait(15 * time.Second).
|
SetSleepBeforeWait(15 * time.Second).
|
||||||
WaitWithContext(ctx)
|
WaitWithContext(ctx)
|
||||||
|
|
@ -540,11 +540,9 @@ func (r *databaseResource) ImportState(
|
||||||
req resource.ImportStateRequest,
|
req resource.ImportStateRequest,
|
||||||
resp *resource.ImportStateResponse,
|
resp *resource.ImportStateResponse,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
if req.ID != "" {
|
if req.ID != "" {
|
||||||
|
|
||||||
idParts := strings.Split(req.ID, core.Separator)
|
idParts := strings.Split(req.ID, core.Separator)
|
||||||
|
|
||||||
if len(idParts) != 4 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" || idParts[3] == "" {
|
if len(idParts) != 4 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" || idParts[3] == "" {
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,6 @@ func TestMapDataSourceFields(t *testing.T) {
|
||||||
},
|
},
|
||||||
testRegion,
|
testRegion,
|
||||||
dataSourceModel{
|
dataSourceModel{
|
||||||
|
|
||||||
UserModel: data.UserModel{
|
UserModel: data.UserModel{
|
||||||
Id: types.Int64Value(1),
|
Id: types.Int64Value(1),
|
||||||
UserId: types.Int64Value(1),
|
UserId: types.Int64Value(1),
|
||||||
|
|
|
||||||
|
|
@ -586,11 +586,9 @@ func (r *userResource) ImportState(
|
||||||
req resource.ImportStateRequest,
|
req resource.ImportStateRequest,
|
||||||
resp *resource.ImportStateResponse,
|
resp *resource.ImportStateResponse,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
if req.ID != "" {
|
if req.ID != "" {
|
||||||
|
|
||||||
idParts := strings.Split(req.ID, core.Separator)
|
idParts := strings.Split(req.ID, core.Separator)
|
||||||
|
|
||||||
if len(idParts) != 4 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" || idParts[3] == "" {
|
if len(idParts) != 4 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" || idParts[3] == "" {
|
||||||
|
|
@ -651,7 +649,6 @@ func (r *userResource) extractIdentityData(
|
||||||
model resourceModel,
|
model resourceModel,
|
||||||
identity UserResourceIdentityModel,
|
identity UserResourceIdentityModel,
|
||||||
) (*clientArg, error) {
|
) (*clientArg, error) {
|
||||||
|
|
||||||
var projectId, region, instanceId string
|
var projectId, region, instanceId string
|
||||||
var userId int64
|
var userId int64
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,6 @@ func (d *databaseDataSource) Configure(
|
||||||
|
|
||||||
// Read retrieves the resource's state from the API.
|
// Read retrieves the resource's state from the API.
|
||||||
func (d *databaseDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
func (d *databaseDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||||
|
|
||||||
var model dataSourceModel
|
var model dataSourceModel
|
||||||
diags := req.Config.Get(ctx, &model)
|
diags := req.Config.Get(ctx, &model)
|
||||||
resp.Diagnostics.Append(diags...)
|
resp.Diagnostics.Append(diags...)
|
||||||
|
|
|
||||||
|
|
@ -422,11 +422,9 @@ func (r *databaseResource) ImportState(
|
||||||
req resource.ImportStateRequest,
|
req resource.ImportStateRequest,
|
||||||
resp *resource.ImportStateResponse,
|
resp *resource.ImportStateResponse,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
if req.ID != "" {
|
if req.ID != "" {
|
||||||
|
|
||||||
idParts := strings.Split(req.ID, core.Separator)
|
idParts := strings.Split(req.ID, core.Separator)
|
||||||
|
|
||||||
if len(idParts) != 4 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" || idParts[3] == "" {
|
if len(idParts) != 4 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" || idParts[3] == "" {
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,6 @@ func handleEncryption(
|
||||||
resp.Encryption.KekKeyRingId == nil ||
|
resp.Encryption.KekKeyRingId == nil ||
|
||||||
resp.Encryption.KekKeyVersion == nil ||
|
resp.Encryption.KekKeyVersion == nil ||
|
||||||
resp.Encryption.ServiceAccount == nil {
|
resp.Encryption.ServiceAccount == nil {
|
||||||
|
|
||||||
if encryptionValue.IsNull() || encryptionValue.IsUnknown() {
|
if encryptionValue.IsNull() || encryptionValue.IsUnknown() {
|
||||||
return sqlserverflexResGen.NewEncryptionValueNull()
|
return sqlserverflexResGen.NewEncryptionValueNull()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,6 @@ var modifiersFileByte []byte
|
||||||
|
|
||||||
// Schema defines the schema for the resource.
|
// Schema defines the schema for the resource.
|
||||||
func (r *instanceResource) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
func (r *instanceResource) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||||
|
|
||||||
schema := sqlserverflexalpha2.InstanceResourceSchema(ctx)
|
schema := sqlserverflexalpha2.InstanceResourceSchema(ctx)
|
||||||
|
|
||||||
fields, err := utils.ReadModifiersConfig(modifiersFileByte)
|
fields, err := utils.ReadModifiersConfig(modifiersFileByte)
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,6 @@ func TestMapDataSourceFields(t *testing.T) {
|
||||||
{
|
{
|
||||||
"simple_values",
|
"simple_values",
|
||||||
&sqlserverflexalpha.GetUserResponse{
|
&sqlserverflexalpha.GetUserResponse{
|
||||||
|
|
||||||
Roles: &[]string{
|
Roles: &[]string{
|
||||||
"role_1",
|
"role_1",
|
||||||
"role_2",
|
"role_2",
|
||||||
|
|
|
||||||
|
|
@ -389,11 +389,9 @@ func (r *userResource) ImportState(
|
||||||
req resource.ImportStateRequest,
|
req resource.ImportStateRequest,
|
||||||
resp *resource.ImportStateResponse,
|
resp *resource.ImportStateResponse,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
if req.ID != "" {
|
if req.ID != "" {
|
||||||
|
|
||||||
idParts := strings.Split(req.ID, core.Separator)
|
idParts := strings.Split(req.ID, core.Separator)
|
||||||
|
|
||||||
if len(idParts) != 4 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" || idParts[3] == "" {
|
if len(idParts) != 4 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" || idParts[3] == "" {
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,6 @@ func (r *databaseResource) Metadata(
|
||||||
var modifiersFileByte []byte
|
var modifiersFileByte []byte
|
||||||
|
|
||||||
func (r *databaseResource) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
func (r *databaseResource) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||||
|
|
||||||
s := sqlserverflexbetaResGen.DatabaseResourceSchema(ctx)
|
s := sqlserverflexbetaResGen.DatabaseResourceSchema(ctx)
|
||||||
|
|
||||||
fields, err := utils.ReadModifiersConfig(modifiersFileByte)
|
fields, err := utils.ReadModifiersConfig(modifiersFileByte)
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,6 @@ func handleEncryption(
|
||||||
resp.Encryption.KekKeyRingId == nil ||
|
resp.Encryption.KekKeyRingId == nil ||
|
||||||
resp.Encryption.KekKeyVersion == nil ||
|
resp.Encryption.KekKeyVersion == nil ||
|
||||||
resp.Encryption.ServiceAccount == nil {
|
resp.Encryption.ServiceAccount == nil {
|
||||||
|
|
||||||
if m.Encryption.IsNull() || m.Encryption.IsUnknown() {
|
if m.Encryption.IsNull() || m.Encryption.IsUnknown() {
|
||||||
return sqlserverflexbetaResGen.NewEncryptionValueNull()
|
return sqlserverflexbetaResGen.NewEncryptionValueNull()
|
||||||
}
|
}
|
||||||
|
|
@ -172,7 +171,6 @@ func handleDSEncryption(
|
||||||
resp.Encryption.KekKeyRingId == nil ||
|
resp.Encryption.KekKeyRingId == nil ||
|
||||||
resp.Encryption.KekKeyVersion == nil ||
|
resp.Encryption.KekKeyVersion == nil ||
|
||||||
resp.Encryption.ServiceAccount == nil {
|
resp.Encryption.ServiceAccount == nil {
|
||||||
|
|
||||||
if m.Encryption.IsNull() || m.Encryption.IsUnknown() {
|
if m.Encryption.IsNull() || m.Encryption.IsUnknown() {
|
||||||
return sqlserverflexbetaDataGen.NewEncryptionValueNull()
|
return sqlserverflexbetaDataGen.NewEncryptionValueNull()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,6 @@ func TestMapDataSourceFields(t *testing.T) {
|
||||||
{
|
{
|
||||||
"simple_values",
|
"simple_values",
|
||||||
&sqlserverflexbeta.GetUserResponse{
|
&sqlserverflexbeta.GetUserResponse{
|
||||||
|
|
||||||
Roles: &[]string{
|
Roles: &[]string{
|
||||||
"role_1",
|
"role_1",
|
||||||
"role_2",
|
"role_2",
|
||||||
|
|
|
||||||
|
|
@ -453,11 +453,9 @@ func (r *userResource) ImportState(
|
||||||
req resource.ImportStateRequest,
|
req resource.ImportStateRequest,
|
||||||
resp *resource.ImportStateResponse,
|
resp *resource.ImportStateResponse,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
if req.ID != "" {
|
if req.ID != "" {
|
||||||
|
|
||||||
idParts := strings.Split(req.ID, core.Separator)
|
idParts := strings.Split(req.ID, core.Separator)
|
||||||
|
|
||||||
if len(idParts) != 4 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" || idParts[3] == "" {
|
if len(idParts) != 4 || idParts[0] == "" || idParts[1] == "" || idParts[2] == "" || idParts[3] == "" {
|
||||||
|
|
|
||||||
|
|
@ -272,8 +272,12 @@ func GetDatabaseByIdWaitHandler(
|
||||||
}
|
}
|
||||||
switch oapiErr.StatusCode {
|
switch oapiErr.StatusCode {
|
||||||
case http.StatusBadGateway, http.StatusGatewayTimeout, http.StatusServiceUnavailable:
|
case http.StatusBadGateway, http.StatusGatewayTimeout, http.StatusServiceUnavailable:
|
||||||
|
tflog.Warn(ctx, "api responded with 50[2,3,4] status", map[string]interface{}{
|
||||||
|
"status": oapiErr.StatusCode,
|
||||||
|
})
|
||||||
|
return false, nil, nil
|
||||||
case http.StatusNotFound:
|
case http.StatusNotFound:
|
||||||
tflog.Warn(ctx, "api responded with status", map[string]interface{}{
|
tflog.Warn(ctx, "api responded with 404 status", map[string]interface{}{
|
||||||
"status": oapiErr.StatusCode,
|
"status": oapiErr.StatusCode,
|
||||||
})
|
})
|
||||||
return false, nil, nil
|
return false, nil, nil
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue