feat: refactor builder for datasource
This commit is contained in:
parent
b1b359f436
commit
f44659f703
24 changed files with 151 additions and 1426 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package build
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
|
@ -509,7 +510,7 @@ func generateServiceFiles(rootDir, generatorDir string) error {
|
|||
|
||||
oasFile := path.Join(generatorDir, "oas", fmt.Sprintf("%s%s.json", service.Name(), svcVersion.Name()))
|
||||
if _, oasErr := os.Stat(oasFile); os.IsNotExist(oasErr) {
|
||||
slog.Warn(" coulc not find matching oas", "svc", service.Name(), "version", svcVersion.Name())
|
||||
slog.Warn(" could not find matching oas", "svc", service.Name(), "version", svcVersion.Name())
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -648,6 +649,15 @@ func generateServiceFiles(rootDir, generatorDir string) error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
|
||||
tfAnoErr := handleTfTagForDatasourceFile(
|
||||
path.Join(tgtFolder, fmt.Sprintf("%s_data_source_gen.go", resource)),
|
||||
scName,
|
||||
resource,
|
||||
)
|
||||
if tfAnoErr != nil {
|
||||
return tfAnoErr
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -655,6 +665,70 @@ func generateServiceFiles(rootDir, generatorDir string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// handleTfTagForDatasourceFile replaces existing "id" with "stf_original_api_id"
|
||||
func handleTfTagForDatasourceFile(filePath, service, resource string) error {
|
||||
slog.Info(" handle terraform tag for datasource", "service", service, "resource", resource)
|
||||
if !fileExists(filePath) {
|
||||
slog.Warn(" could not find file, skipping", "path", filePath)
|
||||
return nil
|
||||
}
|
||||
f, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
tmp, err := os.CreateTemp("", "replace-*")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tmp.Close()
|
||||
|
||||
sc := bufio.NewScanner(f)
|
||||
for sc.Scan() {
|
||||
resLine, err := handleLine(sc.Text())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := io.WriteString(tmp, resLine+"\n"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if scErr := sc.Err(); scErr != nil {
|
||||
return scErr
|
||||
}
|
||||
|
||||
if err := tmp.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := f.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.Rename(tmp.Name(), filePath); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleLine(line string) (string, error) {
|
||||
schemaRegex := regexp.MustCompile(`(\s+")(id)(": schema.[a-zA-Z0-9]+Attribute{)`)
|
||||
|
||||
schemaMatches := schemaRegex.FindAllStringSubmatch(line, -1)
|
||||
if schemaMatches != nil {
|
||||
return fmt.Sprintf("%stf_original_api_id%s", schemaMatches[0][1], schemaMatches[0][3]), nil
|
||||
}
|
||||
|
||||
modelRegex := regexp.MustCompile(`(\s+Id\s+types.[a-zA-Z0-9]+\s+.tfsdk:")(id)(".)`)
|
||||
modelMatches := modelRegex.FindAllStringSubmatch(line, -1)
|
||||
if modelMatches != nil {
|
||||
return fmt.Sprintf("%stf_original_api_id%s", modelMatches[0][1], modelMatches[0][3]), nil
|
||||
}
|
||||
|
||||
return line, nil
|
||||
}
|
||||
|
||||
func checkCommands(commands []string) error {
|
||||
for _, commandName := range commands {
|
||||
if !commandExists(commandName) {
|
||||
|
|
|
|||
|
|
@ -38,12 +38,12 @@ Read-Only:
|
|||
|
||||
- `cpu` (Number) The cpu count of the instance.
|
||||
- `description` (String) The flavor description.
|
||||
- `id` (String) The id of the instance flavor.
|
||||
- `max_gb` (Number) maximum storage which can be ordered for the flavor in Gigabyte.
|
||||
- `memory` (Number) The memory of the instance in Gibibyte.
|
||||
- `min_gb` (Number) minimum storage which is required to order in Gigabyte.
|
||||
- `node_type` (String) defines the nodeType it can be either single or replica
|
||||
- `storage_classes` (Attributes List) maximum storage which can be ordered for the flavor in Gigabyte. (see [below for nested schema](#nestedatt--flavors--storage_classes))
|
||||
- `tf_original_api_id` (String) The id of the instance flavor.
|
||||
|
||||
<a id="nestedatt--flavors--storage_classes"></a>
|
||||
### Nested Schema for `flavors.storage_classes`
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ data "stackitprivatepreview_postgresflexalpha_instance" "example" {
|
|||
|
||||
⚠ **Note:** This feature is in private preview. Supplying this object is only permitted for enabled accounts. If your account does not have access, the request will be rejected. (see [below for nested schema](#nestedatt--encryption))
|
||||
- `flavor_id` (String) The id of the instance flavor.
|
||||
- `id` (String) The ID of the instance.
|
||||
- `is_deletable` (Boolean) Whether the instance can be deleted or not.
|
||||
- `name` (String) The name of the instance.
|
||||
- `network` (Attributes) The access configuration of the instance (see [below for nested schema](#nestedatt--network))
|
||||
|
|
@ -45,6 +44,7 @@ data "stackitprivatepreview_postgresflexalpha_instance" "example" {
|
|||
- `retention_days` (Number) How long backups are retained. The value can only be between 32 and 365 days.
|
||||
- `status` (String) The current status of the instance.
|
||||
- `storage` (Attributes) The object containing information about the storage size and class. (see [below for nested schema](#nestedatt--storage))
|
||||
- `tf_original_api_id` (String) The ID of the instance.
|
||||
- `version` (String) The Postgres version used for the instance. See [Versions Endpoint](/documentation/postgres-flex-service/version/v3alpha1#tag/Version) for supported version parameters.
|
||||
|
||||
<a id="nestedatt--connection_info"></a>
|
||||
|
|
|
|||
|
|
@ -26,6 +26,6 @@ description: |-
|
|||
|
||||
- `collation_name` (String) The collation of the database. This database collation should match the *collation_name* of one of the collations given by the **Get database collation list** endpoint.
|
||||
- `compatibility_level` (Number) CompatibilityLevel of the Database.
|
||||
- `id` (Number) The id of the database.
|
||||
- `name` (String) The name of the database.
|
||||
- `owner` (String) The owner of the database.
|
||||
- `tf_original_api_id` (Number) The id of the database.
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ data "stackitprivatepreview_sqlserverflexalpha_instance" "example" {
|
|||
- `edition` (String) Edition of the MSSQL server instance
|
||||
- `encryption` (Attributes) this defines which key to use for storage encryption (see [below for nested schema](#nestedatt--encryption))
|
||||
- `flavor_id` (String) The id of the instance flavor.
|
||||
- `id` (String) The ID of the instance.
|
||||
- `is_deletable` (Boolean) Whether the instance can be deleted or not.
|
||||
- `name` (String) The name of the instance.
|
||||
- `network` (Attributes) The access configuration of the instance (see [below for nested schema](#nestedatt--network))
|
||||
|
|
@ -42,6 +41,7 @@ data "stackitprivatepreview_sqlserverflexalpha_instance" "example" {
|
|||
- `retention_days` (Number) The days for how long the backup files should be stored before cleaned up. 30 to 365
|
||||
- `status` (String)
|
||||
- `storage` (Attributes) The object containing information about the storage size and class. (see [below for nested schema](#nestedatt--storage))
|
||||
- `tf_original_api_id` (String) The ID of the instance.
|
||||
- `version` (String) The sqlserver version used for the instance.
|
||||
|
||||
<a id="nestedatt--encryption"></a>
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ data "stackitprivatepreview_sqlserverflexbeta_instance" "example" {
|
|||
- `edition` (String) Edition of the MSSQL server instance
|
||||
- `encryption` (Attributes) this defines which key to use for storage encryption (see [below for nested schema](#nestedatt--encryption))
|
||||
- `flavor_id` (String) The id of the instance flavor.
|
||||
- `id` (String) The ID of the instance.
|
||||
- `is_deletable` (Boolean) Whether the instance can be deleted or not.
|
||||
- `name` (String) The name of the instance.
|
||||
- `network` (Attributes) The access configuration of the instance (see [below for nested schema](#nestedatt--network))
|
||||
|
|
@ -42,6 +41,7 @@ data "stackitprivatepreview_sqlserverflexbeta_instance" "example" {
|
|||
- `retention_days` (Number) The days for how long the backup files should be stored before cleaned up. 30 to 365
|
||||
- `status` (String)
|
||||
- `storage` (Attributes) The object containing information about the storage size and class. (see [below for nested schema](#nestedatt--storage))
|
||||
- `tf_original_api_id` (String) The ID of the instance.
|
||||
- `version` (String) The sqlserver version used for the instance.
|
||||
|
||||
<a id="nestedatt--encryption"></a>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ package postgresflexalpha
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
|
||||
|
|
@ -12,11 +14,23 @@ import (
|
|||
func DatabaseResourceSchema(ctx context.Context) schema.Schema {
|
||||
return schema.Schema{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"database_id": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "The ID of the database.",
|
||||
MarkdownDescription: "The ID of the database.",
|
||||
},
|
||||
"id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
Description: "The id of the database.",
|
||||
MarkdownDescription: "The id of the database.",
|
||||
},
|
||||
"instance_id": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "The ID of the instance.",
|
||||
MarkdownDescription: "The ID of the instance.",
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: "The name of the database.",
|
||||
|
|
@ -28,12 +42,33 @@ func DatabaseResourceSchema(ctx context.Context) schema.Schema {
|
|||
Description: "The owner of the database.",
|
||||
MarkdownDescription: "The owner of the database.",
|
||||
},
|
||||
"project_id": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "The STACKIT project ID.",
|
||||
MarkdownDescription: "The STACKIT project ID.",
|
||||
},
|
||||
"region": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "The region which should be addressed",
|
||||
MarkdownDescription: "The region which should be addressed",
|
||||
Validators: []validator.String{
|
||||
stringvalidator.OneOf(
|
||||
"eu01",
|
||||
),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type DatabaseModel struct {
|
||||
Id types.Int64 `tfsdk:"id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Owner types.String `tfsdk:"owner"`
|
||||
DatabaseId types.Int64 `tfsdk:"database_id"`
|
||||
Id types.Int64 `tfsdk:"id"`
|
||||
InstanceId types.String `tfsdk:"instance_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Owner types.String `tfsdk:"owner"`
|
||||
ProjectId types.String `tfsdk:"project_id"`
|
||||
Region types.String `tfsdk:"region"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func FlavorsDataSourceSchema(ctx context.Context) schema.Schema {
|
|||
Description: "The flavor description.",
|
||||
MarkdownDescription: "The flavor description.",
|
||||
},
|
||||
"id": schema.StringAttribute{
|
||||
"tf_original_api_id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: "The id of the instance flavor.",
|
||||
MarkdownDescription: "The id of the instance flavor.",
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ func InstanceDataSourceSchema(ctx context.Context) schema.Schema {
|
|||
Description: "The id of the instance flavor.",
|
||||
MarkdownDescription: "The id of the instance flavor.",
|
||||
},
|
||||
"id": schema.StringAttribute{
|
||||
"tf_original_api_id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: "The ID of the instance.",
|
||||
MarkdownDescription: "The ID of the instance.",
|
||||
|
|
@ -204,7 +204,7 @@ type InstanceModel struct {
|
|||
ConnectionInfo ConnectionInfoValue `tfsdk:"connection_info"`
|
||||
Encryption EncryptionValue `tfsdk:"encryption"`
|
||||
FlavorId types.String `tfsdk:"flavor_id"`
|
||||
Id types.String `tfsdk:"id"`
|
||||
Id types.String `tfsdk:"tf_original_api_id"`
|
||||
InstanceId types.String `tfsdk:"instance_id"`
|
||||
IsDeletable types.Bool `tfsdk:"is_deletable"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
|
|
|
|||
|
|
@ -164,6 +164,11 @@ func TestAccPostgresFlexFlexResource(t *testing.T) {
|
|||
Steps: []resource.TestStep{
|
||||
// Creation
|
||||
{
|
||||
// testdata/<Test_Name>
|
||||
// ConfigDirectory: config.TestNameDirectory(),
|
||||
|
||||
// testdata/<Test_Name>/<step_number>
|
||||
// ConfigDirectory: config.TestStepDirectory(),
|
||||
Config: configResources(instanceResource["backup_schedule"], &testutil.Region),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
// Instance
|
||||
|
|
|
|||
|
|
@ -274,10 +274,7 @@ func mapDataSourceFields(userResp *postgresflex.GetUserResponse, model *DataSour
|
|||
}
|
||||
model.Roles = rolesSet
|
||||
}
|
||||
model.Host = types.StringPointerValue(user.Host)
|
||||
model.Port = types.Int64PointerValue(user.Port)
|
||||
model.Region = types.StringValue(region)
|
||||
model.Status = types.StringPointerValue(user.Status)
|
||||
model.ConnectionString = types.StringPointerValue(user.ConnectionString)
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,17 +14,7 @@ import (
|
|||
func UserDataSourceSchema(ctx context.Context) schema.Schema {
|
||||
return schema.Schema{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"connection_string": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: "The connection string for the user to the instance.",
|
||||
MarkdownDescription: "The connection string for the user to the instance.",
|
||||
},
|
||||
"host": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: "The host of the instance in which the user belongs to.",
|
||||
MarkdownDescription: "The host of the instance in which the user belongs to.",
|
||||
},
|
||||
"id": schema.Int64Attribute{
|
||||
"tf_original_api_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
Description: "The ID of the user.",
|
||||
MarkdownDescription: "The ID of the user.",
|
||||
|
|
@ -39,11 +29,6 @@ func UserDataSourceSchema(ctx context.Context) schema.Schema {
|
|||
Description: "The name of the user.",
|
||||
MarkdownDescription: "The name of the user.",
|
||||
},
|
||||
"port": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
Description: "The port of the instance in which the user belongs to.",
|
||||
MarkdownDescription: "The port of the instance in which the user belongs to.",
|
||||
},
|
||||
"project_id": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: "The STACKIT project ID.",
|
||||
|
|
@ -80,15 +65,12 @@ func UserDataSourceSchema(ctx context.Context) schema.Schema {
|
|||
}
|
||||
|
||||
type UserModel struct {
|
||||
ConnectionString types.String `tfsdk:"connection_string"`
|
||||
Host types.String `tfsdk:"host"`
|
||||
Id types.Int64 `tfsdk:"id"`
|
||||
InstanceId types.String `tfsdk:"instance_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Port types.Int64 `tfsdk:"port"`
|
||||
ProjectId types.String `tfsdk:"project_id"`
|
||||
Region types.String `tfsdk:"region"`
|
||||
Roles types.List `tfsdk:"roles"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
UserId types.Int64 `tfsdk:"user_id"`
|
||||
Id types.Int64 `tfsdk:"tf_original_api_id"`
|
||||
InstanceId types.String `tfsdk:"instance_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
ProjectId types.String `tfsdk:"project_id"`
|
||||
Region types.String `tfsdk:"region"`
|
||||
Roles types.List `tfsdk:"roles"`
|
||||
Status types.String `tfsdk:"status"`
|
||||
UserId types.Int64 `tfsdk:"user_id"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -556,11 +556,8 @@ func mapFields(userResp *postgresflex.GetUserResponse, model *Model, region stri
|
|||
}
|
||||
model.Roles = rolesSet
|
||||
}
|
||||
model.Host = types.StringPointerValue(user.Host)
|
||||
model.Port = types.Int64PointerValue(user.Port)
|
||||
model.Region = types.StringValue(region)
|
||||
model.Status = types.StringPointerValue(user.Status)
|
||||
model.ConnectionString = types.StringPointerValue(user.ConnectionString)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,11 +19,6 @@ func UserResourceSchema(ctx context.Context) schema.Schema {
|
|||
Description: "The connection string for the user to the instance.",
|
||||
MarkdownDescription: "The connection string for the user to the instance.",
|
||||
},
|
||||
"host": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: "The host of the instance in which the user belongs to.",
|
||||
MarkdownDescription: "The host of the instance in which the user belongs to.",
|
||||
},
|
||||
"id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
Description: "The ID of the user.",
|
||||
|
|
@ -45,11 +40,6 @@ func UserResourceSchema(ctx context.Context) schema.Schema {
|
|||
Description: "The password for the user.",
|
||||
MarkdownDescription: "The password for the user.",
|
||||
},
|
||||
"port": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
Description: "The port of the instance in which the user belongs to.",
|
||||
MarkdownDescription: "The port of the instance in which the user belongs to.",
|
||||
},
|
||||
"project_id": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
|
|
@ -91,12 +81,10 @@ func UserResourceSchema(ctx context.Context) schema.Schema {
|
|||
|
||||
type UserModel struct {
|
||||
ConnectionString types.String `tfsdk:"connection_string"`
|
||||
Host types.String `tfsdk:"host"`
|
||||
Id types.Int64 `tfsdk:"id"`
|
||||
InstanceId types.String `tfsdk:"instance_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Password types.String `tfsdk:"password"`
|
||||
Port types.Int64 `tfsdk:"port"`
|
||||
ProjectId types.String `tfsdk:"project_id"`
|
||||
Region types.String `tfsdk:"region"`
|
||||
Roles types.List `tfsdk:"roles"`
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ func DatabaseDataSourceSchema(ctx context.Context) schema.Schema {
|
|||
Description: "The name of the database.",
|
||||
MarkdownDescription: "The name of the database.",
|
||||
},
|
||||
"id": schema.Int64Attribute{
|
||||
"tf_original_api_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
Description: "The id of the database.",
|
||||
MarkdownDescription: "The id of the database.",
|
||||
|
|
@ -72,7 +72,7 @@ type DatabaseModel struct {
|
|||
CollationName types.String `tfsdk:"collation_name"`
|
||||
CompatibilityLevel types.Int64 `tfsdk:"compatibility_level"`
|
||||
DatabaseName types.String `tfsdk:"database_name"`
|
||||
Id types.Int64 `tfsdk:"id"`
|
||||
Id types.Int64 `tfsdk:"tf_original_api_id"`
|
||||
InstanceId types.String `tfsdk:"instance_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Owner types.String `tfsdk:"owner"`
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func FlavorsDataSourceSchema(ctx context.Context) schema.Schema {
|
|||
Description: "The flavor description.",
|
||||
MarkdownDescription: "The flavor description.",
|
||||
},
|
||||
"id": schema.StringAttribute{
|
||||
"tf_original_api_id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: "The id of the instance flavor.",
|
||||
MarkdownDescription: "The id of the instance flavor.",
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ func InstanceDataSourceSchema(ctx context.Context) schema.Schema {
|
|||
Description: "The id of the instance flavor.",
|
||||
MarkdownDescription: "The id of the instance flavor.",
|
||||
},
|
||||
"id": schema.StringAttribute{
|
||||
"tf_original_api_id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: "The ID of the instance.",
|
||||
MarkdownDescription: "The ID of the instance.",
|
||||
|
|
@ -178,7 +178,7 @@ type InstanceModel struct {
|
|||
Edition types.String `tfsdk:"edition"`
|
||||
Encryption EncryptionValue `tfsdk:"encryption"`
|
||||
FlavorId types.String `tfsdk:"flavor_id"`
|
||||
Id types.String `tfsdk:"id"`
|
||||
Id types.String `tfsdk:"tf_original_api_id"`
|
||||
InstanceId types.String `tfsdk:"instance_id"`
|
||||
IsDeletable types.Bool `tfsdk:"is_deletable"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ func UserDataSourceSchema(ctx context.Context) schema.Schema {
|
|||
"users": schema.ListNestedAttribute{
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"id": schema.Int64Attribute{
|
||||
"tf_original_api_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
Description: "The ID of the user.",
|
||||
MarkdownDescription: "The ID of the user.",
|
||||
|
|
|
|||
|
|
@ -1,81 +0,0 @@
|
|||
// Code generated by terraform-plugin-framework-generator DO NOT EDIT.
|
||||
|
||||
package sqlserverflexbeta
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
|
||||
)
|
||||
|
||||
func DatabaseDataSourceSchema(ctx context.Context) schema.Schema {
|
||||
return schema.Schema{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"collation_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: "The collation of the database. This database collation should match the *collation_name* of one of the collations given by the **Get database collation list** endpoint.",
|
||||
MarkdownDescription: "The collation of the database. This database collation should match the *collation_name* of one of the collations given by the **Get database collation list** endpoint.",
|
||||
},
|
||||
"compatibility_level": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
Description: "CompatibilityLevel of the Database.",
|
||||
MarkdownDescription: "CompatibilityLevel of the Database.",
|
||||
},
|
||||
"database_name": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: "The name of the database.",
|
||||
MarkdownDescription: "The name of the database.",
|
||||
},
|
||||
"tf_original_api_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
Description: "The id of the database.",
|
||||
MarkdownDescription: "The id of the database.",
|
||||
},
|
||||
"instance_id": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: "The ID of the instance.",
|
||||
MarkdownDescription: "The ID of the instance.",
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: "The name of the database.",
|
||||
MarkdownDescription: "The name of the database.",
|
||||
},
|
||||
"owner": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: "The owner of the database.",
|
||||
MarkdownDescription: "The owner of the database.",
|
||||
},
|
||||
"project_id": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: "The STACKIT project ID.",
|
||||
MarkdownDescription: "The STACKIT project ID.",
|
||||
},
|
||||
"region": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: "The region which should be addressed",
|
||||
MarkdownDescription: "The region which should be addressed",
|
||||
Validators: []validator.String{
|
||||
stringvalidator.OneOf(
|
||||
"eu01",
|
||||
),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type DatabaseModel struct {
|
||||
CollationName types.String `tfsdk:"collation_name"`
|
||||
CompatibilityLevel types.Int64 `tfsdk:"compatibility_level"`
|
||||
DatabaseName types.String `tfsdk:"database_name"`
|
||||
Id types.Int64 `tfsdk:"tf_original_api_id"`
|
||||
InstanceId types.String `tfsdk:"instance_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Owner types.String `tfsdk:"owner"`
|
||||
ProjectId types.String `tfsdk:"project_id"`
|
||||
Region types.String `tfsdk:"region"`
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,99 +0,0 @@
|
|||
// Code generated by terraform-plugin-framework-generator DO NOT EDIT.
|
||||
|
||||
package sqlserverflexbeta
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
|
||||
)
|
||||
|
||||
func DatabaseResourceSchema(ctx context.Context) schema.Schema {
|
||||
return schema.Schema{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"collation": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "The collation of the database. This database collation should match the *collation_name* of one of the collations given by the **Get database collation list** endpoint.",
|
||||
MarkdownDescription: "The collation of the database. This database collation should match the *collation_name* of one of the collations given by the **Get database collation list** endpoint.",
|
||||
},
|
||||
"collation_name": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: "The collation of the database. This database collation should match the *collation_name* of one of the collations given by the **Get database collation list** endpoint.",
|
||||
MarkdownDescription: "The collation of the database. This database collation should match the *collation_name* of one of the collations given by the **Get database collation list** endpoint.",
|
||||
},
|
||||
"compatibility": schema.Int64Attribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "CompatibilityLevel of the Database.",
|
||||
MarkdownDescription: "CompatibilityLevel of the Database.",
|
||||
},
|
||||
"compatibility_level": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
Description: "CompatibilityLevel of the Database.",
|
||||
MarkdownDescription: "CompatibilityLevel of the Database.",
|
||||
},
|
||||
"database_name": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "The name of the database.",
|
||||
MarkdownDescription: "The name of the database.",
|
||||
},
|
||||
"id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
Description: "The id of the database.",
|
||||
MarkdownDescription: "The id of the database.",
|
||||
},
|
||||
"instance_id": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "The ID of the instance.",
|
||||
MarkdownDescription: "The ID of the instance.",
|
||||
},
|
||||
"name": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: "The name of the database.",
|
||||
MarkdownDescription: "The name of the database.",
|
||||
},
|
||||
"owner": schema.StringAttribute{
|
||||
Required: true,
|
||||
Description: "The owner of the database.",
|
||||
MarkdownDescription: "The owner of the database.",
|
||||
},
|
||||
"project_id": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "The STACKIT project ID.",
|
||||
MarkdownDescription: "The STACKIT project ID.",
|
||||
},
|
||||
"region": schema.StringAttribute{
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
Description: "The region which should be addressed",
|
||||
MarkdownDescription: "The region which should be addressed",
|
||||
Validators: []validator.String{
|
||||
stringvalidator.OneOf(
|
||||
"eu01",
|
||||
),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type DatabaseModel struct {
|
||||
Collation types.String `tfsdk:"collation"`
|
||||
CollationName types.String `tfsdk:"collation_name"`
|
||||
Compatibility types.Int64 `tfsdk:"compatibility"`
|
||||
CompatibilityLevel types.Int64 `tfsdk:"compatibility_level"`
|
||||
DatabaseName types.String `tfsdk:"database_name"`
|
||||
Id types.Int64 `tfsdk:"id"`
|
||||
InstanceId types.String `tfsdk:"instance_id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Owner types.String `tfsdk:"owner"`
|
||||
ProjectId types.String `tfsdk:"project_id"`
|
||||
Region types.String `tfsdk:"region"`
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ func InstanceDataSourceSchema(ctx context.Context) schema.Schema {
|
|||
Description: "The id of the instance flavor.",
|
||||
MarkdownDescription: "The id of the instance flavor.",
|
||||
},
|
||||
"id": schema.StringAttribute{
|
||||
"tf_original_api_id": schema.StringAttribute{
|
||||
Computed: true,
|
||||
Description: "The ID of the instance.",
|
||||
MarkdownDescription: "The ID of the instance.",
|
||||
|
|
@ -178,7 +178,7 @@ type InstanceModel struct {
|
|||
Edition types.String `tfsdk:"edition"`
|
||||
Encryption EncryptionValue `tfsdk:"encryption"`
|
||||
FlavorId types.String `tfsdk:"flavor_id"`
|
||||
Id types.String `tfsdk:"id"`
|
||||
Id types.String `tfsdk:"tf_original_api_id"`
|
||||
InstanceId types.String `tfsdk:"instance_id"`
|
||||
IsDeletable types.Bool `tfsdk:"is_deletable"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
||||
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
|
||||
"github.com/hashicorp/terraform-plugin-testing/plancheck"
|
||||
"github.com/hashicorp/terraform-plugin-testing/statecheck"
|
||||
"github.com/hashicorp/terraform-plugin-testing/terraform"
|
||||
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
|
||||
|
|
@ -160,6 +161,12 @@ func TestAccResourceExample_basic(t *testing.T) {
|
|||
// test create
|
||||
{
|
||||
Config: exBefore,
|
||||
ConfigPlanChecks: resource.ConfigPlanChecks{
|
||||
PreApply: []plancheck.PlanCheck{
|
||||
plancheck.ExpectResourceAction(resName, plancheck.ResourceActionCreate),
|
||||
plancheck.ExpectNonEmptyPlan(),
|
||||
},
|
||||
},
|
||||
ConfigStateChecks: []statecheck.StateCheck{
|
||||
compareValuesSame.AddStateValue(
|
||||
resName,
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ func UserDataSourceSchema(ctx context.Context) schema.Schema {
|
|||
"users": schema.ListNestedAttribute{
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"id": schema.Int64Attribute{
|
||||
"tf_original_api_id": schema.Int64Attribute{
|
||||
Computed: true,
|
||||
Description: "The ID of the user.",
|
||||
MarkdownDescription: "The ID of the user.",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue