fix: pipeline fixes
[skip ci]
This commit is contained in:
parent
eecf98f4b1
commit
8c490da5ce
6 changed files with 56 additions and 47 deletions
|
|
@ -143,7 +143,7 @@ func (d *databaseDataSource) Read(ctx context.Context, req datasource.ReadReques
|
||||||
// Save data into Terraform state
|
// Save data into Terraform state
|
||||||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||||
|
|
||||||
tflog.Info(ctx, "SQL Server Flex beta database read")
|
tflog.Info(ctx, "SQL Server Flex Alpha database read")
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleReadError centralizes API error handling for the Read operation.
|
// handleReadError centralizes API error handling for the Read operation.
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ func (r *instanceResource) ModifyPlan(
|
||||||
|
|
||||||
func (r *instanceResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
func (r *instanceResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
|
||||||
var data resourceModel
|
var data resourceModel
|
||||||
crateErr := "[SQL Server Flex BETA - Create] error"
|
crateErr := "[SQL Server Flex Alpha - Create] error"
|
||||||
|
|
||||||
// Read Terraform plan data into the model
|
// Read Terraform plan data into the model
|
||||||
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
|
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)
|
||||||
|
|
|
||||||
|
|
@ -61,20 +61,20 @@ func testAccPreCheck(t *testing.T) {
|
||||||
|
|
||||||
type resData struct {
|
type resData struct {
|
||||||
ServiceAccountFilePath string
|
ServiceAccountFilePath string
|
||||||
ProjectId string
|
ProjectID string
|
||||||
Region string
|
Region string
|
||||||
Name string
|
Name string
|
||||||
TfName string
|
TfName string
|
||||||
FlavorId string
|
FlavorID string
|
||||||
BackupSchedule string
|
BackupSchedule string
|
||||||
UseEncryption bool
|
UseEncryption bool
|
||||||
KekKeyId string
|
KekKeyID string
|
||||||
KekKeyRingId string
|
KekKeyRingID string
|
||||||
KekKeyVersion uint8
|
KekKeyVersion uint8
|
||||||
KekServiceAccount string
|
KekServiceAccount string
|
||||||
PerformanceClass string
|
PerformanceClass string
|
||||||
Size uint32
|
Size uint32
|
||||||
AclString string
|
ACLString string
|
||||||
AccessScope string
|
AccessScope string
|
||||||
RetentionDays uint32
|
RetentionDays uint32
|
||||||
Version string
|
Version string
|
||||||
|
|
@ -84,13 +84,13 @@ type resData struct {
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Name string
|
Name string
|
||||||
ProjectId string
|
ProjectID string
|
||||||
Roles []string
|
Roles []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Database struct {
|
type Database struct {
|
||||||
Name string
|
Name string
|
||||||
ProjectId string
|
ProjectID string
|
||||||
Owner string
|
Owner string
|
||||||
Collation string
|
Collation string
|
||||||
Compatibility string
|
Compatibility string
|
||||||
|
|
@ -105,16 +105,16 @@ func getExample() resData {
|
||||||
return resData{
|
return resData{
|
||||||
Region: os.Getenv("TF_ACC_REGION"),
|
Region: os.Getenv("TF_ACC_REGION"),
|
||||||
ServiceAccountFilePath: os.Getenv("TF_ACC_SERVICE_ACCOUNT_FILE"),
|
ServiceAccountFilePath: os.Getenv("TF_ACC_SERVICE_ACCOUNT_FILE"),
|
||||||
ProjectId: os.Getenv("TF_ACC_PROJECT_ID"),
|
ProjectID: os.Getenv("TF_ACC_PROJECT_ID"),
|
||||||
Name: name,
|
Name: name,
|
||||||
TfName: name,
|
TfName: name,
|
||||||
FlavorId: "4.16-Single",
|
FlavorID: "4.16-Single",
|
||||||
BackupSchedule: "0 0 * * *",
|
BackupSchedule: "0 0 * * *",
|
||||||
UseEncryption: false,
|
UseEncryption: false,
|
||||||
RetentionDays: 33,
|
RetentionDays: 33,
|
||||||
PerformanceClass: "premium-perf2-stackit",
|
PerformanceClass: "premium-perf2-stackit",
|
||||||
Size: 10,
|
Size: 10,
|
||||||
AclString: "0.0.0.0/0",
|
ACLString: "0.0.0.0/0",
|
||||||
AccessScope: "PUBLIC",
|
AccessScope: "PUBLIC",
|
||||||
Version: "2022",
|
Version: "2022",
|
||||||
}
|
}
|
||||||
|
|
@ -194,21 +194,21 @@ func TestAccInstanceNoEncryption(t *testing.T) {
|
||||||
data.Users = []User{
|
data.Users = []User{
|
||||||
{
|
{
|
||||||
Name: userName,
|
Name: userName,
|
||||||
ProjectId: os.Getenv("TF_ACC_PROJECT_ID"),
|
ProjectID: os.Getenv("TF_ACC_PROJECT_ID"),
|
||||||
Roles: []string{
|
Roles: []string{
|
||||||
"##STACKIT_DatabaseManager##",
|
"##STACKIT_DatabaseManager##",
|
||||||
"##STACKIT_LoginManager##",
|
"##STACKIT_LoginManager##",
|
||||||
"##STACKIT_ProcessManager##",
|
//"##STACKIT_ProcessManager##",
|
||||||
"##STACKIT_SQLAgentManager##",
|
//"##STACKIT_SQLAgentManager##",
|
||||||
"##STACKIT_SQLAgentUser##",
|
//"##STACKIT_SQLAgentUser##",
|
||||||
"##STACKIT_ServerManager##",
|
//"##STACKIT_ServerManager##",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
data.Databases = []Database{
|
data.Databases = []Database{
|
||||||
{
|
{
|
||||||
Name: dbName,
|
Name: dbName,
|
||||||
ProjectId: os.Getenv("TF_ACC_PROJECT_ID"),
|
ProjectID: os.Getenv("TF_ACC_PROJECT_ID"),
|
||||||
Owner: userName,
|
Owner: userName,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -298,23 +298,28 @@ func TestAccInstanceEncryption(t *testing.T) {
|
||||||
data.Users = []User{
|
data.Users = []User{
|
||||||
{
|
{
|
||||||
Name: userName,
|
Name: userName,
|
||||||
ProjectId: os.Getenv("TF_ACC_PROJECT_ID"),
|
ProjectID: os.Getenv("TF_ACC_PROJECT_ID"),
|
||||||
Roles: []string{"##STACKIT_DatabaseManager##", "##STACKIT_LoginManager##"},
|
Roles: []string{"##STACKIT_DatabaseManager##", "##STACKIT_LoginManager##"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
data.Databases = []Database{
|
data.Databases = []Database{
|
||||||
{
|
{
|
||||||
Name: dbName,
|
Name: dbName,
|
||||||
ProjectId: os.Getenv("TF_ACC_PROJECT_ID"),
|
ProjectID: os.Getenv("TF_ACC_PROJECT_ID"),
|
||||||
Owner: userName,
|
Owner: userName,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
data.UseEncryption = true
|
data.UseEncryption = true
|
||||||
data.KekKeyId = "fe039bcf-8d7b-431a-801d-9e81371a6b7b"
|
data.KekKeyID = os.Getenv("TF_ACC_KEK_KEY_ID")
|
||||||
data.KekKeyRingId = "6a2d95ab-3c4c-4963-a2bb-08d17a320e27"
|
data.KekKeyRingID = os.Getenv("TF_ACC_KEK_KEY_RING_ID")
|
||||||
data.KekKeyVersion = 1
|
verString := os.Getenv("TF_ACC_KEK_KEY_VERSION")
|
||||||
data.KekServiceAccount = "henselinm-u2v3ex1@sa.stackit.cloud"
|
version, err := strconv.ParseUint(verString, 0, 8)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("error coverting value to uint8")
|
||||||
|
}
|
||||||
|
data.KekKeyVersion = uint8(version)
|
||||||
|
data.KekServiceAccount = os.Getenv("TF_ACC_KEK_SERVICE_ACCOUNT")
|
||||||
|
|
||||||
resource.ParallelTest(t, resource.TestCase{
|
resource.ParallelTest(t, resource.TestCase{
|
||||||
PreCheck: func() {
|
PreCheck: func() {
|
||||||
|
|
|
||||||
|
|
@ -136,5 +136,5 @@ func (d *userDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
|
||||||
if resp.Diagnostics.HasError() {
|
if resp.Diagnostics.HasError() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tflog.Info(ctx, "SQLServer Flex beta instance read")
|
tflog.Info(ctx, "SQLServer Flex Alpha instance read")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,18 +80,18 @@ func mapFields(userResp *v3alpha1api.GetUserResponse, model *resourceModel, regi
|
||||||
user := userResp
|
user := userResp
|
||||||
|
|
||||||
// Handle user ID
|
// Handle user ID
|
||||||
var userId int64
|
var userID int64
|
||||||
if model.UserId.ValueInt64() != 0 {
|
if model.UserId.ValueInt64() != 0 {
|
||||||
userId = model.UserId.ValueInt64()
|
userID = model.UserId.ValueInt64()
|
||||||
} else if user.Id != 0 {
|
} else if user.Id != 0 {
|
||||||
userId = user.Id
|
userID = user.Id
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("user id not present")
|
return fmt.Errorf("user id not present")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set main attributes
|
// Set main attributes
|
||||||
model.Id = types.Int64Value(userId)
|
model.Id = types.Int64Value(userID)
|
||||||
model.UserId = types.Int64Value(userId)
|
model.UserId = types.Int64Value(userID)
|
||||||
model.Username = types.StringValue(user.Username)
|
model.Username = types.StringValue(user.Username)
|
||||||
|
|
||||||
// Map roles
|
// Map roles
|
||||||
|
|
@ -135,9 +135,9 @@ func mapFieldsCreate(userResp *v3alpha1api.CreateUserResponse, model *resourceMo
|
||||||
if user.Id == 0 {
|
if user.Id == 0 {
|
||||||
return fmt.Errorf("user id not present")
|
return fmt.Errorf("user id not present")
|
||||||
}
|
}
|
||||||
userId := user.Id
|
userID := user.Id
|
||||||
model.Id = types.Int64Value(userId)
|
model.Id = types.Int64Value(userID)
|
||||||
model.UserId = types.Int64Value(userId)
|
model.UserId = types.Int64Value(userID)
|
||||||
model.Username = types.StringValue(user.Username)
|
model.Username = types.StringValue(user.Username)
|
||||||
|
|
||||||
if user.Password == "" {
|
if user.Password == "" {
|
||||||
|
|
@ -185,9 +185,13 @@ func toCreatePayload(
|
||||||
return nil, fmt.Errorf("nil model")
|
return nil, fmt.Errorf("nil model")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &v3alpha1api.CreateUserRequestPayload{
|
res := v3alpha1api.CreateUserRequestPayload{
|
||||||
Username: model.Username.ValueString(),
|
Username: model.Username.ValueString(),
|
||||||
DefaultDatabase: model.DefaultDatabase.ValueStringPointer(),
|
DefaultDatabase: nil,
|
||||||
Roles: roles,
|
Roles: roles,
|
||||||
}, nil
|
}
|
||||||
|
if !model.DefaultDatabase.IsUnknown() && !model.DefaultDatabase.IsNull() {
|
||||||
|
res.DefaultDatabase = model.DefaultDatabase.ValueStringPointer()
|
||||||
|
}
|
||||||
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ func (r *userResource) Configure(ctx context.Context, req resource.ConfigureRequ
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r.client = apiClient
|
r.client = apiClient
|
||||||
tflog.Info(ctx, "SQLServer Beta Flex user client configured")
|
tflog.Info(ctx, "SQLServer Alpha Flex user client configured")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ModifyPlan implements resource.ResourceWithModifyPlan.
|
// ModifyPlan implements resource.ResourceWithModifyPlan.
|
||||||
|
|
@ -206,12 +206,12 @@ func (r *userResource) Create(
|
||||||
|
|
||||||
ctx = core.InitProviderContext(ctx)
|
ctx = core.InitProviderContext(ctx)
|
||||||
|
|
||||||
projectId := model.ProjectId.ValueString()
|
projectID := model.ProjectId.ValueString()
|
||||||
instanceId := model.InstanceId.ValueString()
|
instanceID := model.InstanceId.ValueString()
|
||||||
region := model.Region.ValueString()
|
region := model.Region.ValueString()
|
||||||
|
|
||||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
ctx = tflog.SetField(ctx, "project_id", projectID)
|
||||||
ctx = tflog.SetField(ctx, "instance_id", instanceId)
|
ctx = tflog.SetField(ctx, "instance_id", instanceID)
|
||||||
ctx = tflog.SetField(ctx, "region", region)
|
ctx = tflog.SetField(ctx, "region", region)
|
||||||
|
|
||||||
var roles []string
|
var roles []string
|
||||||
|
|
@ -234,9 +234,9 @@ func (r *userResource) Create(
|
||||||
// Create new user
|
// Create new user
|
||||||
userResp, err := r.client.DefaultAPI.CreateUserRequest(
|
userResp, err := r.client.DefaultAPI.CreateUserRequest(
|
||||||
ctx,
|
ctx,
|
||||||
projectId,
|
projectID,
|
||||||
region,
|
region,
|
||||||
instanceId,
|
instanceID,
|
||||||
).CreateUserRequestPayload(*payload).Execute()
|
).CreateUserRequestPayload(*payload).Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating user", fmt.Sprintf("Calling API: %v", err))
|
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating user", fmt.Sprintf("Calling API: %v", err))
|
||||||
|
|
@ -260,9 +260,9 @@ func (r *userResource) Create(
|
||||||
|
|
||||||
// Set data returned by API in identity
|
// Set data returned by API in identity
|
||||||
identity := UserResourceIdentityModel{
|
identity := UserResourceIdentityModel{
|
||||||
ProjectID: types.StringValue(projectId),
|
ProjectID: types.StringValue(projectID),
|
||||||
Region: types.StringValue(region),
|
Region: types.StringValue(region),
|
||||||
InstanceID: types.StringValue(instanceId),
|
InstanceID: types.StringValue(instanceID),
|
||||||
UserID: types.Int64Value(userId),
|
UserID: types.Int64Value(userId),
|
||||||
}
|
}
|
||||||
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
|
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
|
||||||
|
|
@ -284,8 +284,8 @@ func (r *userResource) Create(
|
||||||
waitResp, err := sqlserverflexalphaWait.CreateUserWaitHandler(
|
waitResp, err := sqlserverflexalphaWait.CreateUserWaitHandler(
|
||||||
ctx,
|
ctx,
|
||||||
r.client.DefaultAPI,
|
r.client.DefaultAPI,
|
||||||
projectId,
|
projectID,
|
||||||
instanceId,
|
instanceID,
|
||||||
region,
|
region,
|
||||||
userId,
|
userId,
|
||||||
).SetSleepBeforeWait(
|
).SetSleepBeforeWait(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue