chore: add sqlserveralpha tests (#49)
## Description
<!-- **Please link some issue here describing what you are trying to achieve.**
In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->
relates to #1234
## Checklist
- [ ] Issue was linked above
- [ ] Code format was applied: `make fmt`
- [ ] Examples were added / adjusted (see `examples/` directory)
- [x] Docs are up-to-date: `make generate-docs` (will be checked by CI)
- [ ] Unit tests got implemented or updated
- [ ] Acceptance tests got implemented or updated (see e.g. [here](f5f99d1709/stackit/internal/services/dns/dns_acc_test.go))
- [x] Unit tests are passing: `make test` (will be checked by CI)
- [x] No linter issues: `make lint` (will be checked by CI)
Reviewed-on: #49
Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
Co-committed-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
This commit is contained in:
parent
ed7ff0f58e
commit
86fc98461c
7 changed files with 814 additions and 587 deletions
|
|
@ -42,14 +42,16 @@ type {{.NameCamel}}Resource struct{
|
|||
type {{.NamePascal}}ResourceIdentityModel struct {
|
||||
ProjectID types.String `tfsdk:"project_id"`
|
||||
Region types.String `tfsdk:"region"`
|
||||
{{.NamePascal}}ID types.String `tfsdk:"instance_id"`
|
||||
// TODO: implement further needed parts
|
||||
{{.NamePascal}}ID types.String `tfsdk:"instance_id"`
|
||||
}
|
||||
|
||||
// Metadata defines terraform resource name
|
||||
func (r *{{.NameCamel}}Resource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_{{.PackageName}}_{{.NameSnake}}"
|
||||
}
|
||||
|
||||
// Schema loads the schema from generated files and adds plan modifiers
|
||||
func (r *{{.NameCamel}}Resource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
schema = {{.PackageName}}ResGen.{{.NamePascal}}ResourceSchema(ctx)
|
||||
|
||||
|
|
@ -67,6 +69,7 @@ func (r *{{.NameCamel}}Resource) Schema(ctx context.Context, req resource.Schema
|
|||
resp.Schema = schema
|
||||
}
|
||||
|
||||
// IdentitySchema defines the identity schema
|
||||
func (r *instanceResource) IdentitySchema(_ context.Context, _ resource.IdentitySchemaRequest, resp *resource.IdentitySchemaResponse) {
|
||||
resp.IdentitySchema = identityschema.Schema{
|
||||
Attributes: map[string]identityschema.Attribute{
|
||||
|
|
@ -83,7 +86,6 @@ func (r *instanceResource) IdentitySchema(_ context.Context, _ resource.Identity
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Configure adds the provider configured client to the resource.
|
||||
func (r *{{.NameCamel}}Resource) Configure(
|
||||
ctx context.Context,
|
||||
|
|
@ -152,18 +154,6 @@ func (r *{{.NameCamel}}Resource) ModifyPlan(
|
|||
return
|
||||
}
|
||||
|
||||
var identityModel {{.NamePascal}}ResourceIdentityModel
|
||||
identityModel.ProjectID = planModel.ProjectId
|
||||
identityModel.Region = planModel.Region
|
||||
if !planModel.{{.NamePascal}}Id.IsNull() && !planModel.{{.NamePascal}}Id.IsUnknown() {
|
||||
identityModel.{{.NamePascal}}ID = planModel.{{.NamePascal}}Id
|
||||
}
|
||||
|
||||
resp.Diagnostics.Append(resp.Identity.Set(ctx, identityModel)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
resp.Diagnostics.Append(resp.Plan.Set(ctx, planModel)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
|
|
@ -184,17 +174,10 @@ func (r *{{.NameCamel}}Resource) Create(ctx context.Context, req resource.Create
|
|||
return
|
||||
}
|
||||
|
||||
// Read identity data
|
||||
var identityData {{.NamePascal}}ResourceIdentityModel
|
||||
resp.Diagnostics.Append(req.Identity.Get(ctx, &identityData)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
projectId := identityData.ProjectID.ValueString()
|
||||
region := identityData.Region.ValueString()
|
||||
projectId := data.ProjectId.ValueString()
|
||||
region := data.Region.ValueString()
|
||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||
ctx = tflog.SetField(ctx, "region", region)
|
||||
|
||||
|
|
@ -320,7 +303,7 @@ func (r *{{.NameCamel}}Resource) Read(ctx context.Context, req resource.ReadRequ
|
|||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||
ctx = tflog.SetField(ctx, "region", region)
|
||||
|
||||
// Todo: Read API call logic
|
||||
// TODO: Read API call logic
|
||||
|
||||
// Save updated data into Terraform state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||
|
|
@ -348,22 +331,26 @@ func (r *{{.NameCamel}}Resource) Update(ctx context.Context, req resource.Update
|
|||
return
|
||||
}
|
||||
|
||||
// Read identity data
|
||||
var identityData {{.NamePascal}}ResourceIdentityModel
|
||||
resp.Diagnostics.Append(req.Identity.Get(ctx, &identityData)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
projectId := identityData.ProjectID.ValueString()
|
||||
region := identityData.Region.ValueString()
|
||||
projectId := data.ProjectId.ValueString()
|
||||
region := data.Region.ValueString()
|
||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||
ctx = tflog.SetField(ctx, "region", region)
|
||||
|
||||
// Todo: Update API call logic
|
||||
// TODO: Update API call logic
|
||||
|
||||
// TODO: Set data returned by API in identity
|
||||
identity := {{.NamePascal}}ResourceIdentityModel{
|
||||
ProjectID: types.StringValue(projectId),
|
||||
Region: types.StringValue(region),
|
||||
// TODO: add missing values
|
||||
{{.NamePascal}}ID: types.StringValue({{.NamePascal}}Id),
|
||||
}
|
||||
resp.Diagnostics.Append(resp.Identity.Set(ctx, identity)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
// Save updated data into Terraform state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||
|
|
@ -395,7 +382,7 @@ func (r *{{.NameCamel}}Resource) Delete(ctx context.Context, req resource.Delete
|
|||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||
ctx = tflog.SetField(ctx, "region", region)
|
||||
|
||||
// Todo: Delete API call logic
|
||||
// TODO: Delete API call logic
|
||||
|
||||
tflog.Info(ctx, "{{.PackageName}}.{{.NamePascal}} deleted")
|
||||
}
|
||||
|
|
@ -409,7 +396,8 @@ func (r *{{.NameCamel}}Resource) ImportState(
|
|||
) {
|
||||
idParts := strings.Split(req.ID, core.Separator)
|
||||
|
||||
// Todo: Import logic
|
||||
// TODO: Import logic
|
||||
// TODO: fix len and parts itself
|
||||
if len(idParts) < 2 || idParts[0] == "" || idParts[1] == "" {
|
||||
core.LogAndAddError(
|
||||
ctx, &resp.Diagnostics,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue