From 0ce380439384793655bc25ff3fcceca52819387e Mon Sep 17 00:00:00 2001 From: "Marcel S. Henselin" Date: Tue, 10 Feb 2026 10:51:28 +0100 Subject: [PATCH] chore: remove generated files from repo --- .gitignore | 2 + .../database_data_source_gen.go | 69 - .../databases_data_source_gen.go | 1180 ---------- .../resources_gen/database_resource_gen.go | 74 - .../flavors_data_source_gen.go | 1909 ---------------- .../flavors_data_source_gen.go | 1909 ---------------- .../instance_data_source_gen.go | 1984 ---------------- .../instances_data_source_gen.go | 1174 ---------- .../resources_gen/instance_resource_gen.go | 2004 ----------------- .../datasources_gen/roles_data_source_gen.go | 52 - .../datasources_gen/user_data_source_gen.go | 76 - .../datasources_gen/users_data_source_gen.go | 1118 --------- .../user/resources_gen/user_resource_gen.go | 93 - .../versions_data_source_gen.go | 569 ----- .../database_data_source_gen.go | 81 - .../databases_data_source_gen.go | 1180 ---------- .../resources_gen/database_resource_gen.go | 99 - .../datasources_gen/flavor_data_source_gen.go | 1909 ---------------- .../flavors_data_source_gen.go | 1909 ---------------- .../instance_data_source_gen.go | 1579 ------------- .../instances_data_source_gen.go | 1172 ---------- .../resources_gen/instance_resource_gen.go | 1597 ------------- .../datasources_gen/user_data_source_gen.go | 1118 --------- .../user/resources_gen/user_resource_gen.go | 111 - .../database_data_source_gen.go | 81 - .../databases_data_source_gen.go | 1180 ---------- .../resources_gen/database_resource_gen.go | 99 - .../datasources_gen/flavor_data_source_gen.go | 1909 ---------------- .../flavors_data_source_gen.go | 1909 ---------------- .../instance_data_source_gen.go | 1579 ------------- .../instances_data_source_gen.go | 1172 ---------- .../resources_gen/instance_resource_gen.go | 1597 ------------- .../datasources_gen/user_data_source_gen.go | 1118 --------- .../user/resources_gen/user_resource_gen.go | 111 - .../version_data_source_gen.go | 569 ----- 35 files changed, 2 insertions(+), 34290 deletions(-) delete mode 100644 stackit/internal/services/postgresflexalpha/database/datasources_gen/database_data_source_gen.go delete mode 100644 stackit/internal/services/postgresflexalpha/database/datasources_gen/databases_data_source_gen.go delete mode 100644 stackit/internal/services/postgresflexalpha/database/resources_gen/database_resource_gen.go delete mode 100644 stackit/internal/services/postgresflexalpha/flavor/datasources_gen/flavors_data_source_gen.go delete mode 100644 stackit/internal/services/postgresflexalpha/flavors/datasources_gen/flavors_data_source_gen.go delete mode 100644 stackit/internal/services/postgresflexalpha/instance/datasources_gen/instance_data_source_gen.go delete mode 100644 stackit/internal/services/postgresflexalpha/instance/datasources_gen/instances_data_source_gen.go delete mode 100644 stackit/internal/services/postgresflexalpha/instance/resources_gen/instance_resource_gen.go delete mode 100644 stackit/internal/services/postgresflexalpha/role/datasources_gen/roles_data_source_gen.go delete mode 100644 stackit/internal/services/postgresflexalpha/user/datasources_gen/user_data_source_gen.go delete mode 100644 stackit/internal/services/postgresflexalpha/user/datasources_gen/users_data_source_gen.go delete mode 100644 stackit/internal/services/postgresflexalpha/user/resources_gen/user_resource_gen.go delete mode 100644 stackit/internal/services/postgresflexalpha/version/datasources_gen/versions_data_source_gen.go delete mode 100644 stackit/internal/services/sqlserverflexalpha/database/datasources_gen/database_data_source_gen.go delete mode 100644 stackit/internal/services/sqlserverflexalpha/database/datasources_gen/databases_data_source_gen.go delete mode 100644 stackit/internal/services/sqlserverflexalpha/database/resources_gen/database_resource_gen.go delete mode 100644 stackit/internal/services/sqlserverflexalpha/flavor/datasources_gen/flavor_data_source_gen.go delete mode 100644 stackit/internal/services/sqlserverflexalpha/flavors/datasources_gen/flavors_data_source_gen.go delete mode 100644 stackit/internal/services/sqlserverflexalpha/instance/datasources_gen/instance_data_source_gen.go delete mode 100644 stackit/internal/services/sqlserverflexalpha/instance/datasources_gen/instances_data_source_gen.go delete mode 100644 stackit/internal/services/sqlserverflexalpha/instance/resources_gen/instance_resource_gen.go delete mode 100644 stackit/internal/services/sqlserverflexalpha/user/datasources_gen/user_data_source_gen.go delete mode 100644 stackit/internal/services/sqlserverflexalpha/user/resources_gen/user_resource_gen.go delete mode 100644 stackit/internal/services/sqlserverflexbeta/database/datasources_gen/database_data_source_gen.go delete mode 100644 stackit/internal/services/sqlserverflexbeta/database/datasources_gen/databases_data_source_gen.go delete mode 100644 stackit/internal/services/sqlserverflexbeta/database/resources_gen/database_resource_gen.go delete mode 100644 stackit/internal/services/sqlserverflexbeta/flavor/datasources_gen/flavor_data_source_gen.go delete mode 100644 stackit/internal/services/sqlserverflexbeta/flavors/datasources_gen/flavors_data_source_gen.go delete mode 100644 stackit/internal/services/sqlserverflexbeta/instance/datasources_gen/instance_data_source_gen.go delete mode 100644 stackit/internal/services/sqlserverflexbeta/instance/datasources_gen/instances_data_source_gen.go delete mode 100644 stackit/internal/services/sqlserverflexbeta/instance/resources_gen/instance_resource_gen.go delete mode 100644 stackit/internal/services/sqlserverflexbeta/user/datasources_gen/user_data_source_gen.go delete mode 100644 stackit/internal/services/sqlserverflexbeta/user/resources_gen/user_resource_gen.go delete mode 100644 stackit/internal/services/sqlserverflexbeta/versions/datasources_gen/version_data_source_gen.go diff --git a/.gitignore b/.gitignore index c588a0f1..436f4f2c 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,5 @@ dist pkg_gen /release/ +**/datasources_gen** +**/resources_gen** diff --git a/stackit/internal/services/postgresflexalpha/database/datasources_gen/database_data_source_gen.go b/stackit/internal/services/postgresflexalpha/database/datasources_gen/database_data_source_gen.go deleted file mode 100644 index d5683a6c..00000000 --- a/stackit/internal/services/postgresflexalpha/database/datasources_gen/database_data_source_gen.go +++ /dev/null @@ -1,69 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -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/datasource/schema" -) - -func DatabaseDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "database_id": schema.Int64Attribute{ - Required: true, - Description: "The ID of the database.", - MarkdownDescription: "The ID 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 { - DatabaseId types.Int64 `tfsdk:"database_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"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` -} diff --git a/stackit/internal/services/postgresflexalpha/database/datasources_gen/databases_data_source_gen.go b/stackit/internal/services/postgresflexalpha/database/datasources_gen/databases_data_source_gen.go deleted file mode 100644 index 7e3e1eec..00000000 --- a/stackit/internal/services/postgresflexalpha/database/datasources_gen/databases_data_source_gen.go +++ /dev/null @@ -1,1180 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package postgresflexalpha - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -func DatabasesDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "databases": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "created": schema.StringAttribute{ - Computed: true, - Description: "The data when the database was created in RFC3339 format.", - MarkdownDescription: "The data when the database was created in RFC3339 format.", - }, - "id": schema.Int64Attribute{ - Computed: true, - Description: "The id of the database.", - MarkdownDescription: "The id of the database.", - }, - "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.", - }, - }, - CustomType: DatabasesType{ - ObjectType: types.ObjectType{ - AttrTypes: DatabasesValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "A list containing all databases for the instance.", - MarkdownDescription: "A list containing all databases for the instance.", - }, - "instance_id": schema.StringAttribute{ - Required: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "page": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of the page of items list to be returned.", - MarkdownDescription: "Number of the page of items list to be returned.", - }, - "pagination": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "page": schema.Int64Attribute{ - Computed: true, - }, - "size": schema.Int64Attribute{ - Computed: true, - }, - "sort": schema.StringAttribute{ - Computed: true, - }, - "total_pages": schema.Int64Attribute{ - Computed: true, - }, - "total_rows": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: PaginationType{ - ObjectType: types.ObjectType{ - AttrTypes: PaginationValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - }, - "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", - ), - }, - }, - "size": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of items to be returned on each page.", - MarkdownDescription: "Number of items to be returned on each page.", - }, - "sort": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "Sorting of the databases to be returned on each page.", - MarkdownDescription: "Sorting of the databases to be returned on each page.", - Validators: []validator.String{ - stringvalidator.OneOf( - "created_at.desc", - "created_at.asc", - "database_id.desc", - "database_id.asc", - "database_name.desc", - "database_name.asc", - "database_owner.desc", - "database_owner.asc", - "index.asc", - "index.desc", - ), - }, - }, - }, - } -} - -type DatabasesModel struct { - Databases types.List `tfsdk:"databases"` - InstanceId types.String `tfsdk:"instance_id"` - Page types.Int64 `tfsdk:"page"` - Pagination PaginationValue `tfsdk:"pagination"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Size types.Int64 `tfsdk:"size"` - Sort types.String `tfsdk:"sort"` -} - -var _ basetypes.ObjectTypable = DatabasesType{} - -type DatabasesType struct { - basetypes.ObjectType -} - -func (t DatabasesType) Equal(o attr.Type) bool { - other, ok := o.(DatabasesType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t DatabasesType) String() string { - return "DatabasesType" -} - -func (t DatabasesType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - createdAttribute, ok := attributes["created"] - - if !ok { - diags.AddError( - "Attribute Missing", - `created is missing from object`) - - return nil, diags - } - - createdVal, ok := createdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`created expected to be basetypes.StringValue, was: %T`, createdAttribute)) - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return nil, diags - } - - idVal, ok := idAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.Int64Value, was: %T`, idAttribute)) - } - - nameAttribute, ok := attributes["name"] - - if !ok { - diags.AddError( - "Attribute Missing", - `name is missing from object`) - - return nil, diags - } - - nameVal, ok := nameAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`name expected to be basetypes.StringValue, was: %T`, nameAttribute)) - } - - ownerAttribute, ok := attributes["owner"] - - if !ok { - diags.AddError( - "Attribute Missing", - `owner is missing from object`) - - return nil, diags - } - - ownerVal, ok := ownerAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`owner expected to be basetypes.StringValue, was: %T`, ownerAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return DatabasesValue{ - Created: createdVal, - Id: idVal, - Name: nameVal, - Owner: ownerVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewDatabasesValueNull() DatabasesValue { - return DatabasesValue{ - state: attr.ValueStateNull, - } -} - -func NewDatabasesValueUnknown() DatabasesValue { - return DatabasesValue{ - state: attr.ValueStateUnknown, - } -} - -func NewDatabasesValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (DatabasesValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing DatabasesValue Attribute Value", - "While creating a DatabasesValue value, a missing attribute value was detected. "+ - "A DatabasesValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("DatabasesValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid DatabasesValue Attribute Type", - "While creating a DatabasesValue value, an invalid attribute value was detected. "+ - "A DatabasesValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("DatabasesValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("DatabasesValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra DatabasesValue Attribute Value", - "While creating a DatabasesValue value, an extra attribute value was detected. "+ - "A DatabasesValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra DatabasesValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewDatabasesValueUnknown(), diags - } - - createdAttribute, ok := attributes["created"] - - if !ok { - diags.AddError( - "Attribute Missing", - `created is missing from object`) - - return NewDatabasesValueUnknown(), diags - } - - createdVal, ok := createdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`created expected to be basetypes.StringValue, was: %T`, createdAttribute)) - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return NewDatabasesValueUnknown(), diags - } - - idVal, ok := idAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.Int64Value, was: %T`, idAttribute)) - } - - nameAttribute, ok := attributes["name"] - - if !ok { - diags.AddError( - "Attribute Missing", - `name is missing from object`) - - return NewDatabasesValueUnknown(), diags - } - - nameVal, ok := nameAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`name expected to be basetypes.StringValue, was: %T`, nameAttribute)) - } - - ownerAttribute, ok := attributes["owner"] - - if !ok { - diags.AddError( - "Attribute Missing", - `owner is missing from object`) - - return NewDatabasesValueUnknown(), diags - } - - ownerVal, ok := ownerAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`owner expected to be basetypes.StringValue, was: %T`, ownerAttribute)) - } - - if diags.HasError() { - return NewDatabasesValueUnknown(), diags - } - - return DatabasesValue{ - Created: createdVal, - Id: idVal, - Name: nameVal, - Owner: ownerVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewDatabasesValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) DatabasesValue { - object, diags := NewDatabasesValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewDatabasesValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t DatabasesType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewDatabasesValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewDatabasesValueUnknown(), nil - } - - if in.IsNull() { - return NewDatabasesValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewDatabasesValueMust(DatabasesValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t DatabasesType) ValueType(ctx context.Context) attr.Value { - return DatabasesValue{} -} - -var _ basetypes.ObjectValuable = DatabasesValue{} - -type DatabasesValue struct { - Created basetypes.StringValue `tfsdk:"created"` - Id basetypes.Int64Value `tfsdk:"id"` - Name basetypes.StringValue `tfsdk:"name"` - Owner basetypes.StringValue `tfsdk:"owner"` - state attr.ValueState -} - -func (v DatabasesValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 4) - - var val tftypes.Value - var err error - - attrTypes["created"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["id"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["name"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["owner"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 4) - - val, err = v.Created.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["created"] = val - - val, err = v.Id.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["id"] = val - - val, err = v.Name.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["name"] = val - - val, err = v.Owner.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["owner"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v DatabasesValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v DatabasesValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v DatabasesValue) String() string { - return "DatabasesValue" -} - -func (v DatabasesValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "created": basetypes.StringType{}, - "id": basetypes.Int64Type{}, - "name": basetypes.StringType{}, - "owner": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "created": v.Created, - "id": v.Id, - "name": v.Name, - "owner": v.Owner, - }) - - return objVal, diags -} - -func (v DatabasesValue) Equal(o attr.Value) bool { - other, ok := o.(DatabasesValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Created.Equal(other.Created) { - return false - } - - if !v.Id.Equal(other.Id) { - return false - } - - if !v.Name.Equal(other.Name) { - return false - } - - if !v.Owner.Equal(other.Owner) { - return false - } - - return true -} - -func (v DatabasesValue) Type(ctx context.Context) attr.Type { - return DatabasesType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v DatabasesValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "created": basetypes.StringType{}, - "id": basetypes.Int64Type{}, - "name": basetypes.StringType{}, - "owner": basetypes.StringType{}, - } -} - -var _ basetypes.ObjectTypable = PaginationType{} - -type PaginationType struct { - basetypes.ObjectType -} - -func (t PaginationType) Equal(o attr.Type) bool { - other, ok := o.(PaginationType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t PaginationType) String() string { - return "PaginationType" -} - -func (t PaginationType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return nil, diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return nil, diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return nil, diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return nil, diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueNull() PaginationValue { - return PaginationValue{ - state: attr.ValueStateNull, - } -} - -func NewPaginationValueUnknown() PaginationValue { - return PaginationValue{ - state: attr.ValueStateUnknown, - } -} - -func NewPaginationValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (PaginationValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing PaginationValue Attribute Value", - "While creating a PaginationValue value, a missing attribute value was detected. "+ - "A PaginationValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid PaginationValue Attribute Type", - "While creating a PaginationValue value, an invalid attribute value was detected. "+ - "A PaginationValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra PaginationValue Attribute Value", - "While creating a PaginationValue value, an extra attribute value was detected. "+ - "A PaginationValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra PaginationValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) PaginationValue { - object, diags := NewPaginationValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewPaginationValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t PaginationType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewPaginationValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewPaginationValueUnknown(), nil - } - - if in.IsNull() { - return NewPaginationValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewPaginationValueMust(PaginationValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t PaginationType) ValueType(ctx context.Context) attr.Value { - return PaginationValue{} -} - -var _ basetypes.ObjectValuable = PaginationValue{} - -type PaginationValue struct { - Page basetypes.Int64Value `tfsdk:"page"` - Size basetypes.Int64Value `tfsdk:"size"` - Sort basetypes.StringValue `tfsdk:"sort"` - TotalPages basetypes.Int64Value `tfsdk:"total_pages"` - TotalRows basetypes.Int64Value `tfsdk:"total_rows"` - state attr.ValueState -} - -func (v PaginationValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 5) - - var val tftypes.Value - var err error - - attrTypes["page"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["sort"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["total_pages"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["total_rows"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 5) - - val, err = v.Page.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["page"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - val, err = v.Sort.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["sort"] = val - - val, err = v.TotalPages.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_pages"] = val - - val, err = v.TotalRows.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_rows"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v PaginationValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v PaginationValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v PaginationValue) String() string { - return "PaginationValue" -} - -func (v PaginationValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "page": v.Page, - "size": v.Size, - "sort": v.Sort, - "total_pages": v.TotalPages, - "total_rows": v.TotalRows, - }) - - return objVal, diags -} - -func (v PaginationValue) Equal(o attr.Value) bool { - other, ok := o.(PaginationValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Page.Equal(other.Page) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - if !v.Sort.Equal(other.Sort) { - return false - } - - if !v.TotalPages.Equal(other.TotalPages) { - return false - } - - if !v.TotalRows.Equal(other.TotalRows) { - return false - } - - return true -} - -func (v PaginationValue) Type(ctx context.Context) attr.Type { - return PaginationType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v PaginationValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } -} diff --git a/stackit/internal/services/postgresflexalpha/database/resources_gen/database_resource_gen.go b/stackit/internal/services/postgresflexalpha/database/resources_gen/database_resource_gen.go deleted file mode 100644 index 6affc956..00000000 --- a/stackit/internal/services/postgresflexalpha/database/resources_gen/database_resource_gen.go +++ /dev/null @@ -1,74 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -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" -) - -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.", - MarkdownDescription: "The name of the database.", - }, - "owner": schema.StringAttribute{ - Optional: true, - Computed: 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 { - 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"` -} diff --git a/stackit/internal/services/postgresflexalpha/flavor/datasources_gen/flavors_data_source_gen.go b/stackit/internal/services/postgresflexalpha/flavor/datasources_gen/flavors_data_source_gen.go deleted file mode 100644 index 924d1375..00000000 --- a/stackit/internal/services/postgresflexalpha/flavor/datasources_gen/flavors_data_source_gen.go +++ /dev/null @@ -1,1909 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package postgresflexalpha - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -func FlavorsDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "flavors": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "cpu": schema.Int64Attribute{ - Computed: true, - Description: "The cpu count of the instance.", - MarkdownDescription: "The cpu count of the instance.", - }, - "description": schema.StringAttribute{ - Computed: true, - Description: "The flavor description.", - MarkdownDescription: "The flavor description.", - }, - "id": schema.StringAttribute{ - Computed: true, - Description: "The id of the instance flavor.", - MarkdownDescription: "The id of the instance flavor.", - }, - "max_gb": schema.Int64Attribute{ - Computed: true, - Description: "maximum storage which can be ordered for the flavor in Gigabyte.", - MarkdownDescription: "maximum storage which can be ordered for the flavor in Gigabyte.", - }, - "memory": schema.Int64Attribute{ - Computed: true, - Description: "The memory of the instance in Gibibyte.", - MarkdownDescription: "The memory of the instance in Gibibyte.", - }, - "min_gb": schema.Int64Attribute{ - Computed: true, - Description: "minimum storage which is required to order in Gigabyte.", - MarkdownDescription: "minimum storage which is required to order in Gigabyte.", - }, - "node_type": schema.StringAttribute{ - Computed: true, - Description: "defines the nodeType it can be either single or replica", - MarkdownDescription: "defines the nodeType it can be either single or replica", - }, - "storage_classes": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "class": schema.StringAttribute{ - Computed: true, - }, - "max_io_per_sec": schema.Int64Attribute{ - Computed: true, - }, - "max_through_in_mb": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: StorageClassesType{ - ObjectType: types.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "maximum storage which can be ordered for the flavor in Gigabyte.", - MarkdownDescription: "maximum storage which can be ordered for the flavor in Gigabyte.", - }, - }, - CustomType: FlavorsType{ - ObjectType: types.ObjectType{ - AttrTypes: FlavorsValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "List of flavors available for the project.", - MarkdownDescription: "List of flavors available for the project.", - }, - "page": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of the page of items list to be returned.", - MarkdownDescription: "Number of the page of items list to be returned.", - }, - "pagination": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "page": schema.Int64Attribute{ - Computed: true, - }, - "size": schema.Int64Attribute{ - Computed: true, - }, - "sort": schema.StringAttribute{ - Computed: true, - }, - "total_pages": schema.Int64Attribute{ - Computed: true, - }, - "total_rows": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: PaginationType{ - ObjectType: types.ObjectType{ - AttrTypes: PaginationValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - }, - "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", - ), - }, - }, - "size": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of items to be returned on each page.", - MarkdownDescription: "Number of items to be returned on each page.", - }, - "sort": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "Sorting of the flavors to be returned on each page.", - MarkdownDescription: "Sorting of the flavors to be returned on each page.", - Validators: []validator.String{ - stringvalidator.OneOf( - "index.desc", - "index.asc", - "cpu.desc", - "cpu.asc", - "flavor_description.asc", - "flavor_description.desc", - "id.desc", - "id.asc", - "size_max.desc", - "size_max.asc", - "ram.desc", - "ram.asc", - "size_min.desc", - "size_min.asc", - "storage_class.asc", - "storage_class.desc", - "node_type.asc", - "node_type.desc", - ), - }, - }, - }, - } -} - -type FlavorsModel struct { - Flavors types.List `tfsdk:"flavors"` - Page types.Int64 `tfsdk:"page"` - Pagination PaginationValue `tfsdk:"pagination"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Size types.Int64 `tfsdk:"size"` - Sort types.String `tfsdk:"sort"` -} - -var _ basetypes.ObjectTypable = FlavorsType{} - -type FlavorsType struct { - basetypes.ObjectType -} - -func (t FlavorsType) Equal(o attr.Type) bool { - other, ok := o.(FlavorsType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t FlavorsType) String() string { - return "FlavorsType" -} - -func (t FlavorsType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - cpuAttribute, ok := attributes["cpu"] - - if !ok { - diags.AddError( - "Attribute Missing", - `cpu is missing from object`) - - return nil, diags - } - - cpuVal, ok := cpuAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`cpu expected to be basetypes.Int64Value, was: %T`, cpuAttribute)) - } - - descriptionAttribute, ok := attributes["description"] - - if !ok { - diags.AddError( - "Attribute Missing", - `description is missing from object`) - - return nil, diags - } - - descriptionVal, ok := descriptionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`description expected to be basetypes.StringValue, was: %T`, descriptionAttribute)) - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return nil, diags - } - - idVal, ok := idAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.StringValue, was: %T`, idAttribute)) - } - - maxGbAttribute, ok := attributes["max_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_gb is missing from object`) - - return nil, diags - } - - maxGbVal, ok := maxGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_gb expected to be basetypes.Int64Value, was: %T`, maxGbAttribute)) - } - - memoryAttribute, ok := attributes["memory"] - - if !ok { - diags.AddError( - "Attribute Missing", - `memory is missing from object`) - - return nil, diags - } - - memoryVal, ok := memoryAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`memory expected to be basetypes.Int64Value, was: %T`, memoryAttribute)) - } - - minGbAttribute, ok := attributes["min_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `min_gb is missing from object`) - - return nil, diags - } - - minGbVal, ok := minGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`min_gb expected to be basetypes.Int64Value, was: %T`, minGbAttribute)) - } - - nodeTypeAttribute, ok := attributes["node_type"] - - if !ok { - diags.AddError( - "Attribute Missing", - `node_type is missing from object`) - - return nil, diags - } - - nodeTypeVal, ok := nodeTypeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`node_type expected to be basetypes.StringValue, was: %T`, nodeTypeAttribute)) - } - - storageClassesAttribute, ok := attributes["storage_classes"] - - if !ok { - diags.AddError( - "Attribute Missing", - `storage_classes is missing from object`) - - return nil, diags - } - - storageClassesVal, ok := storageClassesAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`storage_classes expected to be basetypes.ListValue, was: %T`, storageClassesAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return FlavorsValue{ - Cpu: cpuVal, - Description: descriptionVal, - Id: idVal, - MaxGb: maxGbVal, - Memory: memoryVal, - MinGb: minGbVal, - NodeType: nodeTypeVal, - StorageClasses: storageClassesVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewFlavorsValueNull() FlavorsValue { - return FlavorsValue{ - state: attr.ValueStateNull, - } -} - -func NewFlavorsValueUnknown() FlavorsValue { - return FlavorsValue{ - state: attr.ValueStateUnknown, - } -} - -func NewFlavorsValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (FlavorsValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing FlavorsValue Attribute Value", - "While creating a FlavorsValue value, a missing attribute value was detected. "+ - "A FlavorsValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("FlavorsValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid FlavorsValue Attribute Type", - "While creating a FlavorsValue value, an invalid attribute value was detected. "+ - "A FlavorsValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("FlavorsValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("FlavorsValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra FlavorsValue Attribute Value", - "While creating a FlavorsValue value, an extra attribute value was detected. "+ - "A FlavorsValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra FlavorsValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewFlavorsValueUnknown(), diags - } - - cpuAttribute, ok := attributes["cpu"] - - if !ok { - diags.AddError( - "Attribute Missing", - `cpu is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - cpuVal, ok := cpuAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`cpu expected to be basetypes.Int64Value, was: %T`, cpuAttribute)) - } - - descriptionAttribute, ok := attributes["description"] - - if !ok { - diags.AddError( - "Attribute Missing", - `description is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - descriptionVal, ok := descriptionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`description expected to be basetypes.StringValue, was: %T`, descriptionAttribute)) - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - idVal, ok := idAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.StringValue, was: %T`, idAttribute)) - } - - maxGbAttribute, ok := attributes["max_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_gb is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - maxGbVal, ok := maxGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_gb expected to be basetypes.Int64Value, was: %T`, maxGbAttribute)) - } - - memoryAttribute, ok := attributes["memory"] - - if !ok { - diags.AddError( - "Attribute Missing", - `memory is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - memoryVal, ok := memoryAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`memory expected to be basetypes.Int64Value, was: %T`, memoryAttribute)) - } - - minGbAttribute, ok := attributes["min_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `min_gb is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - minGbVal, ok := minGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`min_gb expected to be basetypes.Int64Value, was: %T`, minGbAttribute)) - } - - nodeTypeAttribute, ok := attributes["node_type"] - - if !ok { - diags.AddError( - "Attribute Missing", - `node_type is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - nodeTypeVal, ok := nodeTypeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`node_type expected to be basetypes.StringValue, was: %T`, nodeTypeAttribute)) - } - - storageClassesAttribute, ok := attributes["storage_classes"] - - if !ok { - diags.AddError( - "Attribute Missing", - `storage_classes is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - storageClassesVal, ok := storageClassesAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`storage_classes expected to be basetypes.ListValue, was: %T`, storageClassesAttribute)) - } - - if diags.HasError() { - return NewFlavorsValueUnknown(), diags - } - - return FlavorsValue{ - Cpu: cpuVal, - Description: descriptionVal, - Id: idVal, - MaxGb: maxGbVal, - Memory: memoryVal, - MinGb: minGbVal, - NodeType: nodeTypeVal, - StorageClasses: storageClassesVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewFlavorsValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) FlavorsValue { - object, diags := NewFlavorsValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewFlavorsValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t FlavorsType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewFlavorsValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewFlavorsValueUnknown(), nil - } - - if in.IsNull() { - return NewFlavorsValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewFlavorsValueMust(FlavorsValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t FlavorsType) ValueType(ctx context.Context) attr.Value { - return FlavorsValue{} -} - -var _ basetypes.ObjectValuable = FlavorsValue{} - -type FlavorsValue struct { - Cpu basetypes.Int64Value `tfsdk:"cpu"` - Description basetypes.StringValue `tfsdk:"description"` - Id basetypes.StringValue `tfsdk:"id"` - MaxGb basetypes.Int64Value `tfsdk:"max_gb"` - Memory basetypes.Int64Value `tfsdk:"memory"` - MinGb basetypes.Int64Value `tfsdk:"min_gb"` - NodeType basetypes.StringValue `tfsdk:"node_type"` - StorageClasses basetypes.ListValue `tfsdk:"storage_classes"` - state attr.ValueState -} - -func (v FlavorsValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 8) - - var val tftypes.Value - var err error - - attrTypes["cpu"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["description"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["max_gb"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["memory"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["min_gb"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["node_type"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["storage_classes"] = basetypes.ListType{ - ElemType: StorageClassesValue{}.Type(ctx), - }.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 8) - - val, err = v.Cpu.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["cpu"] = val - - val, err = v.Description.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["description"] = val - - val, err = v.Id.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["id"] = val - - val, err = v.MaxGb.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["max_gb"] = val - - val, err = v.Memory.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["memory"] = val - - val, err = v.MinGb.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["min_gb"] = val - - val, err = v.NodeType.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["node_type"] = val - - val, err = v.StorageClasses.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["storage_classes"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v FlavorsValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v FlavorsValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v FlavorsValue) String() string { - return "FlavorsValue" -} - -func (v FlavorsValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - storageClasses := types.ListValueMust( - StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - v.StorageClasses.Elements(), - ) - - if v.StorageClasses.IsNull() { - storageClasses = types.ListNull( - StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - ) - } - - if v.StorageClasses.IsUnknown() { - storageClasses = types.ListUnknown( - StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - ) - } - - attributeTypes := map[string]attr.Type{ - "cpu": basetypes.Int64Type{}, - "description": basetypes.StringType{}, - "id": basetypes.StringType{}, - "max_gb": basetypes.Int64Type{}, - "memory": basetypes.Int64Type{}, - "min_gb": basetypes.Int64Type{}, - "node_type": basetypes.StringType{}, - "storage_classes": basetypes.ListType{ - ElemType: StorageClassesValue{}.Type(ctx), - }, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "cpu": v.Cpu, - "description": v.Description, - "id": v.Id, - "max_gb": v.MaxGb, - "memory": v.Memory, - "min_gb": v.MinGb, - "node_type": v.NodeType, - "storage_classes": storageClasses, - }) - - return objVal, diags -} - -func (v FlavorsValue) Equal(o attr.Value) bool { - other, ok := o.(FlavorsValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Cpu.Equal(other.Cpu) { - return false - } - - if !v.Description.Equal(other.Description) { - return false - } - - if !v.Id.Equal(other.Id) { - return false - } - - if !v.MaxGb.Equal(other.MaxGb) { - return false - } - - if !v.Memory.Equal(other.Memory) { - return false - } - - if !v.MinGb.Equal(other.MinGb) { - return false - } - - if !v.NodeType.Equal(other.NodeType) { - return false - } - - if !v.StorageClasses.Equal(other.StorageClasses) { - return false - } - - return true -} - -func (v FlavorsValue) Type(ctx context.Context) attr.Type { - return FlavorsType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v FlavorsValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "cpu": basetypes.Int64Type{}, - "description": basetypes.StringType{}, - "id": basetypes.StringType{}, - "max_gb": basetypes.Int64Type{}, - "memory": basetypes.Int64Type{}, - "min_gb": basetypes.Int64Type{}, - "node_type": basetypes.StringType{}, - "storage_classes": basetypes.ListType{ - ElemType: StorageClassesValue{}.Type(ctx), - }, - } -} - -var _ basetypes.ObjectTypable = StorageClassesType{} - -type StorageClassesType struct { - basetypes.ObjectType -} - -func (t StorageClassesType) Equal(o attr.Type) bool { - other, ok := o.(StorageClassesType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t StorageClassesType) String() string { - return "StorageClassesType" -} - -func (t StorageClassesType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - classAttribute, ok := attributes["class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `class is missing from object`) - - return nil, diags - } - - classVal, ok := classAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`class expected to be basetypes.StringValue, was: %T`, classAttribute)) - } - - maxIoPerSecAttribute, ok := attributes["max_io_per_sec"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_io_per_sec is missing from object`) - - return nil, diags - } - - maxIoPerSecVal, ok := maxIoPerSecAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_io_per_sec expected to be basetypes.Int64Value, was: %T`, maxIoPerSecAttribute)) - } - - maxThroughInMbAttribute, ok := attributes["max_through_in_mb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_through_in_mb is missing from object`) - - return nil, diags - } - - maxThroughInMbVal, ok := maxThroughInMbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_through_in_mb expected to be basetypes.Int64Value, was: %T`, maxThroughInMbAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return StorageClassesValue{ - Class: classVal, - MaxIoPerSec: maxIoPerSecVal, - MaxThroughInMb: maxThroughInMbVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageClassesValueNull() StorageClassesValue { - return StorageClassesValue{ - state: attr.ValueStateNull, - } -} - -func NewStorageClassesValueUnknown() StorageClassesValue { - return StorageClassesValue{ - state: attr.ValueStateUnknown, - } -} - -func NewStorageClassesValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (StorageClassesValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing StorageClassesValue Attribute Value", - "While creating a StorageClassesValue value, a missing attribute value was detected. "+ - "A StorageClassesValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageClassesValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid StorageClassesValue Attribute Type", - "While creating a StorageClassesValue value, an invalid attribute value was detected. "+ - "A StorageClassesValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageClassesValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("StorageClassesValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra StorageClassesValue Attribute Value", - "While creating a StorageClassesValue value, an extra attribute value was detected. "+ - "A StorageClassesValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra StorageClassesValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewStorageClassesValueUnknown(), diags - } - - classAttribute, ok := attributes["class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `class is missing from object`) - - return NewStorageClassesValueUnknown(), diags - } - - classVal, ok := classAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`class expected to be basetypes.StringValue, was: %T`, classAttribute)) - } - - maxIoPerSecAttribute, ok := attributes["max_io_per_sec"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_io_per_sec is missing from object`) - - return NewStorageClassesValueUnknown(), diags - } - - maxIoPerSecVal, ok := maxIoPerSecAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_io_per_sec expected to be basetypes.Int64Value, was: %T`, maxIoPerSecAttribute)) - } - - maxThroughInMbAttribute, ok := attributes["max_through_in_mb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_through_in_mb is missing from object`) - - return NewStorageClassesValueUnknown(), diags - } - - maxThroughInMbVal, ok := maxThroughInMbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_through_in_mb expected to be basetypes.Int64Value, was: %T`, maxThroughInMbAttribute)) - } - - if diags.HasError() { - return NewStorageClassesValueUnknown(), diags - } - - return StorageClassesValue{ - Class: classVal, - MaxIoPerSec: maxIoPerSecVal, - MaxThroughInMb: maxThroughInMbVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageClassesValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) StorageClassesValue { - object, diags := NewStorageClassesValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewStorageClassesValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t StorageClassesType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewStorageClassesValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewStorageClassesValueUnknown(), nil - } - - if in.IsNull() { - return NewStorageClassesValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewStorageClassesValueMust(StorageClassesValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t StorageClassesType) ValueType(ctx context.Context) attr.Value { - return StorageClassesValue{} -} - -var _ basetypes.ObjectValuable = StorageClassesValue{} - -type StorageClassesValue struct { - Class basetypes.StringValue `tfsdk:"class"` - MaxIoPerSec basetypes.Int64Value `tfsdk:"max_io_per_sec"` - MaxThroughInMb basetypes.Int64Value `tfsdk:"max_through_in_mb"` - state attr.ValueState -} - -func (v StorageClassesValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 3) - - var val tftypes.Value - var err error - - attrTypes["class"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["max_io_per_sec"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["max_through_in_mb"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 3) - - val, err = v.Class.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["class"] = val - - val, err = v.MaxIoPerSec.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["max_io_per_sec"] = val - - val, err = v.MaxThroughInMb.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["max_through_in_mb"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v StorageClassesValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v StorageClassesValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v StorageClassesValue) String() string { - return "StorageClassesValue" -} - -func (v StorageClassesValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "class": basetypes.StringType{}, - "max_io_per_sec": basetypes.Int64Type{}, - "max_through_in_mb": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "class": v.Class, - "max_io_per_sec": v.MaxIoPerSec, - "max_through_in_mb": v.MaxThroughInMb, - }) - - return objVal, diags -} - -func (v StorageClassesValue) Equal(o attr.Value) bool { - other, ok := o.(StorageClassesValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Class.Equal(other.Class) { - return false - } - - if !v.MaxIoPerSec.Equal(other.MaxIoPerSec) { - return false - } - - if !v.MaxThroughInMb.Equal(other.MaxThroughInMb) { - return false - } - - return true -} - -func (v StorageClassesValue) Type(ctx context.Context) attr.Type { - return StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v StorageClassesValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "class": basetypes.StringType{}, - "max_io_per_sec": basetypes.Int64Type{}, - "max_through_in_mb": basetypes.Int64Type{}, - } -} - -var _ basetypes.ObjectTypable = PaginationType{} - -type PaginationType struct { - basetypes.ObjectType -} - -func (t PaginationType) Equal(o attr.Type) bool { - other, ok := o.(PaginationType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t PaginationType) String() string { - return "PaginationType" -} - -func (t PaginationType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return nil, diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return nil, diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return nil, diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return nil, diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueNull() PaginationValue { - return PaginationValue{ - state: attr.ValueStateNull, - } -} - -func NewPaginationValueUnknown() PaginationValue { - return PaginationValue{ - state: attr.ValueStateUnknown, - } -} - -func NewPaginationValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (PaginationValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing PaginationValue Attribute Value", - "While creating a PaginationValue value, a missing attribute value was detected. "+ - "A PaginationValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid PaginationValue Attribute Type", - "While creating a PaginationValue value, an invalid attribute value was detected. "+ - "A PaginationValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra PaginationValue Attribute Value", - "While creating a PaginationValue value, an extra attribute value was detected. "+ - "A PaginationValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra PaginationValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) PaginationValue { - object, diags := NewPaginationValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewPaginationValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t PaginationType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewPaginationValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewPaginationValueUnknown(), nil - } - - if in.IsNull() { - return NewPaginationValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewPaginationValueMust(PaginationValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t PaginationType) ValueType(ctx context.Context) attr.Value { - return PaginationValue{} -} - -var _ basetypes.ObjectValuable = PaginationValue{} - -type PaginationValue struct { - Page basetypes.Int64Value `tfsdk:"page"` - Size basetypes.Int64Value `tfsdk:"size"` - Sort basetypes.StringValue `tfsdk:"sort"` - TotalPages basetypes.Int64Value `tfsdk:"total_pages"` - TotalRows basetypes.Int64Value `tfsdk:"total_rows"` - state attr.ValueState -} - -func (v PaginationValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 5) - - var val tftypes.Value - var err error - - attrTypes["page"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["sort"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["total_pages"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["total_rows"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 5) - - val, err = v.Page.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["page"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - val, err = v.Sort.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["sort"] = val - - val, err = v.TotalPages.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_pages"] = val - - val, err = v.TotalRows.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_rows"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v PaginationValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v PaginationValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v PaginationValue) String() string { - return "PaginationValue" -} - -func (v PaginationValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "page": v.Page, - "size": v.Size, - "sort": v.Sort, - "total_pages": v.TotalPages, - "total_rows": v.TotalRows, - }) - - return objVal, diags -} - -func (v PaginationValue) Equal(o attr.Value) bool { - other, ok := o.(PaginationValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Page.Equal(other.Page) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - if !v.Sort.Equal(other.Sort) { - return false - } - - if !v.TotalPages.Equal(other.TotalPages) { - return false - } - - if !v.TotalRows.Equal(other.TotalRows) { - return false - } - - return true -} - -func (v PaginationValue) Type(ctx context.Context) attr.Type { - return PaginationType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v PaginationValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } -} diff --git a/stackit/internal/services/postgresflexalpha/flavors/datasources_gen/flavors_data_source_gen.go b/stackit/internal/services/postgresflexalpha/flavors/datasources_gen/flavors_data_source_gen.go deleted file mode 100644 index dbfe5cc9..00000000 --- a/stackit/internal/services/postgresflexalpha/flavors/datasources_gen/flavors_data_source_gen.go +++ /dev/null @@ -1,1909 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package postgresflexalpha - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -func FlavorsDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "flavors": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "cpu": schema.Int64Attribute{ - Computed: true, - Description: "The cpu count of the instance.", - MarkdownDescription: "The cpu count of the instance.", - }, - "description": schema.StringAttribute{ - Computed: true, - Description: "The flavor description.", - MarkdownDescription: "The flavor description.", - }, - "tf_original_api_id": schema.StringAttribute{ - Computed: true, - Description: "The id of the instance flavor.", - MarkdownDescription: "The id of the instance flavor.", - }, - "max_gb": schema.Int64Attribute{ - Computed: true, - Description: "maximum storage which can be ordered for the flavor in Gigabyte.", - MarkdownDescription: "maximum storage which can be ordered for the flavor in Gigabyte.", - }, - "memory": schema.Int64Attribute{ - Computed: true, - Description: "The memory of the instance in Gibibyte.", - MarkdownDescription: "The memory of the instance in Gibibyte.", - }, - "min_gb": schema.Int64Attribute{ - Computed: true, - Description: "minimum storage which is required to order in Gigabyte.", - MarkdownDescription: "minimum storage which is required to order in Gigabyte.", - }, - "node_type": schema.StringAttribute{ - Computed: true, - Description: "defines the nodeType it can be either single or replica", - MarkdownDescription: "defines the nodeType it can be either single or replica", - }, - "storage_classes": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "class": schema.StringAttribute{ - Computed: true, - }, - "max_io_per_sec": schema.Int64Attribute{ - Computed: true, - }, - "max_through_in_mb": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: StorageClassesType{ - ObjectType: types.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "maximum storage which can be ordered for the flavor in Gigabyte.", - MarkdownDescription: "maximum storage which can be ordered for the flavor in Gigabyte.", - }, - }, - CustomType: FlavorsType{ - ObjectType: types.ObjectType{ - AttrTypes: FlavorsValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "List of flavors available for the project.", - MarkdownDescription: "List of flavors available for the project.", - }, - "page": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of the page of items list to be returned.", - MarkdownDescription: "Number of the page of items list to be returned.", - }, - "pagination": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "page": schema.Int64Attribute{ - Computed: true, - }, - "size": schema.Int64Attribute{ - Computed: true, - }, - "sort": schema.StringAttribute{ - Computed: true, - }, - "total_pages": schema.Int64Attribute{ - Computed: true, - }, - "total_rows": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: PaginationType{ - ObjectType: types.ObjectType{ - AttrTypes: PaginationValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - }, - "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", - ), - }, - }, - "size": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of items to be returned on each page.", - MarkdownDescription: "Number of items to be returned on each page.", - }, - "sort": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "Sorting of the flavors to be returned on each page.", - MarkdownDescription: "Sorting of the flavors to be returned on each page.", - Validators: []validator.String{ - stringvalidator.OneOf( - "index.desc", - "index.asc", - "cpu.desc", - "cpu.asc", - "flavor_description.asc", - "flavor_description.desc", - "id.desc", - "id.asc", - "size_max.desc", - "size_max.asc", - "ram.desc", - "ram.asc", - "size_min.desc", - "size_min.asc", - "storage_class.asc", - "storage_class.desc", - "node_type.asc", - "node_type.desc", - ), - }, - }, - }, - } -} - -type FlavorsModel struct { - Flavors types.List `tfsdk:"flavors"` - Page types.Int64 `tfsdk:"page"` - Pagination PaginationValue `tfsdk:"pagination"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Size types.Int64 `tfsdk:"size"` - Sort types.String `tfsdk:"sort"` -} - -var _ basetypes.ObjectTypable = FlavorsType{} - -type FlavorsType struct { - basetypes.ObjectType -} - -func (t FlavorsType) Equal(o attr.Type) bool { - other, ok := o.(FlavorsType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t FlavorsType) String() string { - return "FlavorsType" -} - -func (t FlavorsType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - cpuAttribute, ok := attributes["cpu"] - - if !ok { - diags.AddError( - "Attribute Missing", - `cpu is missing from object`) - - return nil, diags - } - - cpuVal, ok := cpuAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`cpu expected to be basetypes.Int64Value, was: %T`, cpuAttribute)) - } - - descriptionAttribute, ok := attributes["description"] - - if !ok { - diags.AddError( - "Attribute Missing", - `description is missing from object`) - - return nil, diags - } - - descriptionVal, ok := descriptionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`description expected to be basetypes.StringValue, was: %T`, descriptionAttribute)) - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return nil, diags - } - - idVal, ok := idAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.StringValue, was: %T`, idAttribute)) - } - - maxGbAttribute, ok := attributes["max_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_gb is missing from object`) - - return nil, diags - } - - maxGbVal, ok := maxGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_gb expected to be basetypes.Int64Value, was: %T`, maxGbAttribute)) - } - - memoryAttribute, ok := attributes["memory"] - - if !ok { - diags.AddError( - "Attribute Missing", - `memory is missing from object`) - - return nil, diags - } - - memoryVal, ok := memoryAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`memory expected to be basetypes.Int64Value, was: %T`, memoryAttribute)) - } - - minGbAttribute, ok := attributes["min_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `min_gb is missing from object`) - - return nil, diags - } - - minGbVal, ok := minGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`min_gb expected to be basetypes.Int64Value, was: %T`, minGbAttribute)) - } - - nodeTypeAttribute, ok := attributes["node_type"] - - if !ok { - diags.AddError( - "Attribute Missing", - `node_type is missing from object`) - - return nil, diags - } - - nodeTypeVal, ok := nodeTypeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`node_type expected to be basetypes.StringValue, was: %T`, nodeTypeAttribute)) - } - - storageClassesAttribute, ok := attributes["storage_classes"] - - if !ok { - diags.AddError( - "Attribute Missing", - `storage_classes is missing from object`) - - return nil, diags - } - - storageClassesVal, ok := storageClassesAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`storage_classes expected to be basetypes.ListValue, was: %T`, storageClassesAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return FlavorsValue{ - Cpu: cpuVal, - Description: descriptionVal, - Id: idVal, - MaxGb: maxGbVal, - Memory: memoryVal, - MinGb: minGbVal, - NodeType: nodeTypeVal, - StorageClasses: storageClassesVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewFlavorsValueNull() FlavorsValue { - return FlavorsValue{ - state: attr.ValueStateNull, - } -} - -func NewFlavorsValueUnknown() FlavorsValue { - return FlavorsValue{ - state: attr.ValueStateUnknown, - } -} - -func NewFlavorsValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (FlavorsValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing FlavorsValue Attribute Value", - "While creating a FlavorsValue value, a missing attribute value was detected. "+ - "A FlavorsValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("FlavorsValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid FlavorsValue Attribute Type", - "While creating a FlavorsValue value, an invalid attribute value was detected. "+ - "A FlavorsValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("FlavorsValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("FlavorsValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra FlavorsValue Attribute Value", - "While creating a FlavorsValue value, an extra attribute value was detected. "+ - "A FlavorsValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra FlavorsValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewFlavorsValueUnknown(), diags - } - - cpuAttribute, ok := attributes["cpu"] - - if !ok { - diags.AddError( - "Attribute Missing", - `cpu is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - cpuVal, ok := cpuAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`cpu expected to be basetypes.Int64Value, was: %T`, cpuAttribute)) - } - - descriptionAttribute, ok := attributes["description"] - - if !ok { - diags.AddError( - "Attribute Missing", - `description is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - descriptionVal, ok := descriptionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`description expected to be basetypes.StringValue, was: %T`, descriptionAttribute)) - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - idVal, ok := idAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.StringValue, was: %T`, idAttribute)) - } - - maxGbAttribute, ok := attributes["max_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_gb is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - maxGbVal, ok := maxGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_gb expected to be basetypes.Int64Value, was: %T`, maxGbAttribute)) - } - - memoryAttribute, ok := attributes["memory"] - - if !ok { - diags.AddError( - "Attribute Missing", - `memory is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - memoryVal, ok := memoryAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`memory expected to be basetypes.Int64Value, was: %T`, memoryAttribute)) - } - - minGbAttribute, ok := attributes["min_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `min_gb is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - minGbVal, ok := minGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`min_gb expected to be basetypes.Int64Value, was: %T`, minGbAttribute)) - } - - nodeTypeAttribute, ok := attributes["node_type"] - - if !ok { - diags.AddError( - "Attribute Missing", - `node_type is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - nodeTypeVal, ok := nodeTypeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`node_type expected to be basetypes.StringValue, was: %T`, nodeTypeAttribute)) - } - - storageClassesAttribute, ok := attributes["storage_classes"] - - if !ok { - diags.AddError( - "Attribute Missing", - `storage_classes is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - storageClassesVal, ok := storageClassesAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`storage_classes expected to be basetypes.ListValue, was: %T`, storageClassesAttribute)) - } - - if diags.HasError() { - return NewFlavorsValueUnknown(), diags - } - - return FlavorsValue{ - Cpu: cpuVal, - Description: descriptionVal, - Id: idVal, - MaxGb: maxGbVal, - Memory: memoryVal, - MinGb: minGbVal, - NodeType: nodeTypeVal, - StorageClasses: storageClassesVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewFlavorsValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) FlavorsValue { - object, diags := NewFlavorsValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewFlavorsValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t FlavorsType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewFlavorsValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewFlavorsValueUnknown(), nil - } - - if in.IsNull() { - return NewFlavorsValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewFlavorsValueMust(FlavorsValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t FlavorsType) ValueType(ctx context.Context) attr.Value { - return FlavorsValue{} -} - -var _ basetypes.ObjectValuable = FlavorsValue{} - -type FlavorsValue struct { - Cpu basetypes.Int64Value `tfsdk:"cpu"` - Description basetypes.StringValue `tfsdk:"description"` - Id basetypes.StringValue `tfsdk:"id"` - MaxGb basetypes.Int64Value `tfsdk:"max_gb"` - Memory basetypes.Int64Value `tfsdk:"memory"` - MinGb basetypes.Int64Value `tfsdk:"min_gb"` - NodeType basetypes.StringValue `tfsdk:"node_type"` - StorageClasses basetypes.ListValue `tfsdk:"storage_classes"` - state attr.ValueState -} - -func (v FlavorsValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 8) - - var val tftypes.Value - var err error - - attrTypes["cpu"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["description"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["max_gb"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["memory"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["min_gb"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["node_type"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["storage_classes"] = basetypes.ListType{ - ElemType: StorageClassesValue{}.Type(ctx), - }.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 8) - - val, err = v.Cpu.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["cpu"] = val - - val, err = v.Description.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["description"] = val - - val, err = v.Id.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["id"] = val - - val, err = v.MaxGb.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["max_gb"] = val - - val, err = v.Memory.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["memory"] = val - - val, err = v.MinGb.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["min_gb"] = val - - val, err = v.NodeType.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["node_type"] = val - - val, err = v.StorageClasses.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["storage_classes"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v FlavorsValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v FlavorsValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v FlavorsValue) String() string { - return "FlavorsValue" -} - -func (v FlavorsValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - storageClasses := types.ListValueMust( - StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - v.StorageClasses.Elements(), - ) - - if v.StorageClasses.IsNull() { - storageClasses = types.ListNull( - StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - ) - } - - if v.StorageClasses.IsUnknown() { - storageClasses = types.ListUnknown( - StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - ) - } - - attributeTypes := map[string]attr.Type{ - "cpu": basetypes.Int64Type{}, - "description": basetypes.StringType{}, - "id": basetypes.StringType{}, - "max_gb": basetypes.Int64Type{}, - "memory": basetypes.Int64Type{}, - "min_gb": basetypes.Int64Type{}, - "node_type": basetypes.StringType{}, - "storage_classes": basetypes.ListType{ - ElemType: StorageClassesValue{}.Type(ctx), - }, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "cpu": v.Cpu, - "description": v.Description, - "id": v.Id, - "max_gb": v.MaxGb, - "memory": v.Memory, - "min_gb": v.MinGb, - "node_type": v.NodeType, - "storage_classes": storageClasses, - }) - - return objVal, diags -} - -func (v FlavorsValue) Equal(o attr.Value) bool { - other, ok := o.(FlavorsValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Cpu.Equal(other.Cpu) { - return false - } - - if !v.Description.Equal(other.Description) { - return false - } - - if !v.Id.Equal(other.Id) { - return false - } - - if !v.MaxGb.Equal(other.MaxGb) { - return false - } - - if !v.Memory.Equal(other.Memory) { - return false - } - - if !v.MinGb.Equal(other.MinGb) { - return false - } - - if !v.NodeType.Equal(other.NodeType) { - return false - } - - if !v.StorageClasses.Equal(other.StorageClasses) { - return false - } - - return true -} - -func (v FlavorsValue) Type(ctx context.Context) attr.Type { - return FlavorsType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v FlavorsValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "cpu": basetypes.Int64Type{}, - "description": basetypes.StringType{}, - "id": basetypes.StringType{}, - "max_gb": basetypes.Int64Type{}, - "memory": basetypes.Int64Type{}, - "min_gb": basetypes.Int64Type{}, - "node_type": basetypes.StringType{}, - "storage_classes": basetypes.ListType{ - ElemType: StorageClassesValue{}.Type(ctx), - }, - } -} - -var _ basetypes.ObjectTypable = StorageClassesType{} - -type StorageClassesType struct { - basetypes.ObjectType -} - -func (t StorageClassesType) Equal(o attr.Type) bool { - other, ok := o.(StorageClassesType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t StorageClassesType) String() string { - return "StorageClassesType" -} - -func (t StorageClassesType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - classAttribute, ok := attributes["class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `class is missing from object`) - - return nil, diags - } - - classVal, ok := classAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`class expected to be basetypes.StringValue, was: %T`, classAttribute)) - } - - maxIoPerSecAttribute, ok := attributes["max_io_per_sec"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_io_per_sec is missing from object`) - - return nil, diags - } - - maxIoPerSecVal, ok := maxIoPerSecAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_io_per_sec expected to be basetypes.Int64Value, was: %T`, maxIoPerSecAttribute)) - } - - maxThroughInMbAttribute, ok := attributes["max_through_in_mb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_through_in_mb is missing from object`) - - return nil, diags - } - - maxThroughInMbVal, ok := maxThroughInMbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_through_in_mb expected to be basetypes.Int64Value, was: %T`, maxThroughInMbAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return StorageClassesValue{ - Class: classVal, - MaxIoPerSec: maxIoPerSecVal, - MaxThroughInMb: maxThroughInMbVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageClassesValueNull() StorageClassesValue { - return StorageClassesValue{ - state: attr.ValueStateNull, - } -} - -func NewStorageClassesValueUnknown() StorageClassesValue { - return StorageClassesValue{ - state: attr.ValueStateUnknown, - } -} - -func NewStorageClassesValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (StorageClassesValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing StorageClassesValue Attribute Value", - "While creating a StorageClassesValue value, a missing attribute value was detected. "+ - "A StorageClassesValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageClassesValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid StorageClassesValue Attribute Type", - "While creating a StorageClassesValue value, an invalid attribute value was detected. "+ - "A StorageClassesValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageClassesValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("StorageClassesValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra StorageClassesValue Attribute Value", - "While creating a StorageClassesValue value, an extra attribute value was detected. "+ - "A StorageClassesValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra StorageClassesValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewStorageClassesValueUnknown(), diags - } - - classAttribute, ok := attributes["class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `class is missing from object`) - - return NewStorageClassesValueUnknown(), diags - } - - classVal, ok := classAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`class expected to be basetypes.StringValue, was: %T`, classAttribute)) - } - - maxIoPerSecAttribute, ok := attributes["max_io_per_sec"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_io_per_sec is missing from object`) - - return NewStorageClassesValueUnknown(), diags - } - - maxIoPerSecVal, ok := maxIoPerSecAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_io_per_sec expected to be basetypes.Int64Value, was: %T`, maxIoPerSecAttribute)) - } - - maxThroughInMbAttribute, ok := attributes["max_through_in_mb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_through_in_mb is missing from object`) - - return NewStorageClassesValueUnknown(), diags - } - - maxThroughInMbVal, ok := maxThroughInMbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_through_in_mb expected to be basetypes.Int64Value, was: %T`, maxThroughInMbAttribute)) - } - - if diags.HasError() { - return NewStorageClassesValueUnknown(), diags - } - - return StorageClassesValue{ - Class: classVal, - MaxIoPerSec: maxIoPerSecVal, - MaxThroughInMb: maxThroughInMbVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageClassesValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) StorageClassesValue { - object, diags := NewStorageClassesValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewStorageClassesValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t StorageClassesType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewStorageClassesValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewStorageClassesValueUnknown(), nil - } - - if in.IsNull() { - return NewStorageClassesValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewStorageClassesValueMust(StorageClassesValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t StorageClassesType) ValueType(ctx context.Context) attr.Value { - return StorageClassesValue{} -} - -var _ basetypes.ObjectValuable = StorageClassesValue{} - -type StorageClassesValue struct { - Class basetypes.StringValue `tfsdk:"class"` - MaxIoPerSec basetypes.Int64Value `tfsdk:"max_io_per_sec"` - MaxThroughInMb basetypes.Int64Value `tfsdk:"max_through_in_mb"` - state attr.ValueState -} - -func (v StorageClassesValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 3) - - var val tftypes.Value - var err error - - attrTypes["class"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["max_io_per_sec"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["max_through_in_mb"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 3) - - val, err = v.Class.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["class"] = val - - val, err = v.MaxIoPerSec.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["max_io_per_sec"] = val - - val, err = v.MaxThroughInMb.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["max_through_in_mb"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v StorageClassesValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v StorageClassesValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v StorageClassesValue) String() string { - return "StorageClassesValue" -} - -func (v StorageClassesValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "class": basetypes.StringType{}, - "max_io_per_sec": basetypes.Int64Type{}, - "max_through_in_mb": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "class": v.Class, - "max_io_per_sec": v.MaxIoPerSec, - "max_through_in_mb": v.MaxThroughInMb, - }) - - return objVal, diags -} - -func (v StorageClassesValue) Equal(o attr.Value) bool { - other, ok := o.(StorageClassesValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Class.Equal(other.Class) { - return false - } - - if !v.MaxIoPerSec.Equal(other.MaxIoPerSec) { - return false - } - - if !v.MaxThroughInMb.Equal(other.MaxThroughInMb) { - return false - } - - return true -} - -func (v StorageClassesValue) Type(ctx context.Context) attr.Type { - return StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v StorageClassesValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "class": basetypes.StringType{}, - "max_io_per_sec": basetypes.Int64Type{}, - "max_through_in_mb": basetypes.Int64Type{}, - } -} - -var _ basetypes.ObjectTypable = PaginationType{} - -type PaginationType struct { - basetypes.ObjectType -} - -func (t PaginationType) Equal(o attr.Type) bool { - other, ok := o.(PaginationType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t PaginationType) String() string { - return "PaginationType" -} - -func (t PaginationType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return nil, diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return nil, diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return nil, diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return nil, diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueNull() PaginationValue { - return PaginationValue{ - state: attr.ValueStateNull, - } -} - -func NewPaginationValueUnknown() PaginationValue { - return PaginationValue{ - state: attr.ValueStateUnknown, - } -} - -func NewPaginationValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (PaginationValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing PaginationValue Attribute Value", - "While creating a PaginationValue value, a missing attribute value was detected. "+ - "A PaginationValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid PaginationValue Attribute Type", - "While creating a PaginationValue value, an invalid attribute value was detected. "+ - "A PaginationValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra PaginationValue Attribute Value", - "While creating a PaginationValue value, an extra attribute value was detected. "+ - "A PaginationValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra PaginationValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) PaginationValue { - object, diags := NewPaginationValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewPaginationValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t PaginationType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewPaginationValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewPaginationValueUnknown(), nil - } - - if in.IsNull() { - return NewPaginationValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewPaginationValueMust(PaginationValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t PaginationType) ValueType(ctx context.Context) attr.Value { - return PaginationValue{} -} - -var _ basetypes.ObjectValuable = PaginationValue{} - -type PaginationValue struct { - Page basetypes.Int64Value `tfsdk:"page"` - Size basetypes.Int64Value `tfsdk:"size"` - Sort basetypes.StringValue `tfsdk:"sort"` - TotalPages basetypes.Int64Value `tfsdk:"total_pages"` - TotalRows basetypes.Int64Value `tfsdk:"total_rows"` - state attr.ValueState -} - -func (v PaginationValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 5) - - var val tftypes.Value - var err error - - attrTypes["page"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["sort"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["total_pages"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["total_rows"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 5) - - val, err = v.Page.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["page"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - val, err = v.Sort.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["sort"] = val - - val, err = v.TotalPages.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_pages"] = val - - val, err = v.TotalRows.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_rows"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v PaginationValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v PaginationValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v PaginationValue) String() string { - return "PaginationValue" -} - -func (v PaginationValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "page": v.Page, - "size": v.Size, - "sort": v.Sort, - "total_pages": v.TotalPages, - "total_rows": v.TotalRows, - }) - - return objVal, diags -} - -func (v PaginationValue) Equal(o attr.Value) bool { - other, ok := o.(PaginationValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Page.Equal(other.Page) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - if !v.Sort.Equal(other.Sort) { - return false - } - - if !v.TotalPages.Equal(other.TotalPages) { - return false - } - - if !v.TotalRows.Equal(other.TotalRows) { - return false - } - - return true -} - -func (v PaginationValue) Type(ctx context.Context) attr.Type { - return PaginationType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v PaginationValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } -} diff --git a/stackit/internal/services/postgresflexalpha/instance/datasources_gen/instance_data_source_gen.go b/stackit/internal/services/postgresflexalpha/instance/datasources_gen/instance_data_source_gen.go deleted file mode 100644 index 047d0176..00000000 --- a/stackit/internal/services/postgresflexalpha/instance/datasources_gen/instance_data_source_gen.go +++ /dev/null @@ -1,1984 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package postgresflexalpha - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -func InstanceDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "acl": schema.ListAttribute{ - ElementType: types.StringType, - Computed: true, - Description: "List of IPV4 cidr.", - MarkdownDescription: "List of IPV4 cidr.", - }, - "backup_schedule": schema.StringAttribute{ - Computed: true, - Description: "The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.", - MarkdownDescription: "The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.", - }, - "connection_info": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "host": schema.StringAttribute{ - Computed: true, - Description: "The host of the instance.", - MarkdownDescription: "The host of the instance.", - }, - "port": schema.Int64Attribute{ - Computed: true, - Description: "The port of the instance.", - MarkdownDescription: "The port of the instance.", - }, - }, - CustomType: ConnectionInfoType{ - ObjectType: types.ObjectType{ - AttrTypes: ConnectionInfoValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - Description: "The DNS name and port in the instance overview", - MarkdownDescription: "The DNS name and port in the instance overview", - }, - "encryption": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "kek_key_id": schema.StringAttribute{ - Computed: true, - Description: "The encryption-key key identifier", - MarkdownDescription: "The encryption-key key identifier", - }, - "kek_key_ring_id": schema.StringAttribute{ - Computed: true, - Description: "The encryption-key keyring identifier", - MarkdownDescription: "The encryption-key keyring identifier", - }, - "kek_key_version": schema.StringAttribute{ - Computed: true, - Description: "The encryption-key version", - MarkdownDescription: "The encryption-key version", - }, - "service_account": schema.StringAttribute{ - Computed: true, - }, - }, - CustomType: EncryptionType{ - ObjectType: types.ObjectType{ - AttrTypes: EncryptionValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - Description: "The configuration for instance's volume and backup storage encryption.\n\n⚠\ufe1d **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.\n", - MarkdownDescription: "The configuration for instance's volume and backup storage encryption.\n\n⚠\ufe1d **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.\n", - }, - "flavor_id": schema.StringAttribute{ - Computed: true, - Description: "The id of the instance flavor.", - MarkdownDescription: "The id of the instance flavor.", - }, - "tf_original_api_id": schema.StringAttribute{ - Computed: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "instance_id": schema.StringAttribute{ - Required: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "is_deletable": schema.BoolAttribute{ - Computed: true, - Description: "Whether the instance can be deleted or not.", - MarkdownDescription: "Whether the instance can be deleted or not.", - }, - "name": schema.StringAttribute{ - Computed: true, - Description: "The name of the instance.", - MarkdownDescription: "The name of the instance.", - }, - "network": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "access_scope": schema.StringAttribute{ - Computed: true, - Description: "The access scope of the instance. It defines if the instance is public or airgapped.", - MarkdownDescription: "The access scope of the instance. It defines if the instance is public or airgapped.", - }, - "acl": schema.ListAttribute{ - ElementType: types.StringType, - Computed: true, - Description: "List of IPV4 cidr.", - MarkdownDescription: "List of IPV4 cidr.", - }, - "instance_address": schema.StringAttribute{ - Computed: true, - }, - "router_address": schema.StringAttribute{ - Computed: true, - }, - }, - CustomType: NetworkType{ - ObjectType: types.ObjectType{ - AttrTypes: NetworkValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - Description: "The access configuration of the instance", - MarkdownDescription: "The access configuration of the instance", - }, - "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", - ), - }, - }, - "replicas": schema.Int64Attribute{ - Computed: true, - Description: "How many replicas the instance should have.", - MarkdownDescription: "How many replicas the instance should have.", - }, - "retention_days": schema.Int64Attribute{ - Computed: true, - Description: "How long backups are retained. The value can only be between 32 and 365 days.", - MarkdownDescription: "How long backups are retained. The value can only be between 32 and 365 days.", - }, - "status": schema.StringAttribute{ - Computed: true, - Description: "The current status of the instance.", - MarkdownDescription: "The current status of the instance.", - }, - "storage": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "performance_class": schema.StringAttribute{ - Computed: true, - Description: "The storage class for the storage.", - MarkdownDescription: "The storage class for the storage.", - }, - "size": schema.Int64Attribute{ - Computed: true, - Description: "The storage size in Gigabytes.", - MarkdownDescription: "The storage size in Gigabytes.", - }, - }, - CustomType: StorageType{ - ObjectType: types.ObjectType{ - AttrTypes: StorageValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - Description: "The object containing information about the storage size and class.", - MarkdownDescription: "The object containing information about the storage size and class.", - }, - "version": schema.StringAttribute{ - Computed: true, - Description: "The Postgres version used for the instance. See [Versions Endpoint](/documentation/postgres-flex-service/version/v3alpha1#tag/Version) for supported version parameters.", - MarkdownDescription: "The Postgres version used for the instance. See [Versions Endpoint](/documentation/postgres-flex-service/version/v3alpha1#tag/Version) for supported version parameters.", - }, - }, - } -} - -type InstanceModel struct { - Acl types.List `tfsdk:"acl"` - BackupSchedule types.String `tfsdk:"backup_schedule"` - ConnectionInfo ConnectionInfoValue `tfsdk:"connection_info"` - Encryption EncryptionValue `tfsdk:"encryption"` - FlavorId types.String `tfsdk:"flavor_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"` - Network NetworkValue `tfsdk:"network"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Replicas types.Int64 `tfsdk:"replicas"` - RetentionDays types.Int64 `tfsdk:"retention_days"` - Status types.String `tfsdk:"status"` - Storage StorageValue `tfsdk:"storage"` - Version types.String `tfsdk:"version"` -} - -var _ basetypes.ObjectTypable = ConnectionInfoType{} - -type ConnectionInfoType struct { - basetypes.ObjectType -} - -func (t ConnectionInfoType) Equal(o attr.Type) bool { - other, ok := o.(ConnectionInfoType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t ConnectionInfoType) String() string { - return "ConnectionInfoType" -} - -func (t ConnectionInfoType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - hostAttribute, ok := attributes["host"] - - if !ok { - diags.AddError( - "Attribute Missing", - `host is missing from object`) - - return nil, diags - } - - hostVal, ok := hostAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`host expected to be basetypes.StringValue, was: %T`, hostAttribute)) - } - - portAttribute, ok := attributes["port"] - - if !ok { - diags.AddError( - "Attribute Missing", - `port is missing from object`) - - return nil, diags - } - - portVal, ok := portAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`port expected to be basetypes.Int64Value, was: %T`, portAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return ConnectionInfoValue{ - Host: hostVal, - Port: portVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewConnectionInfoValueNull() ConnectionInfoValue { - return ConnectionInfoValue{ - state: attr.ValueStateNull, - } -} - -func NewConnectionInfoValueUnknown() ConnectionInfoValue { - return ConnectionInfoValue{ - state: attr.ValueStateUnknown, - } -} - -func NewConnectionInfoValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (ConnectionInfoValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing ConnectionInfoValue Attribute Value", - "While creating a ConnectionInfoValue value, a missing attribute value was detected. "+ - "A ConnectionInfoValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("ConnectionInfoValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid ConnectionInfoValue Attribute Type", - "While creating a ConnectionInfoValue value, an invalid attribute value was detected. "+ - "A ConnectionInfoValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("ConnectionInfoValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("ConnectionInfoValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra ConnectionInfoValue Attribute Value", - "While creating a ConnectionInfoValue value, an extra attribute value was detected. "+ - "A ConnectionInfoValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra ConnectionInfoValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewConnectionInfoValueUnknown(), diags - } - - hostAttribute, ok := attributes["host"] - - if !ok { - diags.AddError( - "Attribute Missing", - `host is missing from object`) - - return NewConnectionInfoValueUnknown(), diags - } - - hostVal, ok := hostAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`host expected to be basetypes.StringValue, was: %T`, hostAttribute)) - } - - portAttribute, ok := attributes["port"] - - if !ok { - diags.AddError( - "Attribute Missing", - `port is missing from object`) - - return NewConnectionInfoValueUnknown(), diags - } - - portVal, ok := portAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`port expected to be basetypes.Int64Value, was: %T`, portAttribute)) - } - - if diags.HasError() { - return NewConnectionInfoValueUnknown(), diags - } - - return ConnectionInfoValue{ - Host: hostVal, - Port: portVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewConnectionInfoValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) ConnectionInfoValue { - object, diags := NewConnectionInfoValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewConnectionInfoValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t ConnectionInfoType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewConnectionInfoValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewConnectionInfoValueUnknown(), nil - } - - if in.IsNull() { - return NewConnectionInfoValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewConnectionInfoValueMust(ConnectionInfoValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t ConnectionInfoType) ValueType(ctx context.Context) attr.Value { - return ConnectionInfoValue{} -} - -var _ basetypes.ObjectValuable = ConnectionInfoValue{} - -type ConnectionInfoValue struct { - Host basetypes.StringValue `tfsdk:"host"` - Port basetypes.Int64Value `tfsdk:"port"` - state attr.ValueState -} - -func (v ConnectionInfoValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 2) - - var val tftypes.Value - var err error - - attrTypes["host"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["port"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 2) - - val, err = v.Host.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["host"] = val - - val, err = v.Port.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["port"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v ConnectionInfoValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v ConnectionInfoValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v ConnectionInfoValue) String() string { - return "ConnectionInfoValue" -} - -func (v ConnectionInfoValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "host": basetypes.StringType{}, - "port": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "host": v.Host, - "port": v.Port, - }) - - return objVal, diags -} - -func (v ConnectionInfoValue) Equal(o attr.Value) bool { - other, ok := o.(ConnectionInfoValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Host.Equal(other.Host) { - return false - } - - if !v.Port.Equal(other.Port) { - return false - } - - return true -} - -func (v ConnectionInfoValue) Type(ctx context.Context) attr.Type { - return ConnectionInfoType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v ConnectionInfoValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "host": basetypes.StringType{}, - "port": basetypes.Int64Type{}, - } -} - -var _ basetypes.ObjectTypable = EncryptionType{} - -type EncryptionType struct { - basetypes.ObjectType -} - -func (t EncryptionType) Equal(o attr.Type) bool { - other, ok := o.(EncryptionType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t EncryptionType) String() string { - return "EncryptionType" -} - -func (t EncryptionType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - kekKeyIdAttribute, ok := attributes["kek_key_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_id is missing from object`) - - return nil, diags - } - - kekKeyIdVal, ok := kekKeyIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_id expected to be basetypes.StringValue, was: %T`, kekKeyIdAttribute)) - } - - kekKeyRingIdAttribute, ok := attributes["kek_key_ring_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_ring_id is missing from object`) - - return nil, diags - } - - kekKeyRingIdVal, ok := kekKeyRingIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_ring_id expected to be basetypes.StringValue, was: %T`, kekKeyRingIdAttribute)) - } - - kekKeyVersionAttribute, ok := attributes["kek_key_version"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_version is missing from object`) - - return nil, diags - } - - kekKeyVersionVal, ok := kekKeyVersionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_version expected to be basetypes.StringValue, was: %T`, kekKeyVersionAttribute)) - } - - serviceAccountAttribute, ok := attributes["service_account"] - - if !ok { - diags.AddError( - "Attribute Missing", - `service_account is missing from object`) - - return nil, diags - } - - serviceAccountVal, ok := serviceAccountAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`service_account expected to be basetypes.StringValue, was: %T`, serviceAccountAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return EncryptionValue{ - KekKeyId: kekKeyIdVal, - KekKeyRingId: kekKeyRingIdVal, - KekKeyVersion: kekKeyVersionVal, - ServiceAccount: serviceAccountVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewEncryptionValueNull() EncryptionValue { - return EncryptionValue{ - state: attr.ValueStateNull, - } -} - -func NewEncryptionValueUnknown() EncryptionValue { - return EncryptionValue{ - state: attr.ValueStateUnknown, - } -} - -func NewEncryptionValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (EncryptionValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing EncryptionValue Attribute Value", - "While creating a EncryptionValue value, a missing attribute value was detected. "+ - "A EncryptionValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("EncryptionValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid EncryptionValue Attribute Type", - "While creating a EncryptionValue value, an invalid attribute value was detected. "+ - "A EncryptionValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("EncryptionValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("EncryptionValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra EncryptionValue Attribute Value", - "While creating a EncryptionValue value, an extra attribute value was detected. "+ - "A EncryptionValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra EncryptionValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewEncryptionValueUnknown(), diags - } - - kekKeyIdAttribute, ok := attributes["kek_key_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_id is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - kekKeyIdVal, ok := kekKeyIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_id expected to be basetypes.StringValue, was: %T`, kekKeyIdAttribute)) - } - - kekKeyRingIdAttribute, ok := attributes["kek_key_ring_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_ring_id is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - kekKeyRingIdVal, ok := kekKeyRingIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_ring_id expected to be basetypes.StringValue, was: %T`, kekKeyRingIdAttribute)) - } - - kekKeyVersionAttribute, ok := attributes["kek_key_version"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_version is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - kekKeyVersionVal, ok := kekKeyVersionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_version expected to be basetypes.StringValue, was: %T`, kekKeyVersionAttribute)) - } - - serviceAccountAttribute, ok := attributes["service_account"] - - if !ok { - diags.AddError( - "Attribute Missing", - `service_account is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - serviceAccountVal, ok := serviceAccountAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`service_account expected to be basetypes.StringValue, was: %T`, serviceAccountAttribute)) - } - - if diags.HasError() { - return NewEncryptionValueUnknown(), diags - } - - return EncryptionValue{ - KekKeyId: kekKeyIdVal, - KekKeyRingId: kekKeyRingIdVal, - KekKeyVersion: kekKeyVersionVal, - ServiceAccount: serviceAccountVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewEncryptionValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) EncryptionValue { - object, diags := NewEncryptionValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewEncryptionValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t EncryptionType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewEncryptionValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewEncryptionValueUnknown(), nil - } - - if in.IsNull() { - return NewEncryptionValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewEncryptionValueMust(EncryptionValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t EncryptionType) ValueType(ctx context.Context) attr.Value { - return EncryptionValue{} -} - -var _ basetypes.ObjectValuable = EncryptionValue{} - -type EncryptionValue struct { - KekKeyId basetypes.StringValue `tfsdk:"kek_key_id"` - KekKeyRingId basetypes.StringValue `tfsdk:"kek_key_ring_id"` - KekKeyVersion basetypes.StringValue `tfsdk:"kek_key_version"` - ServiceAccount basetypes.StringValue `tfsdk:"service_account"` - state attr.ValueState -} - -func (v EncryptionValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 4) - - var val tftypes.Value - var err error - - attrTypes["kek_key_id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["kek_key_ring_id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["kek_key_version"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["service_account"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 4) - - val, err = v.KekKeyId.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["kek_key_id"] = val - - val, err = v.KekKeyRingId.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["kek_key_ring_id"] = val - - val, err = v.KekKeyVersion.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["kek_key_version"] = val - - val, err = v.ServiceAccount.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["service_account"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v EncryptionValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v EncryptionValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v EncryptionValue) String() string { - return "EncryptionValue" -} - -func (v EncryptionValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "kek_key_id": basetypes.StringType{}, - "kek_key_ring_id": basetypes.StringType{}, - "kek_key_version": basetypes.StringType{}, - "service_account": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "kek_key_id": v.KekKeyId, - "kek_key_ring_id": v.KekKeyRingId, - "kek_key_version": v.KekKeyVersion, - "service_account": v.ServiceAccount, - }) - - return objVal, diags -} - -func (v EncryptionValue) Equal(o attr.Value) bool { - other, ok := o.(EncryptionValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.KekKeyId.Equal(other.KekKeyId) { - return false - } - - if !v.KekKeyRingId.Equal(other.KekKeyRingId) { - return false - } - - if !v.KekKeyVersion.Equal(other.KekKeyVersion) { - return false - } - - if !v.ServiceAccount.Equal(other.ServiceAccount) { - return false - } - - return true -} - -func (v EncryptionValue) Type(ctx context.Context) attr.Type { - return EncryptionType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v EncryptionValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "kek_key_id": basetypes.StringType{}, - "kek_key_ring_id": basetypes.StringType{}, - "kek_key_version": basetypes.StringType{}, - "service_account": basetypes.StringType{}, - } -} - -var _ basetypes.ObjectTypable = NetworkType{} - -type NetworkType struct { - basetypes.ObjectType -} - -func (t NetworkType) Equal(o attr.Type) bool { - other, ok := o.(NetworkType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t NetworkType) String() string { - return "NetworkType" -} - -func (t NetworkType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - accessScopeAttribute, ok := attributes["access_scope"] - - if !ok { - diags.AddError( - "Attribute Missing", - `access_scope is missing from object`) - - return nil, diags - } - - accessScopeVal, ok := accessScopeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`access_scope expected to be basetypes.StringValue, was: %T`, accessScopeAttribute)) - } - - aclAttribute, ok := attributes["acl"] - - if !ok { - diags.AddError( - "Attribute Missing", - `acl is missing from object`) - - return nil, diags - } - - aclVal, ok := aclAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`acl expected to be basetypes.ListValue, was: %T`, aclAttribute)) - } - - instanceAddressAttribute, ok := attributes["instance_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `instance_address is missing from object`) - - return nil, diags - } - - instanceAddressVal, ok := instanceAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`instance_address expected to be basetypes.StringValue, was: %T`, instanceAddressAttribute)) - } - - routerAddressAttribute, ok := attributes["router_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `router_address is missing from object`) - - return nil, diags - } - - routerAddressVal, ok := routerAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`router_address expected to be basetypes.StringValue, was: %T`, routerAddressAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return NetworkValue{ - AccessScope: accessScopeVal, - Acl: aclVal, - InstanceAddress: instanceAddressVal, - RouterAddress: routerAddressVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewNetworkValueNull() NetworkValue { - return NetworkValue{ - state: attr.ValueStateNull, - } -} - -func NewNetworkValueUnknown() NetworkValue { - return NetworkValue{ - state: attr.ValueStateUnknown, - } -} - -func NewNetworkValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (NetworkValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing NetworkValue Attribute Value", - "While creating a NetworkValue value, a missing attribute value was detected. "+ - "A NetworkValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("NetworkValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid NetworkValue Attribute Type", - "While creating a NetworkValue value, an invalid attribute value was detected. "+ - "A NetworkValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("NetworkValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("NetworkValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra NetworkValue Attribute Value", - "While creating a NetworkValue value, an extra attribute value was detected. "+ - "A NetworkValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra NetworkValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewNetworkValueUnknown(), diags - } - - accessScopeAttribute, ok := attributes["access_scope"] - - if !ok { - diags.AddError( - "Attribute Missing", - `access_scope is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - accessScopeVal, ok := accessScopeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`access_scope expected to be basetypes.StringValue, was: %T`, accessScopeAttribute)) - } - - aclAttribute, ok := attributes["acl"] - - if !ok { - diags.AddError( - "Attribute Missing", - `acl is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - aclVal, ok := aclAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`acl expected to be basetypes.ListValue, was: %T`, aclAttribute)) - } - - instanceAddressAttribute, ok := attributes["instance_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `instance_address is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - instanceAddressVal, ok := instanceAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`instance_address expected to be basetypes.StringValue, was: %T`, instanceAddressAttribute)) - } - - routerAddressAttribute, ok := attributes["router_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `router_address is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - routerAddressVal, ok := routerAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`router_address expected to be basetypes.StringValue, was: %T`, routerAddressAttribute)) - } - - if diags.HasError() { - return NewNetworkValueUnknown(), diags - } - - return NetworkValue{ - AccessScope: accessScopeVal, - Acl: aclVal, - InstanceAddress: instanceAddressVal, - RouterAddress: routerAddressVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewNetworkValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) NetworkValue { - object, diags := NewNetworkValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewNetworkValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t NetworkType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewNetworkValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewNetworkValueUnknown(), nil - } - - if in.IsNull() { - return NewNetworkValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewNetworkValueMust(NetworkValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t NetworkType) ValueType(ctx context.Context) attr.Value { - return NetworkValue{} -} - -var _ basetypes.ObjectValuable = NetworkValue{} - -type NetworkValue struct { - AccessScope basetypes.StringValue `tfsdk:"access_scope"` - Acl basetypes.ListValue `tfsdk:"acl"` - InstanceAddress basetypes.StringValue `tfsdk:"instance_address"` - RouterAddress basetypes.StringValue `tfsdk:"router_address"` - state attr.ValueState -} - -func (v NetworkValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 4) - - var val tftypes.Value - var err error - - attrTypes["access_scope"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["acl"] = basetypes.ListType{ - ElemType: types.StringType, - }.TerraformType(ctx) - attrTypes["instance_address"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["router_address"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 4) - - val, err = v.AccessScope.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["access_scope"] = val - - val, err = v.Acl.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["acl"] = val - - val, err = v.InstanceAddress.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["instance_address"] = val - - val, err = v.RouterAddress.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["router_address"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v NetworkValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v NetworkValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v NetworkValue) String() string { - return "NetworkValue" -} - -func (v NetworkValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - var aclVal basetypes.ListValue - switch { - case v.Acl.IsUnknown(): - aclVal = types.ListUnknown(types.StringType) - case v.Acl.IsNull(): - aclVal = types.ListNull(types.StringType) - default: - var d diag.Diagnostics - aclVal, d = types.ListValue(types.StringType, v.Acl.Elements()) - diags.Append(d...) - } - - if diags.HasError() { - return types.ObjectUnknown(map[string]attr.Type{ - "access_scope": basetypes.StringType{}, - "acl": basetypes.ListType{ - ElemType: types.StringType, - }, - "instance_address": basetypes.StringType{}, - "router_address": basetypes.StringType{}, - }), diags - } - - attributeTypes := map[string]attr.Type{ - "access_scope": basetypes.StringType{}, - "acl": basetypes.ListType{ - ElemType: types.StringType, - }, - "instance_address": basetypes.StringType{}, - "router_address": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "access_scope": v.AccessScope, - "acl": aclVal, - "instance_address": v.InstanceAddress, - "router_address": v.RouterAddress, - }) - - return objVal, diags -} - -func (v NetworkValue) Equal(o attr.Value) bool { - other, ok := o.(NetworkValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.AccessScope.Equal(other.AccessScope) { - return false - } - - if !v.Acl.Equal(other.Acl) { - return false - } - - if !v.InstanceAddress.Equal(other.InstanceAddress) { - return false - } - - if !v.RouterAddress.Equal(other.RouterAddress) { - return false - } - - return true -} - -func (v NetworkValue) Type(ctx context.Context) attr.Type { - return NetworkType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v NetworkValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "access_scope": basetypes.StringType{}, - "acl": basetypes.ListType{ - ElemType: types.StringType, - }, - "instance_address": basetypes.StringType{}, - "router_address": basetypes.StringType{}, - } -} - -var _ basetypes.ObjectTypable = StorageType{} - -type StorageType struct { - basetypes.ObjectType -} - -func (t StorageType) Equal(o attr.Type) bool { - other, ok := o.(StorageType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t StorageType) String() string { - return "StorageType" -} - -func (t StorageType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - performanceClassAttribute, ok := attributes["performance_class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `performance_class is missing from object`) - - return nil, diags - } - - performanceClassVal, ok := performanceClassAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`performance_class expected to be basetypes.StringValue, was: %T`, performanceClassAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return StorageValue{ - PerformanceClass: performanceClassVal, - Size: sizeVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageValueNull() StorageValue { - return StorageValue{ - state: attr.ValueStateNull, - } -} - -func NewStorageValueUnknown() StorageValue { - return StorageValue{ - state: attr.ValueStateUnknown, - } -} - -func NewStorageValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (StorageValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing StorageValue Attribute Value", - "While creating a StorageValue value, a missing attribute value was detected. "+ - "A StorageValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid StorageValue Attribute Type", - "While creating a StorageValue value, an invalid attribute value was detected. "+ - "A StorageValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("StorageValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra StorageValue Attribute Value", - "While creating a StorageValue value, an extra attribute value was detected. "+ - "A StorageValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra StorageValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewStorageValueUnknown(), diags - } - - performanceClassAttribute, ok := attributes["performance_class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `performance_class is missing from object`) - - return NewStorageValueUnknown(), diags - } - - performanceClassVal, ok := performanceClassAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`performance_class expected to be basetypes.StringValue, was: %T`, performanceClassAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewStorageValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - if diags.HasError() { - return NewStorageValueUnknown(), diags - } - - return StorageValue{ - PerformanceClass: performanceClassVal, - Size: sizeVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) StorageValue { - object, diags := NewStorageValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewStorageValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t StorageType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewStorageValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewStorageValueUnknown(), nil - } - - if in.IsNull() { - return NewStorageValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewStorageValueMust(StorageValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t StorageType) ValueType(ctx context.Context) attr.Value { - return StorageValue{} -} - -var _ basetypes.ObjectValuable = StorageValue{} - -type StorageValue struct { - PerformanceClass basetypes.StringValue `tfsdk:"performance_class"` - Size basetypes.Int64Value `tfsdk:"size"` - state attr.ValueState -} - -func (v StorageValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 2) - - var val tftypes.Value - var err error - - attrTypes["performance_class"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 2) - - val, err = v.PerformanceClass.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["performance_class"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v StorageValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v StorageValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v StorageValue) String() string { - return "StorageValue" -} - -func (v StorageValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "performance_class": basetypes.StringType{}, - "size": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "performance_class": v.PerformanceClass, - "size": v.Size, - }) - - return objVal, diags -} - -func (v StorageValue) Equal(o attr.Value) bool { - other, ok := o.(StorageValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.PerformanceClass.Equal(other.PerformanceClass) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - return true -} - -func (v StorageValue) Type(ctx context.Context) attr.Type { - return StorageType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v StorageValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "performance_class": basetypes.StringType{}, - "size": basetypes.Int64Type{}, - } -} diff --git a/stackit/internal/services/postgresflexalpha/instance/datasources_gen/instances_data_source_gen.go b/stackit/internal/services/postgresflexalpha/instance/datasources_gen/instances_data_source_gen.go deleted file mode 100644 index beb620dd..00000000 --- a/stackit/internal/services/postgresflexalpha/instance/datasources_gen/instances_data_source_gen.go +++ /dev/null @@ -1,1174 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package postgresflexalpha - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -func InstancesDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "instances": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "id": schema.StringAttribute{ - Computed: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "is_deletable": schema.BoolAttribute{ - Computed: true, - Description: "Whether the instance can be deleted or not.", - MarkdownDescription: "Whether the instance can be deleted or not.", - }, - "name": schema.StringAttribute{ - Computed: true, - Description: "The name of the instance.", - MarkdownDescription: "The name of the instance.", - }, - "status": schema.StringAttribute{ - Computed: true, - Description: "The current status of the instance.", - MarkdownDescription: "The current status of the instance.", - }, - }, - CustomType: InstancesType{ - ObjectType: types.ObjectType{ - AttrTypes: InstancesValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "List of owned instances and their current status.", - MarkdownDescription: "List of owned instances and their current status.", - }, - "page": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of the page of items list to be returned.", - MarkdownDescription: "Number of the page of items list to be returned.", - }, - "pagination": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "page": schema.Int64Attribute{ - Computed: true, - }, - "size": schema.Int64Attribute{ - Computed: true, - }, - "sort": schema.StringAttribute{ - Computed: true, - }, - "total_pages": schema.Int64Attribute{ - Computed: true, - }, - "total_rows": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: PaginationType{ - ObjectType: types.ObjectType{ - AttrTypes: PaginationValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - }, - "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", - ), - }, - }, - "size": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of items to be returned on each page.", - MarkdownDescription: "Number of items to be returned on each page.", - }, - "sort": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "Sorting of the items to be returned on each page.", - MarkdownDescription: "Sorting of the items to be returned on each page.", - Validators: []validator.String{ - stringvalidator.OneOf( - "index.desc", - "index.asc", - "id.desc", - "id.asc", - "is_deletable.desc", - "is_deletable.asc", - "name.asc", - "name.desc", - "status.asc", - "status.desc", - ), - }, - }, - }, - } -} - -type InstancesModel struct { - Instances types.List `tfsdk:"instances"` - Page types.Int64 `tfsdk:"page"` - Pagination PaginationValue `tfsdk:"pagination"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Size types.Int64 `tfsdk:"size"` - Sort types.String `tfsdk:"sort"` -} - -var _ basetypes.ObjectTypable = InstancesType{} - -type InstancesType struct { - basetypes.ObjectType -} - -func (t InstancesType) Equal(o attr.Type) bool { - other, ok := o.(InstancesType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t InstancesType) String() string { - return "InstancesType" -} - -func (t InstancesType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return nil, diags - } - - idVal, ok := idAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.StringValue, was: %T`, idAttribute)) - } - - isDeletableAttribute, ok := attributes["is_deletable"] - - if !ok { - diags.AddError( - "Attribute Missing", - `is_deletable is missing from object`) - - return nil, diags - } - - isDeletableVal, ok := isDeletableAttribute.(basetypes.BoolValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`is_deletable expected to be basetypes.BoolValue, was: %T`, isDeletableAttribute)) - } - - nameAttribute, ok := attributes["name"] - - if !ok { - diags.AddError( - "Attribute Missing", - `name is missing from object`) - - return nil, diags - } - - nameVal, ok := nameAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`name expected to be basetypes.StringValue, was: %T`, nameAttribute)) - } - - statusAttribute, ok := attributes["status"] - - if !ok { - diags.AddError( - "Attribute Missing", - `status is missing from object`) - - return nil, diags - } - - statusVal, ok := statusAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`status expected to be basetypes.StringValue, was: %T`, statusAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return InstancesValue{ - Id: idVal, - IsDeletable: isDeletableVal, - Name: nameVal, - Status: statusVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewInstancesValueNull() InstancesValue { - return InstancesValue{ - state: attr.ValueStateNull, - } -} - -func NewInstancesValueUnknown() InstancesValue { - return InstancesValue{ - state: attr.ValueStateUnknown, - } -} - -func NewInstancesValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (InstancesValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing InstancesValue Attribute Value", - "While creating a InstancesValue value, a missing attribute value was detected. "+ - "A InstancesValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("InstancesValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid InstancesValue Attribute Type", - "While creating a InstancesValue value, an invalid attribute value was detected. "+ - "A InstancesValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("InstancesValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("InstancesValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra InstancesValue Attribute Value", - "While creating a InstancesValue value, an extra attribute value was detected. "+ - "A InstancesValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra InstancesValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewInstancesValueUnknown(), diags - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return NewInstancesValueUnknown(), diags - } - - idVal, ok := idAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.StringValue, was: %T`, idAttribute)) - } - - isDeletableAttribute, ok := attributes["is_deletable"] - - if !ok { - diags.AddError( - "Attribute Missing", - `is_deletable is missing from object`) - - return NewInstancesValueUnknown(), diags - } - - isDeletableVal, ok := isDeletableAttribute.(basetypes.BoolValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`is_deletable expected to be basetypes.BoolValue, was: %T`, isDeletableAttribute)) - } - - nameAttribute, ok := attributes["name"] - - if !ok { - diags.AddError( - "Attribute Missing", - `name is missing from object`) - - return NewInstancesValueUnknown(), diags - } - - nameVal, ok := nameAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`name expected to be basetypes.StringValue, was: %T`, nameAttribute)) - } - - statusAttribute, ok := attributes["status"] - - if !ok { - diags.AddError( - "Attribute Missing", - `status is missing from object`) - - return NewInstancesValueUnknown(), diags - } - - statusVal, ok := statusAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`status expected to be basetypes.StringValue, was: %T`, statusAttribute)) - } - - if diags.HasError() { - return NewInstancesValueUnknown(), diags - } - - return InstancesValue{ - Id: idVal, - IsDeletable: isDeletableVal, - Name: nameVal, - Status: statusVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewInstancesValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) InstancesValue { - object, diags := NewInstancesValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewInstancesValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t InstancesType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewInstancesValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewInstancesValueUnknown(), nil - } - - if in.IsNull() { - return NewInstancesValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewInstancesValueMust(InstancesValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t InstancesType) ValueType(ctx context.Context) attr.Value { - return InstancesValue{} -} - -var _ basetypes.ObjectValuable = InstancesValue{} - -type InstancesValue struct { - Id basetypes.StringValue `tfsdk:"id"` - IsDeletable basetypes.BoolValue `tfsdk:"is_deletable"` - Name basetypes.StringValue `tfsdk:"name"` - Status basetypes.StringValue `tfsdk:"status"` - state attr.ValueState -} - -func (v InstancesValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 4) - - var val tftypes.Value - var err error - - attrTypes["id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["is_deletable"] = basetypes.BoolType{}.TerraformType(ctx) - attrTypes["name"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["status"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 4) - - val, err = v.Id.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["id"] = val - - val, err = v.IsDeletable.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["is_deletable"] = val - - val, err = v.Name.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["name"] = val - - val, err = v.Status.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["status"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v InstancesValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v InstancesValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v InstancesValue) String() string { - return "InstancesValue" -} - -func (v InstancesValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "id": basetypes.StringType{}, - "is_deletable": basetypes.BoolType{}, - "name": basetypes.StringType{}, - "status": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "id": v.Id, - "is_deletable": v.IsDeletable, - "name": v.Name, - "status": v.Status, - }) - - return objVal, diags -} - -func (v InstancesValue) Equal(o attr.Value) bool { - other, ok := o.(InstancesValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Id.Equal(other.Id) { - return false - } - - if !v.IsDeletable.Equal(other.IsDeletable) { - return false - } - - if !v.Name.Equal(other.Name) { - return false - } - - if !v.Status.Equal(other.Status) { - return false - } - - return true -} - -func (v InstancesValue) Type(ctx context.Context) attr.Type { - return InstancesType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v InstancesValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "id": basetypes.StringType{}, - "is_deletable": basetypes.BoolType{}, - "name": basetypes.StringType{}, - "status": basetypes.StringType{}, - } -} - -var _ basetypes.ObjectTypable = PaginationType{} - -type PaginationType struct { - basetypes.ObjectType -} - -func (t PaginationType) Equal(o attr.Type) bool { - other, ok := o.(PaginationType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t PaginationType) String() string { - return "PaginationType" -} - -func (t PaginationType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return nil, diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return nil, diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return nil, diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return nil, diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueNull() PaginationValue { - return PaginationValue{ - state: attr.ValueStateNull, - } -} - -func NewPaginationValueUnknown() PaginationValue { - return PaginationValue{ - state: attr.ValueStateUnknown, - } -} - -func NewPaginationValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (PaginationValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing PaginationValue Attribute Value", - "While creating a PaginationValue value, a missing attribute value was detected. "+ - "A PaginationValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid PaginationValue Attribute Type", - "While creating a PaginationValue value, an invalid attribute value was detected. "+ - "A PaginationValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra PaginationValue Attribute Value", - "While creating a PaginationValue value, an extra attribute value was detected. "+ - "A PaginationValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra PaginationValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) PaginationValue { - object, diags := NewPaginationValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewPaginationValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t PaginationType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewPaginationValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewPaginationValueUnknown(), nil - } - - if in.IsNull() { - return NewPaginationValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewPaginationValueMust(PaginationValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t PaginationType) ValueType(ctx context.Context) attr.Value { - return PaginationValue{} -} - -var _ basetypes.ObjectValuable = PaginationValue{} - -type PaginationValue struct { - Page basetypes.Int64Value `tfsdk:"page"` - Size basetypes.Int64Value `tfsdk:"size"` - Sort basetypes.StringValue `tfsdk:"sort"` - TotalPages basetypes.Int64Value `tfsdk:"total_pages"` - TotalRows basetypes.Int64Value `tfsdk:"total_rows"` - state attr.ValueState -} - -func (v PaginationValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 5) - - var val tftypes.Value - var err error - - attrTypes["page"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["sort"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["total_pages"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["total_rows"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 5) - - val, err = v.Page.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["page"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - val, err = v.Sort.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["sort"] = val - - val, err = v.TotalPages.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_pages"] = val - - val, err = v.TotalRows.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_rows"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v PaginationValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v PaginationValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v PaginationValue) String() string { - return "PaginationValue" -} - -func (v PaginationValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "page": v.Page, - "size": v.Size, - "sort": v.Sort, - "total_pages": v.TotalPages, - "total_rows": v.TotalRows, - }) - - return objVal, diags -} - -func (v PaginationValue) Equal(o attr.Value) bool { - other, ok := o.(PaginationValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Page.Equal(other.Page) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - if !v.Sort.Equal(other.Sort) { - return false - } - - if !v.TotalPages.Equal(other.TotalPages) { - return false - } - - if !v.TotalRows.Equal(other.TotalRows) { - return false - } - - return true -} - -func (v PaginationValue) Type(ctx context.Context) attr.Type { - return PaginationType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v PaginationValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } -} diff --git a/stackit/internal/services/postgresflexalpha/instance/resources_gen/instance_resource_gen.go b/stackit/internal/services/postgresflexalpha/instance/resources_gen/instance_resource_gen.go deleted file mode 100644 index 35d31cbc..00000000 --- a/stackit/internal/services/postgresflexalpha/instance/resources_gen/instance_resource_gen.go +++ /dev/null @@ -1,2004 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package postgresflexalpha - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/resource/schema" -) - -func InstanceResourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "acl": schema.ListAttribute{ - ElementType: types.StringType, - Computed: true, - Description: "List of IPV4 cidr.", - MarkdownDescription: "List of IPV4 cidr.", - }, - "backup_schedule": schema.StringAttribute{ - Required: true, - Description: "The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.", - MarkdownDescription: "The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.", - }, - "connection_info": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "host": schema.StringAttribute{ - Computed: true, - Description: "The host of the instance.", - MarkdownDescription: "The host of the instance.", - }, - "port": schema.Int64Attribute{ - Computed: true, - Description: "The port of the instance.", - MarkdownDescription: "The port of the instance.", - }, - }, - CustomType: ConnectionInfoType{ - ObjectType: types.ObjectType{ - AttrTypes: ConnectionInfoValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - Description: "The DNS name and port in the instance overview", - MarkdownDescription: "The DNS name and port in the instance overview", - }, - "encryption": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "kek_key_id": schema.StringAttribute{ - Required: true, - Description: "The encryption-key key identifier", - MarkdownDescription: "The encryption-key key identifier", - }, - "kek_key_ring_id": schema.StringAttribute{ - Required: true, - Description: "The encryption-key keyring identifier", - MarkdownDescription: "The encryption-key keyring identifier", - }, - "kek_key_version": schema.StringAttribute{ - Required: true, - Description: "The encryption-key version", - MarkdownDescription: "The encryption-key version", - }, - "service_account": schema.StringAttribute{ - Required: true, - }, - }, - CustomType: EncryptionType{ - ObjectType: types.ObjectType{ - AttrTypes: EncryptionValue{}.AttributeTypes(ctx), - }, - }, - Optional: true, - Computed: true, - Description: "The configuration for instance's volume and backup storage encryption.\n\n⚠\ufe1d **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.\n", - MarkdownDescription: "The configuration for instance's volume and backup storage encryption.\n\n⚠\ufe1d **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.\n", - }, - "flavor_id": schema.StringAttribute{ - Required: true, - Description: "The id of the instance flavor.", - MarkdownDescription: "The id of the instance flavor.", - }, - "id": schema.StringAttribute{ - Computed: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "instance_id": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "is_deletable": schema.BoolAttribute{ - Computed: true, - Description: "Whether the instance can be deleted or not.", - MarkdownDescription: "Whether the instance can be deleted or not.", - }, - "name": schema.StringAttribute{ - Required: true, - Description: "The name of the instance.", - MarkdownDescription: "The name of the instance.", - }, - "network": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "access_scope": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "The access scope of the instance. It defines if the instance is public or airgapped.", - MarkdownDescription: "The access scope of the instance. It defines if the instance is public or airgapped.", - Validators: []validator.String{ - stringvalidator.OneOf( - "PUBLIC", - "SNA", - ), - }, - Default: stringdefault.StaticString("PUBLIC"), - }, - "acl": schema.ListAttribute{ - ElementType: types.StringType, - Required: true, - Description: "List of IPV4 cidr.", - MarkdownDescription: "List of IPV4 cidr.", - }, - "instance_address": schema.StringAttribute{ - Computed: true, - }, - "router_address": schema.StringAttribute{ - Computed: true, - }, - }, - CustomType: NetworkType{ - ObjectType: types.ObjectType{ - AttrTypes: NetworkValue{}.AttributeTypes(ctx), - }, - }, - Required: true, - Description: "The access configuration of the instance", - MarkdownDescription: "The access configuration of the instance", - }, - "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", - ), - }, - }, - "replicas": schema.Int64Attribute{ - Required: true, - Description: "How many replicas the instance should have.", - MarkdownDescription: "How many replicas the instance should have.", - Validators: []validator.Int64{ - int64validator.OneOf( - 1, - 3, - ), - }, - }, - "retention_days": schema.Int64Attribute{ - Required: true, - Description: "How long backups are retained. The value can only be between 32 and 365 days.", - MarkdownDescription: "How long backups are retained. The value can only be between 32 and 365 days.", - }, - "status": schema.StringAttribute{ - Computed: true, - Description: "The current status of the instance.", - MarkdownDescription: "The current status of the instance.", - }, - "storage": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "performance_class": schema.StringAttribute{ - Required: true, - Description: "The storage class for the storage.", - MarkdownDescription: "The storage class for the storage.", - }, - "size": schema.Int64Attribute{ - Required: true, - Description: "The storage size in Gigabytes.", - MarkdownDescription: "The storage size in Gigabytes.", - }, - }, - CustomType: StorageType{ - ObjectType: types.ObjectType{ - AttrTypes: StorageValue{}.AttributeTypes(ctx), - }, - }, - Required: true, - Description: "The object containing information about the storage size and class.", - MarkdownDescription: "The object containing information about the storage size and class.", - }, - "version": schema.StringAttribute{ - Required: true, - Description: "The Postgres version used for the instance. See [Versions Endpoint](/documentation/postgres-flex-service/version/v3alpha1#tag/Version) for supported version parameters.", - MarkdownDescription: "The Postgres version used for the instance. See [Versions Endpoint](/documentation/postgres-flex-service/version/v3alpha1#tag/Version) for supported version parameters.", - }, - }, - } -} - -type InstanceModel struct { - Acl types.List `tfsdk:"acl"` - BackupSchedule types.String `tfsdk:"backup_schedule"` - ConnectionInfo ConnectionInfoValue `tfsdk:"connection_info"` - Encryption EncryptionValue `tfsdk:"encryption"` - FlavorId types.String `tfsdk:"flavor_id"` - Id types.String `tfsdk:"id"` - InstanceId types.String `tfsdk:"instance_id"` - IsDeletable types.Bool `tfsdk:"is_deletable"` - Name types.String `tfsdk:"name"` - Network NetworkValue `tfsdk:"network"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Replicas types.Int64 `tfsdk:"replicas"` - RetentionDays types.Int64 `tfsdk:"retention_days"` - Status types.String `tfsdk:"status"` - Storage StorageValue `tfsdk:"storage"` - Version types.String `tfsdk:"version"` -} - -var _ basetypes.ObjectTypable = ConnectionInfoType{} - -type ConnectionInfoType struct { - basetypes.ObjectType -} - -func (t ConnectionInfoType) Equal(o attr.Type) bool { - other, ok := o.(ConnectionInfoType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t ConnectionInfoType) String() string { - return "ConnectionInfoType" -} - -func (t ConnectionInfoType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - hostAttribute, ok := attributes["host"] - - if !ok { - diags.AddError( - "Attribute Missing", - `host is missing from object`) - - return nil, diags - } - - hostVal, ok := hostAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`host expected to be basetypes.StringValue, was: %T`, hostAttribute)) - } - - portAttribute, ok := attributes["port"] - - if !ok { - diags.AddError( - "Attribute Missing", - `port is missing from object`) - - return nil, diags - } - - portVal, ok := portAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`port expected to be basetypes.Int64Value, was: %T`, portAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return ConnectionInfoValue{ - Host: hostVal, - Port: portVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewConnectionInfoValueNull() ConnectionInfoValue { - return ConnectionInfoValue{ - state: attr.ValueStateNull, - } -} - -func NewConnectionInfoValueUnknown() ConnectionInfoValue { - return ConnectionInfoValue{ - state: attr.ValueStateUnknown, - } -} - -func NewConnectionInfoValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (ConnectionInfoValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing ConnectionInfoValue Attribute Value", - "While creating a ConnectionInfoValue value, a missing attribute value was detected. "+ - "A ConnectionInfoValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("ConnectionInfoValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid ConnectionInfoValue Attribute Type", - "While creating a ConnectionInfoValue value, an invalid attribute value was detected. "+ - "A ConnectionInfoValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("ConnectionInfoValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("ConnectionInfoValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra ConnectionInfoValue Attribute Value", - "While creating a ConnectionInfoValue value, an extra attribute value was detected. "+ - "A ConnectionInfoValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra ConnectionInfoValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewConnectionInfoValueUnknown(), diags - } - - hostAttribute, ok := attributes["host"] - - if !ok { - diags.AddError( - "Attribute Missing", - `host is missing from object`) - - return NewConnectionInfoValueUnknown(), diags - } - - hostVal, ok := hostAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`host expected to be basetypes.StringValue, was: %T`, hostAttribute)) - } - - portAttribute, ok := attributes["port"] - - if !ok { - diags.AddError( - "Attribute Missing", - `port is missing from object`) - - return NewConnectionInfoValueUnknown(), diags - } - - portVal, ok := portAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`port expected to be basetypes.Int64Value, was: %T`, portAttribute)) - } - - if diags.HasError() { - return NewConnectionInfoValueUnknown(), diags - } - - return ConnectionInfoValue{ - Host: hostVal, - Port: portVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewConnectionInfoValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) ConnectionInfoValue { - object, diags := NewConnectionInfoValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewConnectionInfoValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t ConnectionInfoType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewConnectionInfoValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewConnectionInfoValueUnknown(), nil - } - - if in.IsNull() { - return NewConnectionInfoValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewConnectionInfoValueMust(ConnectionInfoValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t ConnectionInfoType) ValueType(ctx context.Context) attr.Value { - return ConnectionInfoValue{} -} - -var _ basetypes.ObjectValuable = ConnectionInfoValue{} - -type ConnectionInfoValue struct { - Host basetypes.StringValue `tfsdk:"host"` - Port basetypes.Int64Value `tfsdk:"port"` - state attr.ValueState -} - -func (v ConnectionInfoValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 2) - - var val tftypes.Value - var err error - - attrTypes["host"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["port"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 2) - - val, err = v.Host.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["host"] = val - - val, err = v.Port.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["port"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v ConnectionInfoValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v ConnectionInfoValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v ConnectionInfoValue) String() string { - return "ConnectionInfoValue" -} - -func (v ConnectionInfoValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "host": basetypes.StringType{}, - "port": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "host": v.Host, - "port": v.Port, - }) - - return objVal, diags -} - -func (v ConnectionInfoValue) Equal(o attr.Value) bool { - other, ok := o.(ConnectionInfoValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Host.Equal(other.Host) { - return false - } - - if !v.Port.Equal(other.Port) { - return false - } - - return true -} - -func (v ConnectionInfoValue) Type(ctx context.Context) attr.Type { - return ConnectionInfoType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v ConnectionInfoValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "host": basetypes.StringType{}, - "port": basetypes.Int64Type{}, - } -} - -var _ basetypes.ObjectTypable = EncryptionType{} - -type EncryptionType struct { - basetypes.ObjectType -} - -func (t EncryptionType) Equal(o attr.Type) bool { - other, ok := o.(EncryptionType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t EncryptionType) String() string { - return "EncryptionType" -} - -func (t EncryptionType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - kekKeyIdAttribute, ok := attributes["kek_key_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_id is missing from object`) - - return nil, diags - } - - kekKeyIdVal, ok := kekKeyIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_id expected to be basetypes.StringValue, was: %T`, kekKeyIdAttribute)) - } - - kekKeyRingIdAttribute, ok := attributes["kek_key_ring_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_ring_id is missing from object`) - - return nil, diags - } - - kekKeyRingIdVal, ok := kekKeyRingIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_ring_id expected to be basetypes.StringValue, was: %T`, kekKeyRingIdAttribute)) - } - - kekKeyVersionAttribute, ok := attributes["kek_key_version"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_version is missing from object`) - - return nil, diags - } - - kekKeyVersionVal, ok := kekKeyVersionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_version expected to be basetypes.StringValue, was: %T`, kekKeyVersionAttribute)) - } - - serviceAccountAttribute, ok := attributes["service_account"] - - if !ok { - diags.AddError( - "Attribute Missing", - `service_account is missing from object`) - - return nil, diags - } - - serviceAccountVal, ok := serviceAccountAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`service_account expected to be basetypes.StringValue, was: %T`, serviceAccountAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return EncryptionValue{ - KekKeyId: kekKeyIdVal, - KekKeyRingId: kekKeyRingIdVal, - KekKeyVersion: kekKeyVersionVal, - ServiceAccount: serviceAccountVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewEncryptionValueNull() EncryptionValue { - return EncryptionValue{ - state: attr.ValueStateNull, - } -} - -func NewEncryptionValueUnknown() EncryptionValue { - return EncryptionValue{ - state: attr.ValueStateUnknown, - } -} - -func NewEncryptionValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (EncryptionValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing EncryptionValue Attribute Value", - "While creating a EncryptionValue value, a missing attribute value was detected. "+ - "A EncryptionValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("EncryptionValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid EncryptionValue Attribute Type", - "While creating a EncryptionValue value, an invalid attribute value was detected. "+ - "A EncryptionValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("EncryptionValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("EncryptionValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra EncryptionValue Attribute Value", - "While creating a EncryptionValue value, an extra attribute value was detected. "+ - "A EncryptionValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra EncryptionValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewEncryptionValueUnknown(), diags - } - - kekKeyIdAttribute, ok := attributes["kek_key_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_id is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - kekKeyIdVal, ok := kekKeyIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_id expected to be basetypes.StringValue, was: %T`, kekKeyIdAttribute)) - } - - kekKeyRingIdAttribute, ok := attributes["kek_key_ring_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_ring_id is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - kekKeyRingIdVal, ok := kekKeyRingIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_ring_id expected to be basetypes.StringValue, was: %T`, kekKeyRingIdAttribute)) - } - - kekKeyVersionAttribute, ok := attributes["kek_key_version"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_version is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - kekKeyVersionVal, ok := kekKeyVersionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_version expected to be basetypes.StringValue, was: %T`, kekKeyVersionAttribute)) - } - - serviceAccountAttribute, ok := attributes["service_account"] - - if !ok { - diags.AddError( - "Attribute Missing", - `service_account is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - serviceAccountVal, ok := serviceAccountAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`service_account expected to be basetypes.StringValue, was: %T`, serviceAccountAttribute)) - } - - if diags.HasError() { - return NewEncryptionValueUnknown(), diags - } - - return EncryptionValue{ - KekKeyId: kekKeyIdVal, - KekKeyRingId: kekKeyRingIdVal, - KekKeyVersion: kekKeyVersionVal, - ServiceAccount: serviceAccountVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewEncryptionValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) EncryptionValue { - object, diags := NewEncryptionValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewEncryptionValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t EncryptionType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewEncryptionValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewEncryptionValueUnknown(), nil - } - - if in.IsNull() { - return NewEncryptionValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewEncryptionValueMust(EncryptionValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t EncryptionType) ValueType(ctx context.Context) attr.Value { - return EncryptionValue{} -} - -var _ basetypes.ObjectValuable = EncryptionValue{} - -type EncryptionValue struct { - KekKeyId basetypes.StringValue `tfsdk:"kek_key_id"` - KekKeyRingId basetypes.StringValue `tfsdk:"kek_key_ring_id"` - KekKeyVersion basetypes.StringValue `tfsdk:"kek_key_version"` - ServiceAccount basetypes.StringValue `tfsdk:"service_account"` - state attr.ValueState -} - -func (v EncryptionValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 4) - - var val tftypes.Value - var err error - - attrTypes["kek_key_id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["kek_key_ring_id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["kek_key_version"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["service_account"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 4) - - val, err = v.KekKeyId.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["kek_key_id"] = val - - val, err = v.KekKeyRingId.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["kek_key_ring_id"] = val - - val, err = v.KekKeyVersion.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["kek_key_version"] = val - - val, err = v.ServiceAccount.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["service_account"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v EncryptionValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v EncryptionValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v EncryptionValue) String() string { - return "EncryptionValue" -} - -func (v EncryptionValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "kek_key_id": basetypes.StringType{}, - "kek_key_ring_id": basetypes.StringType{}, - "kek_key_version": basetypes.StringType{}, - "service_account": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "kek_key_id": v.KekKeyId, - "kek_key_ring_id": v.KekKeyRingId, - "kek_key_version": v.KekKeyVersion, - "service_account": v.ServiceAccount, - }) - - return objVal, diags -} - -func (v EncryptionValue) Equal(o attr.Value) bool { - other, ok := o.(EncryptionValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.KekKeyId.Equal(other.KekKeyId) { - return false - } - - if !v.KekKeyRingId.Equal(other.KekKeyRingId) { - return false - } - - if !v.KekKeyVersion.Equal(other.KekKeyVersion) { - return false - } - - if !v.ServiceAccount.Equal(other.ServiceAccount) { - return false - } - - return true -} - -func (v EncryptionValue) Type(ctx context.Context) attr.Type { - return EncryptionType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v EncryptionValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "kek_key_id": basetypes.StringType{}, - "kek_key_ring_id": basetypes.StringType{}, - "kek_key_version": basetypes.StringType{}, - "service_account": basetypes.StringType{}, - } -} - -var _ basetypes.ObjectTypable = NetworkType{} - -type NetworkType struct { - basetypes.ObjectType -} - -func (t NetworkType) Equal(o attr.Type) bool { - other, ok := o.(NetworkType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t NetworkType) String() string { - return "NetworkType" -} - -func (t NetworkType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - accessScopeAttribute, ok := attributes["access_scope"] - - if !ok { - diags.AddError( - "Attribute Missing", - `access_scope is missing from object`) - - return nil, diags - } - - accessScopeVal, ok := accessScopeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`access_scope expected to be basetypes.StringValue, was: %T`, accessScopeAttribute)) - } - - aclAttribute, ok := attributes["acl"] - - if !ok { - diags.AddError( - "Attribute Missing", - `acl is missing from object`) - - return nil, diags - } - - aclVal, ok := aclAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`acl expected to be basetypes.ListValue, was: %T`, aclAttribute)) - } - - instanceAddressAttribute, ok := attributes["instance_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `instance_address is missing from object`) - - return nil, diags - } - - instanceAddressVal, ok := instanceAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`instance_address expected to be basetypes.StringValue, was: %T`, instanceAddressAttribute)) - } - - routerAddressAttribute, ok := attributes["router_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `router_address is missing from object`) - - return nil, diags - } - - routerAddressVal, ok := routerAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`router_address expected to be basetypes.StringValue, was: %T`, routerAddressAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return NetworkValue{ - AccessScope: accessScopeVal, - Acl: aclVal, - InstanceAddress: instanceAddressVal, - RouterAddress: routerAddressVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewNetworkValueNull() NetworkValue { - return NetworkValue{ - state: attr.ValueStateNull, - } -} - -func NewNetworkValueUnknown() NetworkValue { - return NetworkValue{ - state: attr.ValueStateUnknown, - } -} - -func NewNetworkValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (NetworkValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing NetworkValue Attribute Value", - "While creating a NetworkValue value, a missing attribute value was detected. "+ - "A NetworkValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("NetworkValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid NetworkValue Attribute Type", - "While creating a NetworkValue value, an invalid attribute value was detected. "+ - "A NetworkValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("NetworkValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("NetworkValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra NetworkValue Attribute Value", - "While creating a NetworkValue value, an extra attribute value was detected. "+ - "A NetworkValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra NetworkValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewNetworkValueUnknown(), diags - } - - accessScopeAttribute, ok := attributes["access_scope"] - - if !ok { - diags.AddError( - "Attribute Missing", - `access_scope is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - accessScopeVal, ok := accessScopeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`access_scope expected to be basetypes.StringValue, was: %T`, accessScopeAttribute)) - } - - aclAttribute, ok := attributes["acl"] - - if !ok { - diags.AddError( - "Attribute Missing", - `acl is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - aclVal, ok := aclAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`acl expected to be basetypes.ListValue, was: %T`, aclAttribute)) - } - - instanceAddressAttribute, ok := attributes["instance_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `instance_address is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - instanceAddressVal, ok := instanceAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`instance_address expected to be basetypes.StringValue, was: %T`, instanceAddressAttribute)) - } - - routerAddressAttribute, ok := attributes["router_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `router_address is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - routerAddressVal, ok := routerAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`router_address expected to be basetypes.StringValue, was: %T`, routerAddressAttribute)) - } - - if diags.HasError() { - return NewNetworkValueUnknown(), diags - } - - return NetworkValue{ - AccessScope: accessScopeVal, - Acl: aclVal, - InstanceAddress: instanceAddressVal, - RouterAddress: routerAddressVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewNetworkValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) NetworkValue { - object, diags := NewNetworkValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewNetworkValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t NetworkType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewNetworkValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewNetworkValueUnknown(), nil - } - - if in.IsNull() { - return NewNetworkValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewNetworkValueMust(NetworkValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t NetworkType) ValueType(ctx context.Context) attr.Value { - return NetworkValue{} -} - -var _ basetypes.ObjectValuable = NetworkValue{} - -type NetworkValue struct { - AccessScope basetypes.StringValue `tfsdk:"access_scope"` - Acl basetypes.ListValue `tfsdk:"acl"` - InstanceAddress basetypes.StringValue `tfsdk:"instance_address"` - RouterAddress basetypes.StringValue `tfsdk:"router_address"` - state attr.ValueState -} - -func (v NetworkValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 4) - - var val tftypes.Value - var err error - - attrTypes["access_scope"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["acl"] = basetypes.ListType{ - ElemType: types.StringType, - }.TerraformType(ctx) - attrTypes["instance_address"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["router_address"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 4) - - val, err = v.AccessScope.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["access_scope"] = val - - val, err = v.Acl.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["acl"] = val - - val, err = v.InstanceAddress.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["instance_address"] = val - - val, err = v.RouterAddress.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["router_address"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v NetworkValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v NetworkValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v NetworkValue) String() string { - return "NetworkValue" -} - -func (v NetworkValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - var aclVal basetypes.ListValue - switch { - case v.Acl.IsUnknown(): - aclVal = types.ListUnknown(types.StringType) - case v.Acl.IsNull(): - aclVal = types.ListNull(types.StringType) - default: - var d diag.Diagnostics - aclVal, d = types.ListValue(types.StringType, v.Acl.Elements()) - diags.Append(d...) - } - - if diags.HasError() { - return types.ObjectUnknown(map[string]attr.Type{ - "access_scope": basetypes.StringType{}, - "acl": basetypes.ListType{ - ElemType: types.StringType, - }, - "instance_address": basetypes.StringType{}, - "router_address": basetypes.StringType{}, - }), diags - } - - attributeTypes := map[string]attr.Type{ - "access_scope": basetypes.StringType{}, - "acl": basetypes.ListType{ - ElemType: types.StringType, - }, - "instance_address": basetypes.StringType{}, - "router_address": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "access_scope": v.AccessScope, - "acl": aclVal, - "instance_address": v.InstanceAddress, - "router_address": v.RouterAddress, - }) - - return objVal, diags -} - -func (v NetworkValue) Equal(o attr.Value) bool { - other, ok := o.(NetworkValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.AccessScope.Equal(other.AccessScope) { - return false - } - - if !v.Acl.Equal(other.Acl) { - return false - } - - if !v.InstanceAddress.Equal(other.InstanceAddress) { - return false - } - - if !v.RouterAddress.Equal(other.RouterAddress) { - return false - } - - return true -} - -func (v NetworkValue) Type(ctx context.Context) attr.Type { - return NetworkType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v NetworkValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "access_scope": basetypes.StringType{}, - "acl": basetypes.ListType{ - ElemType: types.StringType, - }, - "instance_address": basetypes.StringType{}, - "router_address": basetypes.StringType{}, - } -} - -var _ basetypes.ObjectTypable = StorageType{} - -type StorageType struct { - basetypes.ObjectType -} - -func (t StorageType) Equal(o attr.Type) bool { - other, ok := o.(StorageType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t StorageType) String() string { - return "StorageType" -} - -func (t StorageType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - performanceClassAttribute, ok := attributes["performance_class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `performance_class is missing from object`) - - return nil, diags - } - - performanceClassVal, ok := performanceClassAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`performance_class expected to be basetypes.StringValue, was: %T`, performanceClassAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return StorageValue{ - PerformanceClass: performanceClassVal, - Size: sizeVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageValueNull() StorageValue { - return StorageValue{ - state: attr.ValueStateNull, - } -} - -func NewStorageValueUnknown() StorageValue { - return StorageValue{ - state: attr.ValueStateUnknown, - } -} - -func NewStorageValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (StorageValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing StorageValue Attribute Value", - "While creating a StorageValue value, a missing attribute value was detected. "+ - "A StorageValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid StorageValue Attribute Type", - "While creating a StorageValue value, an invalid attribute value was detected. "+ - "A StorageValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("StorageValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra StorageValue Attribute Value", - "While creating a StorageValue value, an extra attribute value was detected. "+ - "A StorageValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra StorageValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewStorageValueUnknown(), diags - } - - performanceClassAttribute, ok := attributes["performance_class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `performance_class is missing from object`) - - return NewStorageValueUnknown(), diags - } - - performanceClassVal, ok := performanceClassAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`performance_class expected to be basetypes.StringValue, was: %T`, performanceClassAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewStorageValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - if diags.HasError() { - return NewStorageValueUnknown(), diags - } - - return StorageValue{ - PerformanceClass: performanceClassVal, - Size: sizeVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) StorageValue { - object, diags := NewStorageValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewStorageValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t StorageType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewStorageValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewStorageValueUnknown(), nil - } - - if in.IsNull() { - return NewStorageValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewStorageValueMust(StorageValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t StorageType) ValueType(ctx context.Context) attr.Value { - return StorageValue{} -} - -var _ basetypes.ObjectValuable = StorageValue{} - -type StorageValue struct { - PerformanceClass basetypes.StringValue `tfsdk:"performance_class"` - Size basetypes.Int64Value `tfsdk:"size"` - state attr.ValueState -} - -func (v StorageValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 2) - - var val tftypes.Value - var err error - - attrTypes["performance_class"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 2) - - val, err = v.PerformanceClass.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["performance_class"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v StorageValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v StorageValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v StorageValue) String() string { - return "StorageValue" -} - -func (v StorageValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "performance_class": basetypes.StringType{}, - "size": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "performance_class": v.PerformanceClass, - "size": v.Size, - }) - - return objVal, diags -} - -func (v StorageValue) Equal(o attr.Value) bool { - other, ok := o.(StorageValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.PerformanceClass.Equal(other.PerformanceClass) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - return true -} - -func (v StorageValue) Type(ctx context.Context) attr.Type { - return StorageType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v StorageValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "performance_class": basetypes.StringType{}, - "size": basetypes.Int64Type{}, - } -} diff --git a/stackit/internal/services/postgresflexalpha/role/datasources_gen/roles_data_source_gen.go b/stackit/internal/services/postgresflexalpha/role/datasources_gen/roles_data_source_gen.go deleted file mode 100644 index 415f0647..00000000 --- a/stackit/internal/services/postgresflexalpha/role/datasources_gen/roles_data_source_gen.go +++ /dev/null @@ -1,52 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -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/datasource/schema" -) - -func RolesDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "instance_id": schema.StringAttribute{ - Required: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "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", - ), - }, - }, - "roles": schema.ListAttribute{ - ElementType: types.StringType, - Computed: true, - Description: "List of all role names available in the instance", - MarkdownDescription: "List of all role names available in the instance", - }, - }, - } -} - -type RolesModel struct { - InstanceId types.String `tfsdk:"instance_id"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Roles types.List `tfsdk:"roles"` -} diff --git a/stackit/internal/services/postgresflexalpha/user/datasources_gen/user_data_source_gen.go b/stackit/internal/services/postgresflexalpha/user/datasources_gen/user_data_source_gen.go deleted file mode 100644 index 29a7cca0..00000000 --- a/stackit/internal/services/postgresflexalpha/user/datasources_gen/user_data_source_gen.go +++ /dev/null @@ -1,76 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -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/datasource/schema" -) - -func UserDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "tf_original_api_id": schema.Int64Attribute{ - Computed: true, - Description: "The ID of the user.", - MarkdownDescription: "The ID of the user.", - }, - "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 user.", - MarkdownDescription: "The name of the user.", - }, - "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", - ), - }, - }, - "roles": schema.ListAttribute{ - ElementType: types.StringType, - Computed: true, - Description: "A list of user roles.", - MarkdownDescription: "A list of user roles.", - }, - "status": schema.StringAttribute{ - Computed: true, - Description: "The current status of the user.", - MarkdownDescription: "The current status of the user.", - }, - "user_id": schema.Int64Attribute{ - Required: true, - Description: "The ID of the user.", - MarkdownDescription: "The ID of the user.", - }, - }, - } -} - -type UserModel struct { - 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"` -} diff --git a/stackit/internal/services/postgresflexalpha/user/datasources_gen/users_data_source_gen.go b/stackit/internal/services/postgresflexalpha/user/datasources_gen/users_data_source_gen.go deleted file mode 100644 index b54a5dd6..00000000 --- a/stackit/internal/services/postgresflexalpha/user/datasources_gen/users_data_source_gen.go +++ /dev/null @@ -1,1118 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package postgresflexalpha - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -func UsersDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "instance_id": schema.StringAttribute{ - Required: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "page": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of the page of items list to be returned.", - MarkdownDescription: "Number of the page of items list to be returned.", - }, - "pagination": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "page": schema.Int64Attribute{ - Computed: true, - }, - "size": schema.Int64Attribute{ - Computed: true, - }, - "sort": schema.StringAttribute{ - Computed: true, - }, - "total_pages": schema.Int64Attribute{ - Computed: true, - }, - "total_rows": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: PaginationType{ - ObjectType: types.ObjectType{ - AttrTypes: PaginationValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - }, - "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", - ), - }, - }, - "size": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of items to be returned on each page.", - MarkdownDescription: "Number of items to be returned on each page.", - }, - "sort": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "Sorting of the users to be returned on each page.", - MarkdownDescription: "Sorting of the users to be returned on each page.", - Validators: []validator.String{ - stringvalidator.OneOf( - "id.asc", - "id.desc", - "index.desc", - "index.asc", - "name.desc", - "name.asc", - "status.desc", - "status.asc", - ), - }, - }, - "users": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "id": schema.Int64Attribute{ - Computed: true, - Description: "The ID of the user.", - MarkdownDescription: "The ID of the user.", - }, - "name": schema.StringAttribute{ - Computed: true, - Description: "The name of the user.", - MarkdownDescription: "The name of the user.", - }, - "status": schema.StringAttribute{ - Computed: true, - Description: "The current status of the user.", - MarkdownDescription: "The current status of the user.", - }, - }, - CustomType: UsersType{ - ObjectType: types.ObjectType{ - AttrTypes: UsersValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "List of all users inside an instance", - MarkdownDescription: "List of all users inside an instance", - }, - }, - } -} - -type UsersModel struct { - InstanceId types.String `tfsdk:"instance_id"` - Page types.Int64 `tfsdk:"page"` - Pagination PaginationValue `tfsdk:"pagination"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Size types.Int64 `tfsdk:"size"` - Sort types.String `tfsdk:"sort"` - Users types.List `tfsdk:"users"` -} - -var _ basetypes.ObjectTypable = PaginationType{} - -type PaginationType struct { - basetypes.ObjectType -} - -func (t PaginationType) Equal(o attr.Type) bool { - other, ok := o.(PaginationType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t PaginationType) String() string { - return "PaginationType" -} - -func (t PaginationType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return nil, diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return nil, diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return nil, diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return nil, diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueNull() PaginationValue { - return PaginationValue{ - state: attr.ValueStateNull, - } -} - -func NewPaginationValueUnknown() PaginationValue { - return PaginationValue{ - state: attr.ValueStateUnknown, - } -} - -func NewPaginationValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (PaginationValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing PaginationValue Attribute Value", - "While creating a PaginationValue value, a missing attribute value was detected. "+ - "A PaginationValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid PaginationValue Attribute Type", - "While creating a PaginationValue value, an invalid attribute value was detected. "+ - "A PaginationValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra PaginationValue Attribute Value", - "While creating a PaginationValue value, an extra attribute value was detected. "+ - "A PaginationValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra PaginationValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) PaginationValue { - object, diags := NewPaginationValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewPaginationValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t PaginationType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewPaginationValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewPaginationValueUnknown(), nil - } - - if in.IsNull() { - return NewPaginationValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewPaginationValueMust(PaginationValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t PaginationType) ValueType(ctx context.Context) attr.Value { - return PaginationValue{} -} - -var _ basetypes.ObjectValuable = PaginationValue{} - -type PaginationValue struct { - Page basetypes.Int64Value `tfsdk:"page"` - Size basetypes.Int64Value `tfsdk:"size"` - Sort basetypes.StringValue `tfsdk:"sort"` - TotalPages basetypes.Int64Value `tfsdk:"total_pages"` - TotalRows basetypes.Int64Value `tfsdk:"total_rows"` - state attr.ValueState -} - -func (v PaginationValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 5) - - var val tftypes.Value - var err error - - attrTypes["page"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["sort"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["total_pages"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["total_rows"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 5) - - val, err = v.Page.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["page"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - val, err = v.Sort.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["sort"] = val - - val, err = v.TotalPages.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_pages"] = val - - val, err = v.TotalRows.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_rows"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v PaginationValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v PaginationValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v PaginationValue) String() string { - return "PaginationValue" -} - -func (v PaginationValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "page": v.Page, - "size": v.Size, - "sort": v.Sort, - "total_pages": v.TotalPages, - "total_rows": v.TotalRows, - }) - - return objVal, diags -} - -func (v PaginationValue) Equal(o attr.Value) bool { - other, ok := o.(PaginationValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Page.Equal(other.Page) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - if !v.Sort.Equal(other.Sort) { - return false - } - - if !v.TotalPages.Equal(other.TotalPages) { - return false - } - - if !v.TotalRows.Equal(other.TotalRows) { - return false - } - - return true -} - -func (v PaginationValue) Type(ctx context.Context) attr.Type { - return PaginationType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v PaginationValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } -} - -var _ basetypes.ObjectTypable = UsersType{} - -type UsersType struct { - basetypes.ObjectType -} - -func (t UsersType) Equal(o attr.Type) bool { - other, ok := o.(UsersType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t UsersType) String() string { - return "UsersType" -} - -func (t UsersType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return nil, diags - } - - idVal, ok := idAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.Int64Value, was: %T`, idAttribute)) - } - - nameAttribute, ok := attributes["name"] - - if !ok { - diags.AddError( - "Attribute Missing", - `name is missing from object`) - - return nil, diags - } - - nameVal, ok := nameAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`name expected to be basetypes.StringValue, was: %T`, nameAttribute)) - } - - statusAttribute, ok := attributes["status"] - - if !ok { - diags.AddError( - "Attribute Missing", - `status is missing from object`) - - return nil, diags - } - - statusVal, ok := statusAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`status expected to be basetypes.StringValue, was: %T`, statusAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return UsersValue{ - Id: idVal, - Name: nameVal, - Status: statusVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewUsersValueNull() UsersValue { - return UsersValue{ - state: attr.ValueStateNull, - } -} - -func NewUsersValueUnknown() UsersValue { - return UsersValue{ - state: attr.ValueStateUnknown, - } -} - -func NewUsersValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (UsersValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing UsersValue Attribute Value", - "While creating a UsersValue value, a missing attribute value was detected. "+ - "A UsersValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("UsersValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid UsersValue Attribute Type", - "While creating a UsersValue value, an invalid attribute value was detected. "+ - "A UsersValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("UsersValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("UsersValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra UsersValue Attribute Value", - "While creating a UsersValue value, an extra attribute value was detected. "+ - "A UsersValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra UsersValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewUsersValueUnknown(), diags - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return NewUsersValueUnknown(), diags - } - - idVal, ok := idAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.Int64Value, was: %T`, idAttribute)) - } - - nameAttribute, ok := attributes["name"] - - if !ok { - diags.AddError( - "Attribute Missing", - `name is missing from object`) - - return NewUsersValueUnknown(), diags - } - - nameVal, ok := nameAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`name expected to be basetypes.StringValue, was: %T`, nameAttribute)) - } - - statusAttribute, ok := attributes["status"] - - if !ok { - diags.AddError( - "Attribute Missing", - `status is missing from object`) - - return NewUsersValueUnknown(), diags - } - - statusVal, ok := statusAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`status expected to be basetypes.StringValue, was: %T`, statusAttribute)) - } - - if diags.HasError() { - return NewUsersValueUnknown(), diags - } - - return UsersValue{ - Id: idVal, - Name: nameVal, - Status: statusVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewUsersValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) UsersValue { - object, diags := NewUsersValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewUsersValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t UsersType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewUsersValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewUsersValueUnknown(), nil - } - - if in.IsNull() { - return NewUsersValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewUsersValueMust(UsersValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t UsersType) ValueType(ctx context.Context) attr.Value { - return UsersValue{} -} - -var _ basetypes.ObjectValuable = UsersValue{} - -type UsersValue struct { - Id basetypes.Int64Value `tfsdk:"id"` - Name basetypes.StringValue `tfsdk:"name"` - Status basetypes.StringValue `tfsdk:"status"` - state attr.ValueState -} - -func (v UsersValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 3) - - var val tftypes.Value - var err error - - attrTypes["id"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["name"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["status"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 3) - - val, err = v.Id.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["id"] = val - - val, err = v.Name.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["name"] = val - - val, err = v.Status.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["status"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v UsersValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v UsersValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v UsersValue) String() string { - return "UsersValue" -} - -func (v UsersValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "id": basetypes.Int64Type{}, - "name": basetypes.StringType{}, - "status": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "id": v.Id, - "name": v.Name, - "status": v.Status, - }) - - return objVal, diags -} - -func (v UsersValue) Equal(o attr.Value) bool { - other, ok := o.(UsersValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Id.Equal(other.Id) { - return false - } - - if !v.Name.Equal(other.Name) { - return false - } - - if !v.Status.Equal(other.Status) { - return false - } - - return true -} - -func (v UsersValue) Type(ctx context.Context) attr.Type { - return UsersType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v UsersValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "id": basetypes.Int64Type{}, - "name": basetypes.StringType{}, - "status": basetypes.StringType{}, - } -} diff --git a/stackit/internal/services/postgresflexalpha/user/resources_gen/user_resource_gen.go b/stackit/internal/services/postgresflexalpha/user/resources_gen/user_resource_gen.go deleted file mode 100644 index f07ab701..00000000 --- a/stackit/internal/services/postgresflexalpha/user/resources_gen/user_resource_gen.go +++ /dev/null @@ -1,93 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -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" -) - -func UserResourceSchema(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.", - }, - "id": schema.Int64Attribute{ - Computed: true, - Description: "The ID of the user.", - MarkdownDescription: "The ID of the user.", - }, - "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 user.", - MarkdownDescription: "The name of the user.", - }, - "password": schema.StringAttribute{ - Computed: true, - Description: "The password for the user.", - MarkdownDescription: "The password for the user.", - }, - "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", - ), - }, - }, - "roles": schema.ListAttribute{ - ElementType: types.StringType, - Optional: true, - Computed: true, - Description: "A list containing the user roles for the instance.", - MarkdownDescription: "A list containing the user roles for the instance.", - }, - "status": schema.StringAttribute{ - Computed: true, - Description: "The current status of the user.", - MarkdownDescription: "The current status of the user.", - }, - "user_id": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "The ID of the user.", - MarkdownDescription: "The ID of the user.", - }, - }, - } -} - -type UserModel struct { - ConnectionString types.String `tfsdk:"connection_string"` - Id types.Int64 `tfsdk:"id"` - InstanceId types.String `tfsdk:"instance_id"` - Name types.String `tfsdk:"name"` - Password types.String `tfsdk:"password"` - 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"` -} diff --git a/stackit/internal/services/postgresflexalpha/version/datasources_gen/versions_data_source_gen.go b/stackit/internal/services/postgresflexalpha/version/datasources_gen/versions_data_source_gen.go deleted file mode 100644 index 03530869..00000000 --- a/stackit/internal/services/postgresflexalpha/version/datasources_gen/versions_data_source_gen.go +++ /dev/null @@ -1,569 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package postgresflexalpha - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -func VersionsDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "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", - ), - }, - }, - "versions": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "beta": schema.BoolAttribute{ - Computed: true, - Description: "Flag if the version is a beta version. If set the version may contain bugs and is not fully tested.", - MarkdownDescription: "Flag if the version is a beta version. If set the version may contain bugs and is not fully tested.", - }, - "deprecated": schema.StringAttribute{ - Computed: true, - Description: "Timestamp in RFC3339 format which says when the version will no longer be supported by STACKIT.", - MarkdownDescription: "Timestamp in RFC3339 format which says when the version will no longer be supported by STACKIT.", - }, - "recommend": schema.BoolAttribute{ - Computed: true, - Description: "Flag if the version is recommend by the STACKIT Team.", - MarkdownDescription: "Flag if the version is recommend by the STACKIT Team.", - }, - "version": schema.StringAttribute{ - Computed: true, - Description: "The postgres version used for the instance.", - MarkdownDescription: "The postgres version used for the instance.", - }, - }, - CustomType: VersionsType{ - ObjectType: types.ObjectType{ - AttrTypes: VersionsValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "A list containing available postgres versions.", - MarkdownDescription: "A list containing available postgres versions.", - }, - }, - } -} - -type VersionsModel struct { - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Versions types.List `tfsdk:"versions"` -} - -var _ basetypes.ObjectTypable = VersionsType{} - -type VersionsType struct { - basetypes.ObjectType -} - -func (t VersionsType) Equal(o attr.Type) bool { - other, ok := o.(VersionsType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t VersionsType) String() string { - return "VersionsType" -} - -func (t VersionsType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - betaAttribute, ok := attributes["beta"] - - if !ok { - diags.AddError( - "Attribute Missing", - `beta is missing from object`) - - return nil, diags - } - - betaVal, ok := betaAttribute.(basetypes.BoolValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`beta expected to be basetypes.BoolValue, was: %T`, betaAttribute)) - } - - deprecatedAttribute, ok := attributes["deprecated"] - - if !ok { - diags.AddError( - "Attribute Missing", - `deprecated is missing from object`) - - return nil, diags - } - - deprecatedVal, ok := deprecatedAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`deprecated expected to be basetypes.StringValue, was: %T`, deprecatedAttribute)) - } - - recommendAttribute, ok := attributes["recommend"] - - if !ok { - diags.AddError( - "Attribute Missing", - `recommend is missing from object`) - - return nil, diags - } - - recommendVal, ok := recommendAttribute.(basetypes.BoolValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`recommend expected to be basetypes.BoolValue, was: %T`, recommendAttribute)) - } - - versionAttribute, ok := attributes["version"] - - if !ok { - diags.AddError( - "Attribute Missing", - `version is missing from object`) - - return nil, diags - } - - versionVal, ok := versionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`version expected to be basetypes.StringValue, was: %T`, versionAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return VersionsValue{ - Beta: betaVal, - Deprecated: deprecatedVal, - Recommend: recommendVal, - Version: versionVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewVersionsValueNull() VersionsValue { - return VersionsValue{ - state: attr.ValueStateNull, - } -} - -func NewVersionsValueUnknown() VersionsValue { - return VersionsValue{ - state: attr.ValueStateUnknown, - } -} - -func NewVersionsValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (VersionsValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing VersionsValue Attribute Value", - "While creating a VersionsValue value, a missing attribute value was detected. "+ - "A VersionsValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("VersionsValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid VersionsValue Attribute Type", - "While creating a VersionsValue value, an invalid attribute value was detected. "+ - "A VersionsValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("VersionsValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("VersionsValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra VersionsValue Attribute Value", - "While creating a VersionsValue value, an extra attribute value was detected. "+ - "A VersionsValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra VersionsValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewVersionsValueUnknown(), diags - } - - betaAttribute, ok := attributes["beta"] - - if !ok { - diags.AddError( - "Attribute Missing", - `beta is missing from object`) - - return NewVersionsValueUnknown(), diags - } - - betaVal, ok := betaAttribute.(basetypes.BoolValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`beta expected to be basetypes.BoolValue, was: %T`, betaAttribute)) - } - - deprecatedAttribute, ok := attributes["deprecated"] - - if !ok { - diags.AddError( - "Attribute Missing", - `deprecated is missing from object`) - - return NewVersionsValueUnknown(), diags - } - - deprecatedVal, ok := deprecatedAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`deprecated expected to be basetypes.StringValue, was: %T`, deprecatedAttribute)) - } - - recommendAttribute, ok := attributes["recommend"] - - if !ok { - diags.AddError( - "Attribute Missing", - `recommend is missing from object`) - - return NewVersionsValueUnknown(), diags - } - - recommendVal, ok := recommendAttribute.(basetypes.BoolValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`recommend expected to be basetypes.BoolValue, was: %T`, recommendAttribute)) - } - - versionAttribute, ok := attributes["version"] - - if !ok { - diags.AddError( - "Attribute Missing", - `version is missing from object`) - - return NewVersionsValueUnknown(), diags - } - - versionVal, ok := versionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`version expected to be basetypes.StringValue, was: %T`, versionAttribute)) - } - - if diags.HasError() { - return NewVersionsValueUnknown(), diags - } - - return VersionsValue{ - Beta: betaVal, - Deprecated: deprecatedVal, - Recommend: recommendVal, - Version: versionVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewVersionsValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) VersionsValue { - object, diags := NewVersionsValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewVersionsValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t VersionsType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewVersionsValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewVersionsValueUnknown(), nil - } - - if in.IsNull() { - return NewVersionsValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewVersionsValueMust(VersionsValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t VersionsType) ValueType(ctx context.Context) attr.Value { - return VersionsValue{} -} - -var _ basetypes.ObjectValuable = VersionsValue{} - -type VersionsValue struct { - Beta basetypes.BoolValue `tfsdk:"beta"` - Deprecated basetypes.StringValue `tfsdk:"deprecated"` - Recommend basetypes.BoolValue `tfsdk:"recommend"` - Version basetypes.StringValue `tfsdk:"version"` - state attr.ValueState -} - -func (v VersionsValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 4) - - var val tftypes.Value - var err error - - attrTypes["beta"] = basetypes.BoolType{}.TerraformType(ctx) - attrTypes["deprecated"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["recommend"] = basetypes.BoolType{}.TerraformType(ctx) - attrTypes["version"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 4) - - val, err = v.Beta.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["beta"] = val - - val, err = v.Deprecated.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["deprecated"] = val - - val, err = v.Recommend.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["recommend"] = val - - val, err = v.Version.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["version"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v VersionsValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v VersionsValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v VersionsValue) String() string { - return "VersionsValue" -} - -func (v VersionsValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "beta": basetypes.BoolType{}, - "deprecated": basetypes.StringType{}, - "recommend": basetypes.BoolType{}, - "version": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "beta": v.Beta, - "deprecated": v.Deprecated, - "recommend": v.Recommend, - "version": v.Version, - }) - - return objVal, diags -} - -func (v VersionsValue) Equal(o attr.Value) bool { - other, ok := o.(VersionsValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Beta.Equal(other.Beta) { - return false - } - - if !v.Deprecated.Equal(other.Deprecated) { - return false - } - - if !v.Recommend.Equal(other.Recommend) { - return false - } - - if !v.Version.Equal(other.Version) { - return false - } - - return true -} - -func (v VersionsValue) Type(ctx context.Context) attr.Type { - return VersionsType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v VersionsValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "beta": basetypes.BoolType{}, - "deprecated": basetypes.StringType{}, - "recommend": basetypes.BoolType{}, - "version": basetypes.StringType{}, - } -} diff --git a/stackit/internal/services/sqlserverflexalpha/database/datasources_gen/database_data_source_gen.go b/stackit/internal/services/sqlserverflexalpha/database/datasources_gen/database_data_source_gen.go deleted file mode 100644 index 82250802..00000000 --- a/stackit/internal/services/sqlserverflexalpha/database/datasources_gen/database_data_source_gen.go +++ /dev/null @@ -1,81 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package sqlserverflexalpha - -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"` -} diff --git a/stackit/internal/services/sqlserverflexalpha/database/datasources_gen/databases_data_source_gen.go b/stackit/internal/services/sqlserverflexalpha/database/datasources_gen/databases_data_source_gen.go deleted file mode 100644 index c6b6350a..00000000 --- a/stackit/internal/services/sqlserverflexalpha/database/datasources_gen/databases_data_source_gen.go +++ /dev/null @@ -1,1180 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package sqlserverflexalpha - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -func DatabasesDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "databases": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "created": schema.StringAttribute{ - Computed: true, - Description: "The date when the database was created in RFC3339 format.", - MarkdownDescription: "The date when the database was created in RFC3339 format.", - }, - "id": schema.Int64Attribute{ - Computed: true, - Description: "The id of the database.", - MarkdownDescription: "The id of the database.", - }, - "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.", - }, - }, - CustomType: DatabasesType{ - ObjectType: types.ObjectType{ - AttrTypes: DatabasesValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "A list containing all databases for the instance.", - MarkdownDescription: "A list containing all databases for the instance.", - }, - "instance_id": schema.StringAttribute{ - Required: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "page": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of the page of items list to be returned.", - MarkdownDescription: "Number of the page of items list to be returned.", - }, - "pagination": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "page": schema.Int64Attribute{ - Computed: true, - }, - "size": schema.Int64Attribute{ - Computed: true, - }, - "sort": schema.StringAttribute{ - Computed: true, - }, - "total_pages": schema.Int64Attribute{ - Computed: true, - }, - "total_rows": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: PaginationType{ - ObjectType: types.ObjectType{ - AttrTypes: PaginationValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - }, - "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", - ), - }, - }, - "size": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of items to be returned on each page.", - MarkdownDescription: "Number of items to be returned on each page.", - }, - "sort": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "Sorting of the databases to be returned on each page.", - MarkdownDescription: "Sorting of the databases to be returned on each page.", - Validators: []validator.String{ - stringvalidator.OneOf( - "created_at.desc", - "created_at.asc", - "database_id.desc", - "database_id.asc", - "database_name.desc", - "database_name.asc", - "database_owner.desc", - "database_owner.asc", - "index.asc", - "index.desc", - ), - }, - }, - }, - } -} - -type DatabasesModel struct { - Databases types.List `tfsdk:"databases"` - InstanceId types.String `tfsdk:"instance_id"` - Page types.Int64 `tfsdk:"page"` - Pagination PaginationValue `tfsdk:"pagination"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Size types.Int64 `tfsdk:"size"` - Sort types.String `tfsdk:"sort"` -} - -var _ basetypes.ObjectTypable = DatabasesType{} - -type DatabasesType struct { - basetypes.ObjectType -} - -func (t DatabasesType) Equal(o attr.Type) bool { - other, ok := o.(DatabasesType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t DatabasesType) String() string { - return "DatabasesType" -} - -func (t DatabasesType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - createdAttribute, ok := attributes["created"] - - if !ok { - diags.AddError( - "Attribute Missing", - `created is missing from object`) - - return nil, diags - } - - createdVal, ok := createdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`created expected to be basetypes.StringValue, was: %T`, createdAttribute)) - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return nil, diags - } - - idVal, ok := idAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.Int64Value, was: %T`, idAttribute)) - } - - nameAttribute, ok := attributes["name"] - - if !ok { - diags.AddError( - "Attribute Missing", - `name is missing from object`) - - return nil, diags - } - - nameVal, ok := nameAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`name expected to be basetypes.StringValue, was: %T`, nameAttribute)) - } - - ownerAttribute, ok := attributes["owner"] - - if !ok { - diags.AddError( - "Attribute Missing", - `owner is missing from object`) - - return nil, diags - } - - ownerVal, ok := ownerAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`owner expected to be basetypes.StringValue, was: %T`, ownerAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return DatabasesValue{ - Created: createdVal, - Id: idVal, - Name: nameVal, - Owner: ownerVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewDatabasesValueNull() DatabasesValue { - return DatabasesValue{ - state: attr.ValueStateNull, - } -} - -func NewDatabasesValueUnknown() DatabasesValue { - return DatabasesValue{ - state: attr.ValueStateUnknown, - } -} - -func NewDatabasesValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (DatabasesValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing DatabasesValue Attribute Value", - "While creating a DatabasesValue value, a missing attribute value was detected. "+ - "A DatabasesValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("DatabasesValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid DatabasesValue Attribute Type", - "While creating a DatabasesValue value, an invalid attribute value was detected. "+ - "A DatabasesValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("DatabasesValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("DatabasesValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra DatabasesValue Attribute Value", - "While creating a DatabasesValue value, an extra attribute value was detected. "+ - "A DatabasesValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra DatabasesValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewDatabasesValueUnknown(), diags - } - - createdAttribute, ok := attributes["created"] - - if !ok { - diags.AddError( - "Attribute Missing", - `created is missing from object`) - - return NewDatabasesValueUnknown(), diags - } - - createdVal, ok := createdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`created expected to be basetypes.StringValue, was: %T`, createdAttribute)) - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return NewDatabasesValueUnknown(), diags - } - - idVal, ok := idAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.Int64Value, was: %T`, idAttribute)) - } - - nameAttribute, ok := attributes["name"] - - if !ok { - diags.AddError( - "Attribute Missing", - `name is missing from object`) - - return NewDatabasesValueUnknown(), diags - } - - nameVal, ok := nameAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`name expected to be basetypes.StringValue, was: %T`, nameAttribute)) - } - - ownerAttribute, ok := attributes["owner"] - - if !ok { - diags.AddError( - "Attribute Missing", - `owner is missing from object`) - - return NewDatabasesValueUnknown(), diags - } - - ownerVal, ok := ownerAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`owner expected to be basetypes.StringValue, was: %T`, ownerAttribute)) - } - - if diags.HasError() { - return NewDatabasesValueUnknown(), diags - } - - return DatabasesValue{ - Created: createdVal, - Id: idVal, - Name: nameVal, - Owner: ownerVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewDatabasesValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) DatabasesValue { - object, diags := NewDatabasesValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewDatabasesValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t DatabasesType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewDatabasesValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewDatabasesValueUnknown(), nil - } - - if in.IsNull() { - return NewDatabasesValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewDatabasesValueMust(DatabasesValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t DatabasesType) ValueType(ctx context.Context) attr.Value { - return DatabasesValue{} -} - -var _ basetypes.ObjectValuable = DatabasesValue{} - -type DatabasesValue struct { - Created basetypes.StringValue `tfsdk:"created"` - Id basetypes.Int64Value `tfsdk:"id"` - Name basetypes.StringValue `tfsdk:"name"` - Owner basetypes.StringValue `tfsdk:"owner"` - state attr.ValueState -} - -func (v DatabasesValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 4) - - var val tftypes.Value - var err error - - attrTypes["created"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["id"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["name"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["owner"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 4) - - val, err = v.Created.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["created"] = val - - val, err = v.Id.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["id"] = val - - val, err = v.Name.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["name"] = val - - val, err = v.Owner.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["owner"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v DatabasesValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v DatabasesValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v DatabasesValue) String() string { - return "DatabasesValue" -} - -func (v DatabasesValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "created": basetypes.StringType{}, - "id": basetypes.Int64Type{}, - "name": basetypes.StringType{}, - "owner": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "created": v.Created, - "id": v.Id, - "name": v.Name, - "owner": v.Owner, - }) - - return objVal, diags -} - -func (v DatabasesValue) Equal(o attr.Value) bool { - other, ok := o.(DatabasesValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Created.Equal(other.Created) { - return false - } - - if !v.Id.Equal(other.Id) { - return false - } - - if !v.Name.Equal(other.Name) { - return false - } - - if !v.Owner.Equal(other.Owner) { - return false - } - - return true -} - -func (v DatabasesValue) Type(ctx context.Context) attr.Type { - return DatabasesType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v DatabasesValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "created": basetypes.StringType{}, - "id": basetypes.Int64Type{}, - "name": basetypes.StringType{}, - "owner": basetypes.StringType{}, - } -} - -var _ basetypes.ObjectTypable = PaginationType{} - -type PaginationType struct { - basetypes.ObjectType -} - -func (t PaginationType) Equal(o attr.Type) bool { - other, ok := o.(PaginationType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t PaginationType) String() string { - return "PaginationType" -} - -func (t PaginationType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return nil, diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return nil, diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return nil, diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return nil, diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueNull() PaginationValue { - return PaginationValue{ - state: attr.ValueStateNull, - } -} - -func NewPaginationValueUnknown() PaginationValue { - return PaginationValue{ - state: attr.ValueStateUnknown, - } -} - -func NewPaginationValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (PaginationValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing PaginationValue Attribute Value", - "While creating a PaginationValue value, a missing attribute value was detected. "+ - "A PaginationValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid PaginationValue Attribute Type", - "While creating a PaginationValue value, an invalid attribute value was detected. "+ - "A PaginationValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra PaginationValue Attribute Value", - "While creating a PaginationValue value, an extra attribute value was detected. "+ - "A PaginationValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra PaginationValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) PaginationValue { - object, diags := NewPaginationValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewPaginationValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t PaginationType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewPaginationValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewPaginationValueUnknown(), nil - } - - if in.IsNull() { - return NewPaginationValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewPaginationValueMust(PaginationValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t PaginationType) ValueType(ctx context.Context) attr.Value { - return PaginationValue{} -} - -var _ basetypes.ObjectValuable = PaginationValue{} - -type PaginationValue struct { - Page basetypes.Int64Value `tfsdk:"page"` - Size basetypes.Int64Value `tfsdk:"size"` - Sort basetypes.StringValue `tfsdk:"sort"` - TotalPages basetypes.Int64Value `tfsdk:"total_pages"` - TotalRows basetypes.Int64Value `tfsdk:"total_rows"` - state attr.ValueState -} - -func (v PaginationValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 5) - - var val tftypes.Value - var err error - - attrTypes["page"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["sort"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["total_pages"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["total_rows"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 5) - - val, err = v.Page.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["page"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - val, err = v.Sort.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["sort"] = val - - val, err = v.TotalPages.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_pages"] = val - - val, err = v.TotalRows.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_rows"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v PaginationValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v PaginationValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v PaginationValue) String() string { - return "PaginationValue" -} - -func (v PaginationValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "page": v.Page, - "size": v.Size, - "sort": v.Sort, - "total_pages": v.TotalPages, - "total_rows": v.TotalRows, - }) - - return objVal, diags -} - -func (v PaginationValue) Equal(o attr.Value) bool { - other, ok := o.(PaginationValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Page.Equal(other.Page) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - if !v.Sort.Equal(other.Sort) { - return false - } - - if !v.TotalPages.Equal(other.TotalPages) { - return false - } - - if !v.TotalRows.Equal(other.TotalRows) { - return false - } - - return true -} - -func (v PaginationValue) Type(ctx context.Context) attr.Type { - return PaginationType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v PaginationValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } -} diff --git a/stackit/internal/services/sqlserverflexalpha/database/resources_gen/database_resource_gen.go b/stackit/internal/services/sqlserverflexalpha/database/resources_gen/database_resource_gen.go deleted file mode 100644 index 8e5886ad..00000000 --- a/stackit/internal/services/sqlserverflexalpha/database/resources_gen/database_resource_gen.go +++ /dev/null @@ -1,99 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package sqlserverflexalpha - -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"` -} diff --git a/stackit/internal/services/sqlserverflexalpha/flavor/datasources_gen/flavor_data_source_gen.go b/stackit/internal/services/sqlserverflexalpha/flavor/datasources_gen/flavor_data_source_gen.go deleted file mode 100644 index d8654cf4..00000000 --- a/stackit/internal/services/sqlserverflexalpha/flavor/datasources_gen/flavor_data_source_gen.go +++ /dev/null @@ -1,1909 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package sqlserverflexalpha - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -func FlavorDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "flavors": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "cpu": schema.Int64Attribute{ - Computed: true, - Description: "The cpu count of the instance.", - MarkdownDescription: "The cpu count of the instance.", - }, - "description": schema.StringAttribute{ - Computed: true, - Description: "The flavor description.", - MarkdownDescription: "The flavor description.", - }, - "id": schema.StringAttribute{ - Computed: true, - Description: "The id of the instance flavor.", - MarkdownDescription: "The id of the instance flavor.", - }, - "max_gb": schema.Int64Attribute{ - Computed: true, - Description: "maximum storage which can be ordered for the flavor in Gigabyte.", - MarkdownDescription: "maximum storage which can be ordered for the flavor in Gigabyte.", - }, - "memory": schema.Int64Attribute{ - Computed: true, - Description: "The memory of the instance in Gibibyte.", - MarkdownDescription: "The memory of the instance in Gibibyte.", - }, - "min_gb": schema.Int64Attribute{ - Computed: true, - Description: "minimum storage which is required to order in Gigabyte.", - MarkdownDescription: "minimum storage which is required to order in Gigabyte.", - }, - "node_type": schema.StringAttribute{ - Computed: true, - Description: "defines the nodeType it can be either single or HA", - MarkdownDescription: "defines the nodeType it can be either single or HA", - }, - "storage_classes": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "class": schema.StringAttribute{ - Computed: true, - }, - "max_io_per_sec": schema.Int64Attribute{ - Computed: true, - }, - "max_through_in_mb": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: StorageClassesType{ - ObjectType: types.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "maximum storage which can be ordered for the flavor in Gigabyte.", - MarkdownDescription: "maximum storage which can be ordered for the flavor in Gigabyte.", - }, - }, - CustomType: FlavorsType{ - ObjectType: types.ObjectType{ - AttrTypes: FlavorsValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "List of flavors available for the project.", - MarkdownDescription: "List of flavors available for the project.", - }, - "page": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of the page of items list to be returned.", - MarkdownDescription: "Number of the page of items list to be returned.", - }, - "pagination": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "page": schema.Int64Attribute{ - Computed: true, - }, - "size": schema.Int64Attribute{ - Computed: true, - }, - "sort": schema.StringAttribute{ - Computed: true, - }, - "total_pages": schema.Int64Attribute{ - Computed: true, - }, - "total_rows": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: PaginationType{ - ObjectType: types.ObjectType{ - AttrTypes: PaginationValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - }, - "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", - ), - }, - }, - "size": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of items to be returned on each page.", - MarkdownDescription: "Number of items to be returned on each page.", - }, - "sort": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "Sorting of the flavors to be returned on each page.", - MarkdownDescription: "Sorting of the flavors to be returned on each page.", - Validators: []validator.String{ - stringvalidator.OneOf( - "index.desc", - "index.asc", - "cpu.desc", - "cpu.asc", - "flavor_description.asc", - "flavor_description.desc", - "id.desc", - "id.asc", - "size_max.desc", - "size_max.asc", - "ram.desc", - "ram.asc", - "size_min.desc", - "size_min.asc", - "storage_class.asc", - "storage_class.desc", - "node_type.asc", - "node_type.desc", - ), - }, - }, - }, - } -} - -type FlavorModel struct { - Flavors types.List `tfsdk:"flavors"` - Page types.Int64 `tfsdk:"page"` - Pagination PaginationValue `tfsdk:"pagination"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Size types.Int64 `tfsdk:"size"` - Sort types.String `tfsdk:"sort"` -} - -var _ basetypes.ObjectTypable = FlavorsType{} - -type FlavorsType struct { - basetypes.ObjectType -} - -func (t FlavorsType) Equal(o attr.Type) bool { - other, ok := o.(FlavorsType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t FlavorsType) String() string { - return "FlavorsType" -} - -func (t FlavorsType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - cpuAttribute, ok := attributes["cpu"] - - if !ok { - diags.AddError( - "Attribute Missing", - `cpu is missing from object`) - - return nil, diags - } - - cpuVal, ok := cpuAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`cpu expected to be basetypes.Int64Value, was: %T`, cpuAttribute)) - } - - descriptionAttribute, ok := attributes["description"] - - if !ok { - diags.AddError( - "Attribute Missing", - `description is missing from object`) - - return nil, diags - } - - descriptionVal, ok := descriptionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`description expected to be basetypes.StringValue, was: %T`, descriptionAttribute)) - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return nil, diags - } - - idVal, ok := idAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.StringValue, was: %T`, idAttribute)) - } - - maxGbAttribute, ok := attributes["max_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_gb is missing from object`) - - return nil, diags - } - - maxGbVal, ok := maxGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_gb expected to be basetypes.Int64Value, was: %T`, maxGbAttribute)) - } - - memoryAttribute, ok := attributes["memory"] - - if !ok { - diags.AddError( - "Attribute Missing", - `memory is missing from object`) - - return nil, diags - } - - memoryVal, ok := memoryAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`memory expected to be basetypes.Int64Value, was: %T`, memoryAttribute)) - } - - minGbAttribute, ok := attributes["min_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `min_gb is missing from object`) - - return nil, diags - } - - minGbVal, ok := minGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`min_gb expected to be basetypes.Int64Value, was: %T`, minGbAttribute)) - } - - nodeTypeAttribute, ok := attributes["node_type"] - - if !ok { - diags.AddError( - "Attribute Missing", - `node_type is missing from object`) - - return nil, diags - } - - nodeTypeVal, ok := nodeTypeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`node_type expected to be basetypes.StringValue, was: %T`, nodeTypeAttribute)) - } - - storageClassesAttribute, ok := attributes["storage_classes"] - - if !ok { - diags.AddError( - "Attribute Missing", - `storage_classes is missing from object`) - - return nil, diags - } - - storageClassesVal, ok := storageClassesAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`storage_classes expected to be basetypes.ListValue, was: %T`, storageClassesAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return FlavorsValue{ - Cpu: cpuVal, - Description: descriptionVal, - Id: idVal, - MaxGb: maxGbVal, - Memory: memoryVal, - MinGb: minGbVal, - NodeType: nodeTypeVal, - StorageClasses: storageClassesVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewFlavorsValueNull() FlavorsValue { - return FlavorsValue{ - state: attr.ValueStateNull, - } -} - -func NewFlavorsValueUnknown() FlavorsValue { - return FlavorsValue{ - state: attr.ValueStateUnknown, - } -} - -func NewFlavorsValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (FlavorsValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing FlavorsValue Attribute Value", - "While creating a FlavorsValue value, a missing attribute value was detected. "+ - "A FlavorsValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("FlavorsValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid FlavorsValue Attribute Type", - "While creating a FlavorsValue value, an invalid attribute value was detected. "+ - "A FlavorsValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("FlavorsValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("FlavorsValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra FlavorsValue Attribute Value", - "While creating a FlavorsValue value, an extra attribute value was detected. "+ - "A FlavorsValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra FlavorsValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewFlavorsValueUnknown(), diags - } - - cpuAttribute, ok := attributes["cpu"] - - if !ok { - diags.AddError( - "Attribute Missing", - `cpu is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - cpuVal, ok := cpuAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`cpu expected to be basetypes.Int64Value, was: %T`, cpuAttribute)) - } - - descriptionAttribute, ok := attributes["description"] - - if !ok { - diags.AddError( - "Attribute Missing", - `description is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - descriptionVal, ok := descriptionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`description expected to be basetypes.StringValue, was: %T`, descriptionAttribute)) - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - idVal, ok := idAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.StringValue, was: %T`, idAttribute)) - } - - maxGbAttribute, ok := attributes["max_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_gb is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - maxGbVal, ok := maxGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_gb expected to be basetypes.Int64Value, was: %T`, maxGbAttribute)) - } - - memoryAttribute, ok := attributes["memory"] - - if !ok { - diags.AddError( - "Attribute Missing", - `memory is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - memoryVal, ok := memoryAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`memory expected to be basetypes.Int64Value, was: %T`, memoryAttribute)) - } - - minGbAttribute, ok := attributes["min_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `min_gb is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - minGbVal, ok := minGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`min_gb expected to be basetypes.Int64Value, was: %T`, minGbAttribute)) - } - - nodeTypeAttribute, ok := attributes["node_type"] - - if !ok { - diags.AddError( - "Attribute Missing", - `node_type is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - nodeTypeVal, ok := nodeTypeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`node_type expected to be basetypes.StringValue, was: %T`, nodeTypeAttribute)) - } - - storageClassesAttribute, ok := attributes["storage_classes"] - - if !ok { - diags.AddError( - "Attribute Missing", - `storage_classes is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - storageClassesVal, ok := storageClassesAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`storage_classes expected to be basetypes.ListValue, was: %T`, storageClassesAttribute)) - } - - if diags.HasError() { - return NewFlavorsValueUnknown(), diags - } - - return FlavorsValue{ - Cpu: cpuVal, - Description: descriptionVal, - Id: idVal, - MaxGb: maxGbVal, - Memory: memoryVal, - MinGb: minGbVal, - NodeType: nodeTypeVal, - StorageClasses: storageClassesVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewFlavorsValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) FlavorsValue { - object, diags := NewFlavorsValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewFlavorsValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t FlavorsType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewFlavorsValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewFlavorsValueUnknown(), nil - } - - if in.IsNull() { - return NewFlavorsValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewFlavorsValueMust(FlavorsValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t FlavorsType) ValueType(ctx context.Context) attr.Value { - return FlavorsValue{} -} - -var _ basetypes.ObjectValuable = FlavorsValue{} - -type FlavorsValue struct { - Cpu basetypes.Int64Value `tfsdk:"cpu"` - Description basetypes.StringValue `tfsdk:"description"` - Id basetypes.StringValue `tfsdk:"id"` - MaxGb basetypes.Int64Value `tfsdk:"max_gb"` - Memory basetypes.Int64Value `tfsdk:"memory"` - MinGb basetypes.Int64Value `tfsdk:"min_gb"` - NodeType basetypes.StringValue `tfsdk:"node_type"` - StorageClasses basetypes.ListValue `tfsdk:"storage_classes"` - state attr.ValueState -} - -func (v FlavorsValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 8) - - var val tftypes.Value - var err error - - attrTypes["cpu"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["description"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["max_gb"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["memory"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["min_gb"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["node_type"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["storage_classes"] = basetypes.ListType{ - ElemType: StorageClassesValue{}.Type(ctx), - }.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 8) - - val, err = v.Cpu.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["cpu"] = val - - val, err = v.Description.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["description"] = val - - val, err = v.Id.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["id"] = val - - val, err = v.MaxGb.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["max_gb"] = val - - val, err = v.Memory.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["memory"] = val - - val, err = v.MinGb.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["min_gb"] = val - - val, err = v.NodeType.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["node_type"] = val - - val, err = v.StorageClasses.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["storage_classes"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v FlavorsValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v FlavorsValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v FlavorsValue) String() string { - return "FlavorsValue" -} - -func (v FlavorsValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - storageClasses := types.ListValueMust( - StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - v.StorageClasses.Elements(), - ) - - if v.StorageClasses.IsNull() { - storageClasses = types.ListNull( - StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - ) - } - - if v.StorageClasses.IsUnknown() { - storageClasses = types.ListUnknown( - StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - ) - } - - attributeTypes := map[string]attr.Type{ - "cpu": basetypes.Int64Type{}, - "description": basetypes.StringType{}, - "id": basetypes.StringType{}, - "max_gb": basetypes.Int64Type{}, - "memory": basetypes.Int64Type{}, - "min_gb": basetypes.Int64Type{}, - "node_type": basetypes.StringType{}, - "storage_classes": basetypes.ListType{ - ElemType: StorageClassesValue{}.Type(ctx), - }, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "cpu": v.Cpu, - "description": v.Description, - "id": v.Id, - "max_gb": v.MaxGb, - "memory": v.Memory, - "min_gb": v.MinGb, - "node_type": v.NodeType, - "storage_classes": storageClasses, - }) - - return objVal, diags -} - -func (v FlavorsValue) Equal(o attr.Value) bool { - other, ok := o.(FlavorsValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Cpu.Equal(other.Cpu) { - return false - } - - if !v.Description.Equal(other.Description) { - return false - } - - if !v.Id.Equal(other.Id) { - return false - } - - if !v.MaxGb.Equal(other.MaxGb) { - return false - } - - if !v.Memory.Equal(other.Memory) { - return false - } - - if !v.MinGb.Equal(other.MinGb) { - return false - } - - if !v.NodeType.Equal(other.NodeType) { - return false - } - - if !v.StorageClasses.Equal(other.StorageClasses) { - return false - } - - return true -} - -func (v FlavorsValue) Type(ctx context.Context) attr.Type { - return FlavorsType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v FlavorsValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "cpu": basetypes.Int64Type{}, - "description": basetypes.StringType{}, - "id": basetypes.StringType{}, - "max_gb": basetypes.Int64Type{}, - "memory": basetypes.Int64Type{}, - "min_gb": basetypes.Int64Type{}, - "node_type": basetypes.StringType{}, - "storage_classes": basetypes.ListType{ - ElemType: StorageClassesValue{}.Type(ctx), - }, - } -} - -var _ basetypes.ObjectTypable = StorageClassesType{} - -type StorageClassesType struct { - basetypes.ObjectType -} - -func (t StorageClassesType) Equal(o attr.Type) bool { - other, ok := o.(StorageClassesType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t StorageClassesType) String() string { - return "StorageClassesType" -} - -func (t StorageClassesType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - classAttribute, ok := attributes["class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `class is missing from object`) - - return nil, diags - } - - classVal, ok := classAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`class expected to be basetypes.StringValue, was: %T`, classAttribute)) - } - - maxIoPerSecAttribute, ok := attributes["max_io_per_sec"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_io_per_sec is missing from object`) - - return nil, diags - } - - maxIoPerSecVal, ok := maxIoPerSecAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_io_per_sec expected to be basetypes.Int64Value, was: %T`, maxIoPerSecAttribute)) - } - - maxThroughInMbAttribute, ok := attributes["max_through_in_mb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_through_in_mb is missing from object`) - - return nil, diags - } - - maxThroughInMbVal, ok := maxThroughInMbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_through_in_mb expected to be basetypes.Int64Value, was: %T`, maxThroughInMbAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return StorageClassesValue{ - Class: classVal, - MaxIoPerSec: maxIoPerSecVal, - MaxThroughInMb: maxThroughInMbVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageClassesValueNull() StorageClassesValue { - return StorageClassesValue{ - state: attr.ValueStateNull, - } -} - -func NewStorageClassesValueUnknown() StorageClassesValue { - return StorageClassesValue{ - state: attr.ValueStateUnknown, - } -} - -func NewStorageClassesValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (StorageClassesValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing StorageClassesValue Attribute Value", - "While creating a StorageClassesValue value, a missing attribute value was detected. "+ - "A StorageClassesValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageClassesValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid StorageClassesValue Attribute Type", - "While creating a StorageClassesValue value, an invalid attribute value was detected. "+ - "A StorageClassesValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageClassesValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("StorageClassesValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra StorageClassesValue Attribute Value", - "While creating a StorageClassesValue value, an extra attribute value was detected. "+ - "A StorageClassesValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra StorageClassesValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewStorageClassesValueUnknown(), diags - } - - classAttribute, ok := attributes["class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `class is missing from object`) - - return NewStorageClassesValueUnknown(), diags - } - - classVal, ok := classAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`class expected to be basetypes.StringValue, was: %T`, classAttribute)) - } - - maxIoPerSecAttribute, ok := attributes["max_io_per_sec"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_io_per_sec is missing from object`) - - return NewStorageClassesValueUnknown(), diags - } - - maxIoPerSecVal, ok := maxIoPerSecAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_io_per_sec expected to be basetypes.Int64Value, was: %T`, maxIoPerSecAttribute)) - } - - maxThroughInMbAttribute, ok := attributes["max_through_in_mb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_through_in_mb is missing from object`) - - return NewStorageClassesValueUnknown(), diags - } - - maxThroughInMbVal, ok := maxThroughInMbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_through_in_mb expected to be basetypes.Int64Value, was: %T`, maxThroughInMbAttribute)) - } - - if diags.HasError() { - return NewStorageClassesValueUnknown(), diags - } - - return StorageClassesValue{ - Class: classVal, - MaxIoPerSec: maxIoPerSecVal, - MaxThroughInMb: maxThroughInMbVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageClassesValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) StorageClassesValue { - object, diags := NewStorageClassesValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewStorageClassesValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t StorageClassesType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewStorageClassesValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewStorageClassesValueUnknown(), nil - } - - if in.IsNull() { - return NewStorageClassesValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewStorageClassesValueMust(StorageClassesValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t StorageClassesType) ValueType(ctx context.Context) attr.Value { - return StorageClassesValue{} -} - -var _ basetypes.ObjectValuable = StorageClassesValue{} - -type StorageClassesValue struct { - Class basetypes.StringValue `tfsdk:"class"` - MaxIoPerSec basetypes.Int64Value `tfsdk:"max_io_per_sec"` - MaxThroughInMb basetypes.Int64Value `tfsdk:"max_through_in_mb"` - state attr.ValueState -} - -func (v StorageClassesValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 3) - - var val tftypes.Value - var err error - - attrTypes["class"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["max_io_per_sec"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["max_through_in_mb"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 3) - - val, err = v.Class.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["class"] = val - - val, err = v.MaxIoPerSec.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["max_io_per_sec"] = val - - val, err = v.MaxThroughInMb.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["max_through_in_mb"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v StorageClassesValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v StorageClassesValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v StorageClassesValue) String() string { - return "StorageClassesValue" -} - -func (v StorageClassesValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "class": basetypes.StringType{}, - "max_io_per_sec": basetypes.Int64Type{}, - "max_through_in_mb": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "class": v.Class, - "max_io_per_sec": v.MaxIoPerSec, - "max_through_in_mb": v.MaxThroughInMb, - }) - - return objVal, diags -} - -func (v StorageClassesValue) Equal(o attr.Value) bool { - other, ok := o.(StorageClassesValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Class.Equal(other.Class) { - return false - } - - if !v.MaxIoPerSec.Equal(other.MaxIoPerSec) { - return false - } - - if !v.MaxThroughInMb.Equal(other.MaxThroughInMb) { - return false - } - - return true -} - -func (v StorageClassesValue) Type(ctx context.Context) attr.Type { - return StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v StorageClassesValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "class": basetypes.StringType{}, - "max_io_per_sec": basetypes.Int64Type{}, - "max_through_in_mb": basetypes.Int64Type{}, - } -} - -var _ basetypes.ObjectTypable = PaginationType{} - -type PaginationType struct { - basetypes.ObjectType -} - -func (t PaginationType) Equal(o attr.Type) bool { - other, ok := o.(PaginationType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t PaginationType) String() string { - return "PaginationType" -} - -func (t PaginationType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return nil, diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return nil, diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return nil, diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return nil, diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueNull() PaginationValue { - return PaginationValue{ - state: attr.ValueStateNull, - } -} - -func NewPaginationValueUnknown() PaginationValue { - return PaginationValue{ - state: attr.ValueStateUnknown, - } -} - -func NewPaginationValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (PaginationValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing PaginationValue Attribute Value", - "While creating a PaginationValue value, a missing attribute value was detected. "+ - "A PaginationValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid PaginationValue Attribute Type", - "While creating a PaginationValue value, an invalid attribute value was detected. "+ - "A PaginationValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra PaginationValue Attribute Value", - "While creating a PaginationValue value, an extra attribute value was detected. "+ - "A PaginationValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra PaginationValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) PaginationValue { - object, diags := NewPaginationValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewPaginationValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t PaginationType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewPaginationValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewPaginationValueUnknown(), nil - } - - if in.IsNull() { - return NewPaginationValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewPaginationValueMust(PaginationValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t PaginationType) ValueType(ctx context.Context) attr.Value { - return PaginationValue{} -} - -var _ basetypes.ObjectValuable = PaginationValue{} - -type PaginationValue struct { - Page basetypes.Int64Value `tfsdk:"page"` - Size basetypes.Int64Value `tfsdk:"size"` - Sort basetypes.StringValue `tfsdk:"sort"` - TotalPages basetypes.Int64Value `tfsdk:"total_pages"` - TotalRows basetypes.Int64Value `tfsdk:"total_rows"` - state attr.ValueState -} - -func (v PaginationValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 5) - - var val tftypes.Value - var err error - - attrTypes["page"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["sort"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["total_pages"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["total_rows"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 5) - - val, err = v.Page.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["page"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - val, err = v.Sort.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["sort"] = val - - val, err = v.TotalPages.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_pages"] = val - - val, err = v.TotalRows.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_rows"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v PaginationValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v PaginationValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v PaginationValue) String() string { - return "PaginationValue" -} - -func (v PaginationValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "page": v.Page, - "size": v.Size, - "sort": v.Sort, - "total_pages": v.TotalPages, - "total_rows": v.TotalRows, - }) - - return objVal, diags -} - -func (v PaginationValue) Equal(o attr.Value) bool { - other, ok := o.(PaginationValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Page.Equal(other.Page) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - if !v.Sort.Equal(other.Sort) { - return false - } - - if !v.TotalPages.Equal(other.TotalPages) { - return false - } - - if !v.TotalRows.Equal(other.TotalRows) { - return false - } - - return true -} - -func (v PaginationValue) Type(ctx context.Context) attr.Type { - return PaginationType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v PaginationValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } -} diff --git a/stackit/internal/services/sqlserverflexalpha/flavors/datasources_gen/flavors_data_source_gen.go b/stackit/internal/services/sqlserverflexalpha/flavors/datasources_gen/flavors_data_source_gen.go deleted file mode 100644 index 40f086e2..00000000 --- a/stackit/internal/services/sqlserverflexalpha/flavors/datasources_gen/flavors_data_source_gen.go +++ /dev/null @@ -1,1909 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package sqlserverflexalpha - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -func FlavorsDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "flavors": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "cpu": schema.Int64Attribute{ - Computed: true, - Description: "The cpu count of the instance.", - MarkdownDescription: "The cpu count of the instance.", - }, - "description": schema.StringAttribute{ - Computed: true, - Description: "The flavor description.", - MarkdownDescription: "The flavor description.", - }, - "tf_original_api_id": schema.StringAttribute{ - Computed: true, - Description: "The id of the instance flavor.", - MarkdownDescription: "The id of the instance flavor.", - }, - "max_gb": schema.Int64Attribute{ - Computed: true, - Description: "maximum storage which can be ordered for the flavor in Gigabyte.", - MarkdownDescription: "maximum storage which can be ordered for the flavor in Gigabyte.", - }, - "memory": schema.Int64Attribute{ - Computed: true, - Description: "The memory of the instance in Gibibyte.", - MarkdownDescription: "The memory of the instance in Gibibyte.", - }, - "min_gb": schema.Int64Attribute{ - Computed: true, - Description: "minimum storage which is required to order in Gigabyte.", - MarkdownDescription: "minimum storage which is required to order in Gigabyte.", - }, - "node_type": schema.StringAttribute{ - Computed: true, - Description: "defines the nodeType it can be either single or HA", - MarkdownDescription: "defines the nodeType it can be either single or HA", - }, - "storage_classes": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "class": schema.StringAttribute{ - Computed: true, - }, - "max_io_per_sec": schema.Int64Attribute{ - Computed: true, - }, - "max_through_in_mb": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: StorageClassesType{ - ObjectType: types.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "maximum storage which can be ordered for the flavor in Gigabyte.", - MarkdownDescription: "maximum storage which can be ordered for the flavor in Gigabyte.", - }, - }, - CustomType: FlavorsType{ - ObjectType: types.ObjectType{ - AttrTypes: FlavorsValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "List of flavors available for the project.", - MarkdownDescription: "List of flavors available for the project.", - }, - "page": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of the page of items list to be returned.", - MarkdownDescription: "Number of the page of items list to be returned.", - }, - "pagination": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "page": schema.Int64Attribute{ - Computed: true, - }, - "size": schema.Int64Attribute{ - Computed: true, - }, - "sort": schema.StringAttribute{ - Computed: true, - }, - "total_pages": schema.Int64Attribute{ - Computed: true, - }, - "total_rows": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: PaginationType{ - ObjectType: types.ObjectType{ - AttrTypes: PaginationValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - }, - "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", - ), - }, - }, - "size": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of items to be returned on each page.", - MarkdownDescription: "Number of items to be returned on each page.", - }, - "sort": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "Sorting of the flavors to be returned on each page.", - MarkdownDescription: "Sorting of the flavors to be returned on each page.", - Validators: []validator.String{ - stringvalidator.OneOf( - "index.desc", - "index.asc", - "cpu.desc", - "cpu.asc", - "flavor_description.asc", - "flavor_description.desc", - "id.desc", - "id.asc", - "size_max.desc", - "size_max.asc", - "ram.desc", - "ram.asc", - "size_min.desc", - "size_min.asc", - "storage_class.asc", - "storage_class.desc", - "node_type.asc", - "node_type.desc", - ), - }, - }, - }, - } -} - -type FlavorsModel struct { - Flavors types.List `tfsdk:"flavors"` - Page types.Int64 `tfsdk:"page"` - Pagination PaginationValue `tfsdk:"pagination"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Size types.Int64 `tfsdk:"size"` - Sort types.String `tfsdk:"sort"` -} - -var _ basetypes.ObjectTypable = FlavorsType{} - -type FlavorsType struct { - basetypes.ObjectType -} - -func (t FlavorsType) Equal(o attr.Type) bool { - other, ok := o.(FlavorsType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t FlavorsType) String() string { - return "FlavorsType" -} - -func (t FlavorsType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - cpuAttribute, ok := attributes["cpu"] - - if !ok { - diags.AddError( - "Attribute Missing", - `cpu is missing from object`) - - return nil, diags - } - - cpuVal, ok := cpuAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`cpu expected to be basetypes.Int64Value, was: %T`, cpuAttribute)) - } - - descriptionAttribute, ok := attributes["description"] - - if !ok { - diags.AddError( - "Attribute Missing", - `description is missing from object`) - - return nil, diags - } - - descriptionVal, ok := descriptionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`description expected to be basetypes.StringValue, was: %T`, descriptionAttribute)) - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return nil, diags - } - - idVal, ok := idAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.StringValue, was: %T`, idAttribute)) - } - - maxGbAttribute, ok := attributes["max_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_gb is missing from object`) - - return nil, diags - } - - maxGbVal, ok := maxGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_gb expected to be basetypes.Int64Value, was: %T`, maxGbAttribute)) - } - - memoryAttribute, ok := attributes["memory"] - - if !ok { - diags.AddError( - "Attribute Missing", - `memory is missing from object`) - - return nil, diags - } - - memoryVal, ok := memoryAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`memory expected to be basetypes.Int64Value, was: %T`, memoryAttribute)) - } - - minGbAttribute, ok := attributes["min_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `min_gb is missing from object`) - - return nil, diags - } - - minGbVal, ok := minGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`min_gb expected to be basetypes.Int64Value, was: %T`, minGbAttribute)) - } - - nodeTypeAttribute, ok := attributes["node_type"] - - if !ok { - diags.AddError( - "Attribute Missing", - `node_type is missing from object`) - - return nil, diags - } - - nodeTypeVal, ok := nodeTypeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`node_type expected to be basetypes.StringValue, was: %T`, nodeTypeAttribute)) - } - - storageClassesAttribute, ok := attributes["storage_classes"] - - if !ok { - diags.AddError( - "Attribute Missing", - `storage_classes is missing from object`) - - return nil, diags - } - - storageClassesVal, ok := storageClassesAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`storage_classes expected to be basetypes.ListValue, was: %T`, storageClassesAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return FlavorsValue{ - Cpu: cpuVal, - Description: descriptionVal, - Id: idVal, - MaxGb: maxGbVal, - Memory: memoryVal, - MinGb: minGbVal, - NodeType: nodeTypeVal, - StorageClasses: storageClassesVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewFlavorsValueNull() FlavorsValue { - return FlavorsValue{ - state: attr.ValueStateNull, - } -} - -func NewFlavorsValueUnknown() FlavorsValue { - return FlavorsValue{ - state: attr.ValueStateUnknown, - } -} - -func NewFlavorsValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (FlavorsValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing FlavorsValue Attribute Value", - "While creating a FlavorsValue value, a missing attribute value was detected. "+ - "A FlavorsValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("FlavorsValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid FlavorsValue Attribute Type", - "While creating a FlavorsValue value, an invalid attribute value was detected. "+ - "A FlavorsValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("FlavorsValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("FlavorsValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra FlavorsValue Attribute Value", - "While creating a FlavorsValue value, an extra attribute value was detected. "+ - "A FlavorsValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra FlavorsValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewFlavorsValueUnknown(), diags - } - - cpuAttribute, ok := attributes["cpu"] - - if !ok { - diags.AddError( - "Attribute Missing", - `cpu is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - cpuVal, ok := cpuAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`cpu expected to be basetypes.Int64Value, was: %T`, cpuAttribute)) - } - - descriptionAttribute, ok := attributes["description"] - - if !ok { - diags.AddError( - "Attribute Missing", - `description is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - descriptionVal, ok := descriptionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`description expected to be basetypes.StringValue, was: %T`, descriptionAttribute)) - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - idVal, ok := idAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.StringValue, was: %T`, idAttribute)) - } - - maxGbAttribute, ok := attributes["max_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_gb is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - maxGbVal, ok := maxGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_gb expected to be basetypes.Int64Value, was: %T`, maxGbAttribute)) - } - - memoryAttribute, ok := attributes["memory"] - - if !ok { - diags.AddError( - "Attribute Missing", - `memory is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - memoryVal, ok := memoryAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`memory expected to be basetypes.Int64Value, was: %T`, memoryAttribute)) - } - - minGbAttribute, ok := attributes["min_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `min_gb is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - minGbVal, ok := minGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`min_gb expected to be basetypes.Int64Value, was: %T`, minGbAttribute)) - } - - nodeTypeAttribute, ok := attributes["node_type"] - - if !ok { - diags.AddError( - "Attribute Missing", - `node_type is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - nodeTypeVal, ok := nodeTypeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`node_type expected to be basetypes.StringValue, was: %T`, nodeTypeAttribute)) - } - - storageClassesAttribute, ok := attributes["storage_classes"] - - if !ok { - diags.AddError( - "Attribute Missing", - `storage_classes is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - storageClassesVal, ok := storageClassesAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`storage_classes expected to be basetypes.ListValue, was: %T`, storageClassesAttribute)) - } - - if diags.HasError() { - return NewFlavorsValueUnknown(), diags - } - - return FlavorsValue{ - Cpu: cpuVal, - Description: descriptionVal, - Id: idVal, - MaxGb: maxGbVal, - Memory: memoryVal, - MinGb: minGbVal, - NodeType: nodeTypeVal, - StorageClasses: storageClassesVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewFlavorsValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) FlavorsValue { - object, diags := NewFlavorsValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewFlavorsValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t FlavorsType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewFlavorsValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewFlavorsValueUnknown(), nil - } - - if in.IsNull() { - return NewFlavorsValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewFlavorsValueMust(FlavorsValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t FlavorsType) ValueType(ctx context.Context) attr.Value { - return FlavorsValue{} -} - -var _ basetypes.ObjectValuable = FlavorsValue{} - -type FlavorsValue struct { - Cpu basetypes.Int64Value `tfsdk:"cpu"` - Description basetypes.StringValue `tfsdk:"description"` - Id basetypes.StringValue `tfsdk:"id"` - MaxGb basetypes.Int64Value `tfsdk:"max_gb"` - Memory basetypes.Int64Value `tfsdk:"memory"` - MinGb basetypes.Int64Value `tfsdk:"min_gb"` - NodeType basetypes.StringValue `tfsdk:"node_type"` - StorageClasses basetypes.ListValue `tfsdk:"storage_classes"` - state attr.ValueState -} - -func (v FlavorsValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 8) - - var val tftypes.Value - var err error - - attrTypes["cpu"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["description"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["max_gb"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["memory"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["min_gb"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["node_type"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["storage_classes"] = basetypes.ListType{ - ElemType: StorageClassesValue{}.Type(ctx), - }.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 8) - - val, err = v.Cpu.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["cpu"] = val - - val, err = v.Description.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["description"] = val - - val, err = v.Id.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["id"] = val - - val, err = v.MaxGb.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["max_gb"] = val - - val, err = v.Memory.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["memory"] = val - - val, err = v.MinGb.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["min_gb"] = val - - val, err = v.NodeType.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["node_type"] = val - - val, err = v.StorageClasses.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["storage_classes"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v FlavorsValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v FlavorsValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v FlavorsValue) String() string { - return "FlavorsValue" -} - -func (v FlavorsValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - storageClasses := types.ListValueMust( - StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - v.StorageClasses.Elements(), - ) - - if v.StorageClasses.IsNull() { - storageClasses = types.ListNull( - StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - ) - } - - if v.StorageClasses.IsUnknown() { - storageClasses = types.ListUnknown( - StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - ) - } - - attributeTypes := map[string]attr.Type{ - "cpu": basetypes.Int64Type{}, - "description": basetypes.StringType{}, - "id": basetypes.StringType{}, - "max_gb": basetypes.Int64Type{}, - "memory": basetypes.Int64Type{}, - "min_gb": basetypes.Int64Type{}, - "node_type": basetypes.StringType{}, - "storage_classes": basetypes.ListType{ - ElemType: StorageClassesValue{}.Type(ctx), - }, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "cpu": v.Cpu, - "description": v.Description, - "id": v.Id, - "max_gb": v.MaxGb, - "memory": v.Memory, - "min_gb": v.MinGb, - "node_type": v.NodeType, - "storage_classes": storageClasses, - }) - - return objVal, diags -} - -func (v FlavorsValue) Equal(o attr.Value) bool { - other, ok := o.(FlavorsValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Cpu.Equal(other.Cpu) { - return false - } - - if !v.Description.Equal(other.Description) { - return false - } - - if !v.Id.Equal(other.Id) { - return false - } - - if !v.MaxGb.Equal(other.MaxGb) { - return false - } - - if !v.Memory.Equal(other.Memory) { - return false - } - - if !v.MinGb.Equal(other.MinGb) { - return false - } - - if !v.NodeType.Equal(other.NodeType) { - return false - } - - if !v.StorageClasses.Equal(other.StorageClasses) { - return false - } - - return true -} - -func (v FlavorsValue) Type(ctx context.Context) attr.Type { - return FlavorsType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v FlavorsValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "cpu": basetypes.Int64Type{}, - "description": basetypes.StringType{}, - "id": basetypes.StringType{}, - "max_gb": basetypes.Int64Type{}, - "memory": basetypes.Int64Type{}, - "min_gb": basetypes.Int64Type{}, - "node_type": basetypes.StringType{}, - "storage_classes": basetypes.ListType{ - ElemType: StorageClassesValue{}.Type(ctx), - }, - } -} - -var _ basetypes.ObjectTypable = StorageClassesType{} - -type StorageClassesType struct { - basetypes.ObjectType -} - -func (t StorageClassesType) Equal(o attr.Type) bool { - other, ok := o.(StorageClassesType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t StorageClassesType) String() string { - return "StorageClassesType" -} - -func (t StorageClassesType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - classAttribute, ok := attributes["class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `class is missing from object`) - - return nil, diags - } - - classVal, ok := classAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`class expected to be basetypes.StringValue, was: %T`, classAttribute)) - } - - maxIoPerSecAttribute, ok := attributes["max_io_per_sec"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_io_per_sec is missing from object`) - - return nil, diags - } - - maxIoPerSecVal, ok := maxIoPerSecAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_io_per_sec expected to be basetypes.Int64Value, was: %T`, maxIoPerSecAttribute)) - } - - maxThroughInMbAttribute, ok := attributes["max_through_in_mb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_through_in_mb is missing from object`) - - return nil, diags - } - - maxThroughInMbVal, ok := maxThroughInMbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_through_in_mb expected to be basetypes.Int64Value, was: %T`, maxThroughInMbAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return StorageClassesValue{ - Class: classVal, - MaxIoPerSec: maxIoPerSecVal, - MaxThroughInMb: maxThroughInMbVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageClassesValueNull() StorageClassesValue { - return StorageClassesValue{ - state: attr.ValueStateNull, - } -} - -func NewStorageClassesValueUnknown() StorageClassesValue { - return StorageClassesValue{ - state: attr.ValueStateUnknown, - } -} - -func NewStorageClassesValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (StorageClassesValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing StorageClassesValue Attribute Value", - "While creating a StorageClassesValue value, a missing attribute value was detected. "+ - "A StorageClassesValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageClassesValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid StorageClassesValue Attribute Type", - "While creating a StorageClassesValue value, an invalid attribute value was detected. "+ - "A StorageClassesValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageClassesValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("StorageClassesValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra StorageClassesValue Attribute Value", - "While creating a StorageClassesValue value, an extra attribute value was detected. "+ - "A StorageClassesValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra StorageClassesValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewStorageClassesValueUnknown(), diags - } - - classAttribute, ok := attributes["class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `class is missing from object`) - - return NewStorageClassesValueUnknown(), diags - } - - classVal, ok := classAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`class expected to be basetypes.StringValue, was: %T`, classAttribute)) - } - - maxIoPerSecAttribute, ok := attributes["max_io_per_sec"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_io_per_sec is missing from object`) - - return NewStorageClassesValueUnknown(), diags - } - - maxIoPerSecVal, ok := maxIoPerSecAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_io_per_sec expected to be basetypes.Int64Value, was: %T`, maxIoPerSecAttribute)) - } - - maxThroughInMbAttribute, ok := attributes["max_through_in_mb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_through_in_mb is missing from object`) - - return NewStorageClassesValueUnknown(), diags - } - - maxThroughInMbVal, ok := maxThroughInMbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_through_in_mb expected to be basetypes.Int64Value, was: %T`, maxThroughInMbAttribute)) - } - - if diags.HasError() { - return NewStorageClassesValueUnknown(), diags - } - - return StorageClassesValue{ - Class: classVal, - MaxIoPerSec: maxIoPerSecVal, - MaxThroughInMb: maxThroughInMbVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageClassesValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) StorageClassesValue { - object, diags := NewStorageClassesValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewStorageClassesValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t StorageClassesType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewStorageClassesValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewStorageClassesValueUnknown(), nil - } - - if in.IsNull() { - return NewStorageClassesValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewStorageClassesValueMust(StorageClassesValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t StorageClassesType) ValueType(ctx context.Context) attr.Value { - return StorageClassesValue{} -} - -var _ basetypes.ObjectValuable = StorageClassesValue{} - -type StorageClassesValue struct { - Class basetypes.StringValue `tfsdk:"class"` - MaxIoPerSec basetypes.Int64Value `tfsdk:"max_io_per_sec"` - MaxThroughInMb basetypes.Int64Value `tfsdk:"max_through_in_mb"` - state attr.ValueState -} - -func (v StorageClassesValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 3) - - var val tftypes.Value - var err error - - attrTypes["class"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["max_io_per_sec"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["max_through_in_mb"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 3) - - val, err = v.Class.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["class"] = val - - val, err = v.MaxIoPerSec.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["max_io_per_sec"] = val - - val, err = v.MaxThroughInMb.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["max_through_in_mb"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v StorageClassesValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v StorageClassesValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v StorageClassesValue) String() string { - return "StorageClassesValue" -} - -func (v StorageClassesValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "class": basetypes.StringType{}, - "max_io_per_sec": basetypes.Int64Type{}, - "max_through_in_mb": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "class": v.Class, - "max_io_per_sec": v.MaxIoPerSec, - "max_through_in_mb": v.MaxThroughInMb, - }) - - return objVal, diags -} - -func (v StorageClassesValue) Equal(o attr.Value) bool { - other, ok := o.(StorageClassesValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Class.Equal(other.Class) { - return false - } - - if !v.MaxIoPerSec.Equal(other.MaxIoPerSec) { - return false - } - - if !v.MaxThroughInMb.Equal(other.MaxThroughInMb) { - return false - } - - return true -} - -func (v StorageClassesValue) Type(ctx context.Context) attr.Type { - return StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v StorageClassesValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "class": basetypes.StringType{}, - "max_io_per_sec": basetypes.Int64Type{}, - "max_through_in_mb": basetypes.Int64Type{}, - } -} - -var _ basetypes.ObjectTypable = PaginationType{} - -type PaginationType struct { - basetypes.ObjectType -} - -func (t PaginationType) Equal(o attr.Type) bool { - other, ok := o.(PaginationType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t PaginationType) String() string { - return "PaginationType" -} - -func (t PaginationType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return nil, diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return nil, diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return nil, diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return nil, diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueNull() PaginationValue { - return PaginationValue{ - state: attr.ValueStateNull, - } -} - -func NewPaginationValueUnknown() PaginationValue { - return PaginationValue{ - state: attr.ValueStateUnknown, - } -} - -func NewPaginationValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (PaginationValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing PaginationValue Attribute Value", - "While creating a PaginationValue value, a missing attribute value was detected. "+ - "A PaginationValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid PaginationValue Attribute Type", - "While creating a PaginationValue value, an invalid attribute value was detected. "+ - "A PaginationValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra PaginationValue Attribute Value", - "While creating a PaginationValue value, an extra attribute value was detected. "+ - "A PaginationValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra PaginationValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) PaginationValue { - object, diags := NewPaginationValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewPaginationValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t PaginationType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewPaginationValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewPaginationValueUnknown(), nil - } - - if in.IsNull() { - return NewPaginationValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewPaginationValueMust(PaginationValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t PaginationType) ValueType(ctx context.Context) attr.Value { - return PaginationValue{} -} - -var _ basetypes.ObjectValuable = PaginationValue{} - -type PaginationValue struct { - Page basetypes.Int64Value `tfsdk:"page"` - Size basetypes.Int64Value `tfsdk:"size"` - Sort basetypes.StringValue `tfsdk:"sort"` - TotalPages basetypes.Int64Value `tfsdk:"total_pages"` - TotalRows basetypes.Int64Value `tfsdk:"total_rows"` - state attr.ValueState -} - -func (v PaginationValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 5) - - var val tftypes.Value - var err error - - attrTypes["page"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["sort"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["total_pages"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["total_rows"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 5) - - val, err = v.Page.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["page"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - val, err = v.Sort.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["sort"] = val - - val, err = v.TotalPages.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_pages"] = val - - val, err = v.TotalRows.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_rows"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v PaginationValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v PaginationValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v PaginationValue) String() string { - return "PaginationValue" -} - -func (v PaginationValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "page": v.Page, - "size": v.Size, - "sort": v.Sort, - "total_pages": v.TotalPages, - "total_rows": v.TotalRows, - }) - - return objVal, diags -} - -func (v PaginationValue) Equal(o attr.Value) bool { - other, ok := o.(PaginationValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Page.Equal(other.Page) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - if !v.Sort.Equal(other.Sort) { - return false - } - - if !v.TotalPages.Equal(other.TotalPages) { - return false - } - - if !v.TotalRows.Equal(other.TotalRows) { - return false - } - - return true -} - -func (v PaginationValue) Type(ctx context.Context) attr.Type { - return PaginationType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v PaginationValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } -} diff --git a/stackit/internal/services/sqlserverflexalpha/instance/datasources_gen/instance_data_source_gen.go b/stackit/internal/services/sqlserverflexalpha/instance/datasources_gen/instance_data_source_gen.go deleted file mode 100644 index 5880a392..00000000 --- a/stackit/internal/services/sqlserverflexalpha/instance/datasources_gen/instance_data_source_gen.go +++ /dev/null @@ -1,1579 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package sqlserverflexalpha - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -func InstanceDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "backup_schedule": schema.StringAttribute{ - Computed: true, - Description: "The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.", - MarkdownDescription: "The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.", - }, - "edition": schema.StringAttribute{ - Computed: true, - Description: "Edition of the MSSQL server instance", - MarkdownDescription: "Edition of the MSSQL server instance", - }, - "encryption": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "kek_key_id": schema.StringAttribute{ - Computed: true, - Description: "The key identifier", - MarkdownDescription: "The key identifier", - }, - "kek_key_ring_id": schema.StringAttribute{ - Computed: true, - Description: "The keyring identifier", - MarkdownDescription: "The keyring identifier", - }, - "kek_key_version": schema.StringAttribute{ - Computed: true, - Description: "The key version", - MarkdownDescription: "The key version", - }, - "service_account": schema.StringAttribute{ - Computed: true, - }, - }, - CustomType: EncryptionType{ - ObjectType: types.ObjectType{ - AttrTypes: EncryptionValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - Description: "this defines which key to use for storage encryption", - MarkdownDescription: "this defines which key to use for storage encryption", - }, - "flavor_id": schema.StringAttribute{ - Computed: true, - Description: "The id of the instance flavor.", - MarkdownDescription: "The id of the instance flavor.", - }, - "tf_original_api_id": schema.StringAttribute{ - Computed: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "instance_id": schema.StringAttribute{ - Required: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "is_deletable": schema.BoolAttribute{ - Computed: true, - Description: "Whether the instance can be deleted or not.", - MarkdownDescription: "Whether the instance can be deleted or not.", - }, - "name": schema.StringAttribute{ - Computed: true, - Description: "The name of the instance.", - MarkdownDescription: "The name of the instance.", - }, - "network": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "access_scope": schema.StringAttribute{ - Computed: true, - Description: "The network access scope of the instance\n\n⚠️ **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.\n", - MarkdownDescription: "The network access scope of the instance\n\n⚠️ **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.\n", - }, - "acl": schema.ListAttribute{ - ElementType: types.StringType, - Computed: true, - Description: "List of IPV4 cidr.", - MarkdownDescription: "List of IPV4 cidr.", - }, - "instance_address": schema.StringAttribute{ - Computed: true, - }, - "router_address": schema.StringAttribute{ - Computed: true, - }, - }, - CustomType: NetworkType{ - ObjectType: types.ObjectType{ - AttrTypes: NetworkValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - Description: "The access configuration of the instance", - MarkdownDescription: "The access configuration of the instance", - }, - "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", - ), - }, - }, - "replicas": schema.Int64Attribute{ - Computed: true, - Description: "How many replicas the instance should have.", - MarkdownDescription: "How many replicas the instance should have.", - }, - "retention_days": schema.Int64Attribute{ - Computed: true, - Description: "The days for how long the backup files should be stored before cleaned up. 30 to 365", - MarkdownDescription: "The days for how long the backup files should be stored before cleaned up. 30 to 365", - }, - "status": schema.StringAttribute{ - Computed: true, - }, - "storage": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "class": schema.StringAttribute{ - Computed: true, - Description: "The storage class for the storage.", - MarkdownDescription: "The storage class for the storage.", - }, - "size": schema.Int64Attribute{ - Computed: true, - Description: "The storage size in Gigabytes.", - MarkdownDescription: "The storage size in Gigabytes.", - }, - }, - CustomType: StorageType{ - ObjectType: types.ObjectType{ - AttrTypes: StorageValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - Description: "The object containing information about the storage size and class.", - MarkdownDescription: "The object containing information about the storage size and class.", - }, - "version": schema.StringAttribute{ - Computed: true, - Description: "The sqlserver version used for the instance.", - MarkdownDescription: "The sqlserver version used for the instance.", - }, - }, - } -} - -type InstanceModel struct { - BackupSchedule types.String `tfsdk:"backup_schedule"` - Edition types.String `tfsdk:"edition"` - Encryption EncryptionValue `tfsdk:"encryption"` - FlavorId types.String `tfsdk:"flavor_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"` - Network NetworkValue `tfsdk:"network"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Replicas types.Int64 `tfsdk:"replicas"` - RetentionDays types.Int64 `tfsdk:"retention_days"` - Status types.String `tfsdk:"status"` - Storage StorageValue `tfsdk:"storage"` - Version types.String `tfsdk:"version"` -} - -var _ basetypes.ObjectTypable = EncryptionType{} - -type EncryptionType struct { - basetypes.ObjectType -} - -func (t EncryptionType) Equal(o attr.Type) bool { - other, ok := o.(EncryptionType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t EncryptionType) String() string { - return "EncryptionType" -} - -func (t EncryptionType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - kekKeyIdAttribute, ok := attributes["kek_key_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_id is missing from object`) - - return nil, diags - } - - kekKeyIdVal, ok := kekKeyIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_id expected to be basetypes.StringValue, was: %T`, kekKeyIdAttribute)) - } - - kekKeyRingIdAttribute, ok := attributes["kek_key_ring_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_ring_id is missing from object`) - - return nil, diags - } - - kekKeyRingIdVal, ok := kekKeyRingIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_ring_id expected to be basetypes.StringValue, was: %T`, kekKeyRingIdAttribute)) - } - - kekKeyVersionAttribute, ok := attributes["kek_key_version"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_version is missing from object`) - - return nil, diags - } - - kekKeyVersionVal, ok := kekKeyVersionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_version expected to be basetypes.StringValue, was: %T`, kekKeyVersionAttribute)) - } - - serviceAccountAttribute, ok := attributes["service_account"] - - if !ok { - diags.AddError( - "Attribute Missing", - `service_account is missing from object`) - - return nil, diags - } - - serviceAccountVal, ok := serviceAccountAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`service_account expected to be basetypes.StringValue, was: %T`, serviceAccountAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return EncryptionValue{ - KekKeyId: kekKeyIdVal, - KekKeyRingId: kekKeyRingIdVal, - KekKeyVersion: kekKeyVersionVal, - ServiceAccount: serviceAccountVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewEncryptionValueNull() EncryptionValue { - return EncryptionValue{ - state: attr.ValueStateNull, - } -} - -func NewEncryptionValueUnknown() EncryptionValue { - return EncryptionValue{ - state: attr.ValueStateUnknown, - } -} - -func NewEncryptionValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (EncryptionValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing EncryptionValue Attribute Value", - "While creating a EncryptionValue value, a missing attribute value was detected. "+ - "A EncryptionValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("EncryptionValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid EncryptionValue Attribute Type", - "While creating a EncryptionValue value, an invalid attribute value was detected. "+ - "A EncryptionValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("EncryptionValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("EncryptionValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra EncryptionValue Attribute Value", - "While creating a EncryptionValue value, an extra attribute value was detected. "+ - "A EncryptionValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra EncryptionValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewEncryptionValueUnknown(), diags - } - - kekKeyIdAttribute, ok := attributes["kek_key_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_id is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - kekKeyIdVal, ok := kekKeyIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_id expected to be basetypes.StringValue, was: %T`, kekKeyIdAttribute)) - } - - kekKeyRingIdAttribute, ok := attributes["kek_key_ring_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_ring_id is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - kekKeyRingIdVal, ok := kekKeyRingIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_ring_id expected to be basetypes.StringValue, was: %T`, kekKeyRingIdAttribute)) - } - - kekKeyVersionAttribute, ok := attributes["kek_key_version"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_version is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - kekKeyVersionVal, ok := kekKeyVersionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_version expected to be basetypes.StringValue, was: %T`, kekKeyVersionAttribute)) - } - - serviceAccountAttribute, ok := attributes["service_account"] - - if !ok { - diags.AddError( - "Attribute Missing", - `service_account is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - serviceAccountVal, ok := serviceAccountAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`service_account expected to be basetypes.StringValue, was: %T`, serviceAccountAttribute)) - } - - if diags.HasError() { - return NewEncryptionValueUnknown(), diags - } - - return EncryptionValue{ - KekKeyId: kekKeyIdVal, - KekKeyRingId: kekKeyRingIdVal, - KekKeyVersion: kekKeyVersionVal, - ServiceAccount: serviceAccountVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewEncryptionValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) EncryptionValue { - object, diags := NewEncryptionValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewEncryptionValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t EncryptionType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewEncryptionValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewEncryptionValueUnknown(), nil - } - - if in.IsNull() { - return NewEncryptionValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewEncryptionValueMust(EncryptionValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t EncryptionType) ValueType(ctx context.Context) attr.Value { - return EncryptionValue{} -} - -var _ basetypes.ObjectValuable = EncryptionValue{} - -type EncryptionValue struct { - KekKeyId basetypes.StringValue `tfsdk:"kek_key_id"` - KekKeyRingId basetypes.StringValue `tfsdk:"kek_key_ring_id"` - KekKeyVersion basetypes.StringValue `tfsdk:"kek_key_version"` - ServiceAccount basetypes.StringValue `tfsdk:"service_account"` - state attr.ValueState -} - -func (v EncryptionValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 4) - - var val tftypes.Value - var err error - - attrTypes["kek_key_id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["kek_key_ring_id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["kek_key_version"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["service_account"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 4) - - val, err = v.KekKeyId.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["kek_key_id"] = val - - val, err = v.KekKeyRingId.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["kek_key_ring_id"] = val - - val, err = v.KekKeyVersion.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["kek_key_version"] = val - - val, err = v.ServiceAccount.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["service_account"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v EncryptionValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v EncryptionValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v EncryptionValue) String() string { - return "EncryptionValue" -} - -func (v EncryptionValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "kek_key_id": basetypes.StringType{}, - "kek_key_ring_id": basetypes.StringType{}, - "kek_key_version": basetypes.StringType{}, - "service_account": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "kek_key_id": v.KekKeyId, - "kek_key_ring_id": v.KekKeyRingId, - "kek_key_version": v.KekKeyVersion, - "service_account": v.ServiceAccount, - }) - - return objVal, diags -} - -func (v EncryptionValue) Equal(o attr.Value) bool { - other, ok := o.(EncryptionValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.KekKeyId.Equal(other.KekKeyId) { - return false - } - - if !v.KekKeyRingId.Equal(other.KekKeyRingId) { - return false - } - - if !v.KekKeyVersion.Equal(other.KekKeyVersion) { - return false - } - - if !v.ServiceAccount.Equal(other.ServiceAccount) { - return false - } - - return true -} - -func (v EncryptionValue) Type(ctx context.Context) attr.Type { - return EncryptionType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v EncryptionValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "kek_key_id": basetypes.StringType{}, - "kek_key_ring_id": basetypes.StringType{}, - "kek_key_version": basetypes.StringType{}, - "service_account": basetypes.StringType{}, - } -} - -var _ basetypes.ObjectTypable = NetworkType{} - -type NetworkType struct { - basetypes.ObjectType -} - -func (t NetworkType) Equal(o attr.Type) bool { - other, ok := o.(NetworkType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t NetworkType) String() string { - return "NetworkType" -} - -func (t NetworkType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - accessScopeAttribute, ok := attributes["access_scope"] - - if !ok { - diags.AddError( - "Attribute Missing", - `access_scope is missing from object`) - - return nil, diags - } - - accessScopeVal, ok := accessScopeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`access_scope expected to be basetypes.StringValue, was: %T`, accessScopeAttribute)) - } - - aclAttribute, ok := attributes["acl"] - - if !ok { - diags.AddError( - "Attribute Missing", - `acl is missing from object`) - - return nil, diags - } - - aclVal, ok := aclAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`acl expected to be basetypes.ListValue, was: %T`, aclAttribute)) - } - - instanceAddressAttribute, ok := attributes["instance_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `instance_address is missing from object`) - - return nil, diags - } - - instanceAddressVal, ok := instanceAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`instance_address expected to be basetypes.StringValue, was: %T`, instanceAddressAttribute)) - } - - routerAddressAttribute, ok := attributes["router_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `router_address is missing from object`) - - return nil, diags - } - - routerAddressVal, ok := routerAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`router_address expected to be basetypes.StringValue, was: %T`, routerAddressAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return NetworkValue{ - AccessScope: accessScopeVal, - Acl: aclVal, - InstanceAddress: instanceAddressVal, - RouterAddress: routerAddressVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewNetworkValueNull() NetworkValue { - return NetworkValue{ - state: attr.ValueStateNull, - } -} - -func NewNetworkValueUnknown() NetworkValue { - return NetworkValue{ - state: attr.ValueStateUnknown, - } -} - -func NewNetworkValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (NetworkValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing NetworkValue Attribute Value", - "While creating a NetworkValue value, a missing attribute value was detected. "+ - "A NetworkValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("NetworkValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid NetworkValue Attribute Type", - "While creating a NetworkValue value, an invalid attribute value was detected. "+ - "A NetworkValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("NetworkValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("NetworkValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra NetworkValue Attribute Value", - "While creating a NetworkValue value, an extra attribute value was detected. "+ - "A NetworkValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra NetworkValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewNetworkValueUnknown(), diags - } - - accessScopeAttribute, ok := attributes["access_scope"] - - if !ok { - diags.AddError( - "Attribute Missing", - `access_scope is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - accessScopeVal, ok := accessScopeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`access_scope expected to be basetypes.StringValue, was: %T`, accessScopeAttribute)) - } - - aclAttribute, ok := attributes["acl"] - - if !ok { - diags.AddError( - "Attribute Missing", - `acl is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - aclVal, ok := aclAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`acl expected to be basetypes.ListValue, was: %T`, aclAttribute)) - } - - instanceAddressAttribute, ok := attributes["instance_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `instance_address is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - instanceAddressVal, ok := instanceAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`instance_address expected to be basetypes.StringValue, was: %T`, instanceAddressAttribute)) - } - - routerAddressAttribute, ok := attributes["router_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `router_address is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - routerAddressVal, ok := routerAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`router_address expected to be basetypes.StringValue, was: %T`, routerAddressAttribute)) - } - - if diags.HasError() { - return NewNetworkValueUnknown(), diags - } - - return NetworkValue{ - AccessScope: accessScopeVal, - Acl: aclVal, - InstanceAddress: instanceAddressVal, - RouterAddress: routerAddressVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewNetworkValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) NetworkValue { - object, diags := NewNetworkValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewNetworkValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t NetworkType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewNetworkValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewNetworkValueUnknown(), nil - } - - if in.IsNull() { - return NewNetworkValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewNetworkValueMust(NetworkValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t NetworkType) ValueType(ctx context.Context) attr.Value { - return NetworkValue{} -} - -var _ basetypes.ObjectValuable = NetworkValue{} - -type NetworkValue struct { - AccessScope basetypes.StringValue `tfsdk:"access_scope"` - Acl basetypes.ListValue `tfsdk:"acl"` - InstanceAddress basetypes.StringValue `tfsdk:"instance_address"` - RouterAddress basetypes.StringValue `tfsdk:"router_address"` - state attr.ValueState -} - -func (v NetworkValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 4) - - var val tftypes.Value - var err error - - attrTypes["access_scope"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["acl"] = basetypes.ListType{ - ElemType: types.StringType, - }.TerraformType(ctx) - attrTypes["instance_address"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["router_address"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 4) - - val, err = v.AccessScope.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["access_scope"] = val - - val, err = v.Acl.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["acl"] = val - - val, err = v.InstanceAddress.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["instance_address"] = val - - val, err = v.RouterAddress.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["router_address"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v NetworkValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v NetworkValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v NetworkValue) String() string { - return "NetworkValue" -} - -func (v NetworkValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - var aclVal basetypes.ListValue - switch { - case v.Acl.IsUnknown(): - aclVal = types.ListUnknown(types.StringType) - case v.Acl.IsNull(): - aclVal = types.ListNull(types.StringType) - default: - var d diag.Diagnostics - aclVal, d = types.ListValue(types.StringType, v.Acl.Elements()) - diags.Append(d...) - } - - if diags.HasError() { - return types.ObjectUnknown(map[string]attr.Type{ - "access_scope": basetypes.StringType{}, - "acl": basetypes.ListType{ - ElemType: types.StringType, - }, - "instance_address": basetypes.StringType{}, - "router_address": basetypes.StringType{}, - }), diags - } - - attributeTypes := map[string]attr.Type{ - "access_scope": basetypes.StringType{}, - "acl": basetypes.ListType{ - ElemType: types.StringType, - }, - "instance_address": basetypes.StringType{}, - "router_address": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "access_scope": v.AccessScope, - "acl": aclVal, - "instance_address": v.InstanceAddress, - "router_address": v.RouterAddress, - }) - - return objVal, diags -} - -func (v NetworkValue) Equal(o attr.Value) bool { - other, ok := o.(NetworkValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.AccessScope.Equal(other.AccessScope) { - return false - } - - if !v.Acl.Equal(other.Acl) { - return false - } - - if !v.InstanceAddress.Equal(other.InstanceAddress) { - return false - } - - if !v.RouterAddress.Equal(other.RouterAddress) { - return false - } - - return true -} - -func (v NetworkValue) Type(ctx context.Context) attr.Type { - return NetworkType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v NetworkValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "access_scope": basetypes.StringType{}, - "acl": basetypes.ListType{ - ElemType: types.StringType, - }, - "instance_address": basetypes.StringType{}, - "router_address": basetypes.StringType{}, - } -} - -var _ basetypes.ObjectTypable = StorageType{} - -type StorageType struct { - basetypes.ObjectType -} - -func (t StorageType) Equal(o attr.Type) bool { - other, ok := o.(StorageType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t StorageType) String() string { - return "StorageType" -} - -func (t StorageType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - classAttribute, ok := attributes["class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `class is missing from object`) - - return nil, diags - } - - classVal, ok := classAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`class expected to be basetypes.StringValue, was: %T`, classAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return StorageValue{ - Class: classVal, - Size: sizeVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageValueNull() StorageValue { - return StorageValue{ - state: attr.ValueStateNull, - } -} - -func NewStorageValueUnknown() StorageValue { - return StorageValue{ - state: attr.ValueStateUnknown, - } -} - -func NewStorageValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (StorageValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing StorageValue Attribute Value", - "While creating a StorageValue value, a missing attribute value was detected. "+ - "A StorageValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid StorageValue Attribute Type", - "While creating a StorageValue value, an invalid attribute value was detected. "+ - "A StorageValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("StorageValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra StorageValue Attribute Value", - "While creating a StorageValue value, an extra attribute value was detected. "+ - "A StorageValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra StorageValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewStorageValueUnknown(), diags - } - - classAttribute, ok := attributes["class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `class is missing from object`) - - return NewStorageValueUnknown(), diags - } - - classVal, ok := classAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`class expected to be basetypes.StringValue, was: %T`, classAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewStorageValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - if diags.HasError() { - return NewStorageValueUnknown(), diags - } - - return StorageValue{ - Class: classVal, - Size: sizeVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) StorageValue { - object, diags := NewStorageValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewStorageValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t StorageType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewStorageValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewStorageValueUnknown(), nil - } - - if in.IsNull() { - return NewStorageValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewStorageValueMust(StorageValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t StorageType) ValueType(ctx context.Context) attr.Value { - return StorageValue{} -} - -var _ basetypes.ObjectValuable = StorageValue{} - -type StorageValue struct { - Class basetypes.StringValue `tfsdk:"class"` - Size basetypes.Int64Value `tfsdk:"size"` - state attr.ValueState -} - -func (v StorageValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 2) - - var val tftypes.Value - var err error - - attrTypes["class"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 2) - - val, err = v.Class.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["class"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v StorageValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v StorageValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v StorageValue) String() string { - return "StorageValue" -} - -func (v StorageValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "class": basetypes.StringType{}, - "size": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "class": v.Class, - "size": v.Size, - }) - - return objVal, diags -} - -func (v StorageValue) Equal(o attr.Value) bool { - other, ok := o.(StorageValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Class.Equal(other.Class) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - return true -} - -func (v StorageValue) Type(ctx context.Context) attr.Type { - return StorageType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v StorageValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "class": basetypes.StringType{}, - "size": basetypes.Int64Type{}, - } -} diff --git a/stackit/internal/services/sqlserverflexalpha/instance/datasources_gen/instances_data_source_gen.go b/stackit/internal/services/sqlserverflexalpha/instance/datasources_gen/instances_data_source_gen.go deleted file mode 100644 index 33df0a5d..00000000 --- a/stackit/internal/services/sqlserverflexalpha/instance/datasources_gen/instances_data_source_gen.go +++ /dev/null @@ -1,1172 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package sqlserverflexalpha - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -func InstancesDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "instances": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "id": schema.StringAttribute{ - Computed: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "is_deletable": schema.BoolAttribute{ - Computed: true, - Description: "Whether the instance can be deleted or not.", - MarkdownDescription: "Whether the instance can be deleted or not.", - }, - "name": schema.StringAttribute{ - Computed: true, - Description: "The name of the instance.", - MarkdownDescription: "The name of the instance.", - }, - "status": schema.StringAttribute{ - Computed: true, - }, - }, - CustomType: InstancesType{ - ObjectType: types.ObjectType{ - AttrTypes: InstancesValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "List of owned instances and their current status.", - MarkdownDescription: "List of owned instances and their current status.", - }, - "page": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of the page of items list to be returned.", - MarkdownDescription: "Number of the page of items list to be returned.", - }, - "pagination": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "page": schema.Int64Attribute{ - Computed: true, - }, - "size": schema.Int64Attribute{ - Computed: true, - }, - "sort": schema.StringAttribute{ - Computed: true, - }, - "total_pages": schema.Int64Attribute{ - Computed: true, - }, - "total_rows": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: PaginationType{ - ObjectType: types.ObjectType{ - AttrTypes: PaginationValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - }, - "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", - ), - }, - }, - "size": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of items to be returned on each page.", - MarkdownDescription: "Number of items to be returned on each page.", - }, - "sort": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "Sorting of the items to be returned on each page.", - MarkdownDescription: "Sorting of the items to be returned on each page.", - Validators: []validator.String{ - stringvalidator.OneOf( - "index.desc", - "index.asc", - "id.desc", - "id.asc", - "is_deletable.desc", - "is_deletable.asc", - "name.asc", - "name.desc", - "status.asc", - "status.desc", - ), - }, - }, - }, - } -} - -type InstancesModel struct { - Instances types.List `tfsdk:"instances"` - Page types.Int64 `tfsdk:"page"` - Pagination PaginationValue `tfsdk:"pagination"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Size types.Int64 `tfsdk:"size"` - Sort types.String `tfsdk:"sort"` -} - -var _ basetypes.ObjectTypable = InstancesType{} - -type InstancesType struct { - basetypes.ObjectType -} - -func (t InstancesType) Equal(o attr.Type) bool { - other, ok := o.(InstancesType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t InstancesType) String() string { - return "InstancesType" -} - -func (t InstancesType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return nil, diags - } - - idVal, ok := idAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.StringValue, was: %T`, idAttribute)) - } - - isDeletableAttribute, ok := attributes["is_deletable"] - - if !ok { - diags.AddError( - "Attribute Missing", - `is_deletable is missing from object`) - - return nil, diags - } - - isDeletableVal, ok := isDeletableAttribute.(basetypes.BoolValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`is_deletable expected to be basetypes.BoolValue, was: %T`, isDeletableAttribute)) - } - - nameAttribute, ok := attributes["name"] - - if !ok { - diags.AddError( - "Attribute Missing", - `name is missing from object`) - - return nil, diags - } - - nameVal, ok := nameAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`name expected to be basetypes.StringValue, was: %T`, nameAttribute)) - } - - statusAttribute, ok := attributes["status"] - - if !ok { - diags.AddError( - "Attribute Missing", - `status is missing from object`) - - return nil, diags - } - - statusVal, ok := statusAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`status expected to be basetypes.StringValue, was: %T`, statusAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return InstancesValue{ - Id: idVal, - IsDeletable: isDeletableVal, - Name: nameVal, - Status: statusVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewInstancesValueNull() InstancesValue { - return InstancesValue{ - state: attr.ValueStateNull, - } -} - -func NewInstancesValueUnknown() InstancesValue { - return InstancesValue{ - state: attr.ValueStateUnknown, - } -} - -func NewInstancesValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (InstancesValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing InstancesValue Attribute Value", - "While creating a InstancesValue value, a missing attribute value was detected. "+ - "A InstancesValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("InstancesValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid InstancesValue Attribute Type", - "While creating a InstancesValue value, an invalid attribute value was detected. "+ - "A InstancesValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("InstancesValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("InstancesValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra InstancesValue Attribute Value", - "While creating a InstancesValue value, an extra attribute value was detected. "+ - "A InstancesValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra InstancesValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewInstancesValueUnknown(), diags - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return NewInstancesValueUnknown(), diags - } - - idVal, ok := idAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.StringValue, was: %T`, idAttribute)) - } - - isDeletableAttribute, ok := attributes["is_deletable"] - - if !ok { - diags.AddError( - "Attribute Missing", - `is_deletable is missing from object`) - - return NewInstancesValueUnknown(), diags - } - - isDeletableVal, ok := isDeletableAttribute.(basetypes.BoolValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`is_deletable expected to be basetypes.BoolValue, was: %T`, isDeletableAttribute)) - } - - nameAttribute, ok := attributes["name"] - - if !ok { - diags.AddError( - "Attribute Missing", - `name is missing from object`) - - return NewInstancesValueUnknown(), diags - } - - nameVal, ok := nameAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`name expected to be basetypes.StringValue, was: %T`, nameAttribute)) - } - - statusAttribute, ok := attributes["status"] - - if !ok { - diags.AddError( - "Attribute Missing", - `status is missing from object`) - - return NewInstancesValueUnknown(), diags - } - - statusVal, ok := statusAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`status expected to be basetypes.StringValue, was: %T`, statusAttribute)) - } - - if diags.HasError() { - return NewInstancesValueUnknown(), diags - } - - return InstancesValue{ - Id: idVal, - IsDeletable: isDeletableVal, - Name: nameVal, - Status: statusVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewInstancesValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) InstancesValue { - object, diags := NewInstancesValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewInstancesValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t InstancesType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewInstancesValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewInstancesValueUnknown(), nil - } - - if in.IsNull() { - return NewInstancesValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewInstancesValueMust(InstancesValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t InstancesType) ValueType(ctx context.Context) attr.Value { - return InstancesValue{} -} - -var _ basetypes.ObjectValuable = InstancesValue{} - -type InstancesValue struct { - Id basetypes.StringValue `tfsdk:"id"` - IsDeletable basetypes.BoolValue `tfsdk:"is_deletable"` - Name basetypes.StringValue `tfsdk:"name"` - Status basetypes.StringValue `tfsdk:"status"` - state attr.ValueState -} - -func (v InstancesValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 4) - - var val tftypes.Value - var err error - - attrTypes["id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["is_deletable"] = basetypes.BoolType{}.TerraformType(ctx) - attrTypes["name"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["status"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 4) - - val, err = v.Id.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["id"] = val - - val, err = v.IsDeletable.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["is_deletable"] = val - - val, err = v.Name.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["name"] = val - - val, err = v.Status.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["status"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v InstancesValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v InstancesValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v InstancesValue) String() string { - return "InstancesValue" -} - -func (v InstancesValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "id": basetypes.StringType{}, - "is_deletable": basetypes.BoolType{}, - "name": basetypes.StringType{}, - "status": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "id": v.Id, - "is_deletable": v.IsDeletable, - "name": v.Name, - "status": v.Status, - }) - - return objVal, diags -} - -func (v InstancesValue) Equal(o attr.Value) bool { - other, ok := o.(InstancesValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Id.Equal(other.Id) { - return false - } - - if !v.IsDeletable.Equal(other.IsDeletable) { - return false - } - - if !v.Name.Equal(other.Name) { - return false - } - - if !v.Status.Equal(other.Status) { - return false - } - - return true -} - -func (v InstancesValue) Type(ctx context.Context) attr.Type { - return InstancesType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v InstancesValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "id": basetypes.StringType{}, - "is_deletable": basetypes.BoolType{}, - "name": basetypes.StringType{}, - "status": basetypes.StringType{}, - } -} - -var _ basetypes.ObjectTypable = PaginationType{} - -type PaginationType struct { - basetypes.ObjectType -} - -func (t PaginationType) Equal(o attr.Type) bool { - other, ok := o.(PaginationType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t PaginationType) String() string { - return "PaginationType" -} - -func (t PaginationType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return nil, diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return nil, diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return nil, diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return nil, diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueNull() PaginationValue { - return PaginationValue{ - state: attr.ValueStateNull, - } -} - -func NewPaginationValueUnknown() PaginationValue { - return PaginationValue{ - state: attr.ValueStateUnknown, - } -} - -func NewPaginationValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (PaginationValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing PaginationValue Attribute Value", - "While creating a PaginationValue value, a missing attribute value was detected. "+ - "A PaginationValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid PaginationValue Attribute Type", - "While creating a PaginationValue value, an invalid attribute value was detected. "+ - "A PaginationValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra PaginationValue Attribute Value", - "While creating a PaginationValue value, an extra attribute value was detected. "+ - "A PaginationValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra PaginationValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) PaginationValue { - object, diags := NewPaginationValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewPaginationValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t PaginationType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewPaginationValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewPaginationValueUnknown(), nil - } - - if in.IsNull() { - return NewPaginationValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewPaginationValueMust(PaginationValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t PaginationType) ValueType(ctx context.Context) attr.Value { - return PaginationValue{} -} - -var _ basetypes.ObjectValuable = PaginationValue{} - -type PaginationValue struct { - Page basetypes.Int64Value `tfsdk:"page"` - Size basetypes.Int64Value `tfsdk:"size"` - Sort basetypes.StringValue `tfsdk:"sort"` - TotalPages basetypes.Int64Value `tfsdk:"total_pages"` - TotalRows basetypes.Int64Value `tfsdk:"total_rows"` - state attr.ValueState -} - -func (v PaginationValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 5) - - var val tftypes.Value - var err error - - attrTypes["page"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["sort"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["total_pages"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["total_rows"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 5) - - val, err = v.Page.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["page"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - val, err = v.Sort.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["sort"] = val - - val, err = v.TotalPages.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_pages"] = val - - val, err = v.TotalRows.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_rows"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v PaginationValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v PaginationValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v PaginationValue) String() string { - return "PaginationValue" -} - -func (v PaginationValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "page": v.Page, - "size": v.Size, - "sort": v.Sort, - "total_pages": v.TotalPages, - "total_rows": v.TotalRows, - }) - - return objVal, diags -} - -func (v PaginationValue) Equal(o attr.Value) bool { - other, ok := o.(PaginationValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Page.Equal(other.Page) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - if !v.Sort.Equal(other.Sort) { - return false - } - - if !v.TotalPages.Equal(other.TotalPages) { - return false - } - - if !v.TotalRows.Equal(other.TotalRows) { - return false - } - - return true -} - -func (v PaginationValue) Type(ctx context.Context) attr.Type { - return PaginationType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v PaginationValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } -} diff --git a/stackit/internal/services/sqlserverflexalpha/instance/resources_gen/instance_resource_gen.go b/stackit/internal/services/sqlserverflexalpha/instance/resources_gen/instance_resource_gen.go deleted file mode 100644 index 671c7fd3..00000000 --- a/stackit/internal/services/sqlserverflexalpha/instance/resources_gen/instance_resource_gen.go +++ /dev/null @@ -1,1597 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package sqlserverflexalpha - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/resource/schema" -) - -func InstanceResourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "backup_schedule": schema.StringAttribute{ - Required: true, - Description: "The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.", - MarkdownDescription: "The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.", - }, - "edition": schema.StringAttribute{ - Computed: true, - Description: "Edition of the MSSQL server instance", - MarkdownDescription: "Edition of the MSSQL server instance", - }, - "encryption": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "kek_key_id": schema.StringAttribute{ - Required: true, - Description: "The key identifier", - MarkdownDescription: "The key identifier", - }, - "kek_key_ring_id": schema.StringAttribute{ - Required: true, - Description: "The keyring identifier", - MarkdownDescription: "The keyring identifier", - }, - "kek_key_version": schema.StringAttribute{ - Required: true, - Description: "The key version", - MarkdownDescription: "The key version", - }, - "service_account": schema.StringAttribute{ - Required: true, - }, - }, - CustomType: EncryptionType{ - ObjectType: types.ObjectType{ - AttrTypes: EncryptionValue{}.AttributeTypes(ctx), - }, - }, - Optional: true, - Computed: true, - Description: "this defines which key to use for storage encryption", - MarkdownDescription: "this defines which key to use for storage encryption", - }, - "flavor_id": schema.StringAttribute{ - Required: true, - Description: "The id of the instance flavor.", - MarkdownDescription: "The id of the instance flavor.", - }, - "id": schema.StringAttribute{ - Computed: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "instance_id": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "is_deletable": schema.BoolAttribute{ - Computed: true, - Description: "Whether the instance can be deleted or not.", - MarkdownDescription: "Whether the instance can be deleted or not.", - }, - "name": schema.StringAttribute{ - Required: true, - Description: "The name of the instance.", - MarkdownDescription: "The name of the instance.", - }, - "network": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "access_scope": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "The network access scope of the instance\n\n⚠️ **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.\n", - MarkdownDescription: "The network access scope of the instance\n\n⚠️ **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.\n", - Validators: []validator.String{ - stringvalidator.OneOf( - "PUBLIC", - "SNA", - ), - }, - Default: stringdefault.StaticString("PUBLIC"), - }, - "acl": schema.ListAttribute{ - ElementType: types.StringType, - Required: true, - Description: "List of IPV4 cidr.", - MarkdownDescription: "List of IPV4 cidr.", - }, - "instance_address": schema.StringAttribute{ - Computed: true, - }, - "router_address": schema.StringAttribute{ - Computed: true, - }, - }, - CustomType: NetworkType{ - ObjectType: types.ObjectType{ - AttrTypes: NetworkValue{}.AttributeTypes(ctx), - }, - }, - Required: true, - Description: "the network configuration of the instance.", - MarkdownDescription: "the network configuration of the instance.", - }, - "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", - ), - }, - }, - "replicas": schema.Int64Attribute{ - Computed: true, - Description: "How many replicas the instance should have.", - MarkdownDescription: "How many replicas the instance should have.", - }, - "retention_days": schema.Int64Attribute{ - Required: true, - Description: "The days for how long the backup files should be stored before cleaned up. 30 to 365", - MarkdownDescription: "The days for how long the backup files should be stored before cleaned up. 30 to 365", - }, - "status": schema.StringAttribute{ - Computed: true, - }, - "storage": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "class": schema.StringAttribute{ - Required: true, - Description: "The storage class for the storage.", - MarkdownDescription: "The storage class for the storage.", - }, - "size": schema.Int64Attribute{ - Required: true, - Description: "The storage size in Gigabytes.", - MarkdownDescription: "The storage size in Gigabytes.", - }, - }, - CustomType: StorageType{ - ObjectType: types.ObjectType{ - AttrTypes: StorageValue{}.AttributeTypes(ctx), - }, - }, - Required: true, - Description: "The object containing information about the storage size and class.", - MarkdownDescription: "The object containing information about the storage size and class.", - }, - "version": schema.StringAttribute{ - Required: true, - Description: "The sqlserver version used for the instance.", - MarkdownDescription: "The sqlserver version used for the instance.", - Validators: []validator.String{ - stringvalidator.OneOf( - "2022", - ), - }, - }, - }, - } -} - -type InstanceModel struct { - BackupSchedule types.String `tfsdk:"backup_schedule"` - Edition types.String `tfsdk:"edition"` - Encryption EncryptionValue `tfsdk:"encryption"` - FlavorId types.String `tfsdk:"flavor_id"` - Id types.String `tfsdk:"id"` - InstanceId types.String `tfsdk:"instance_id"` - IsDeletable types.Bool `tfsdk:"is_deletable"` - Name types.String `tfsdk:"name"` - Network NetworkValue `tfsdk:"network"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Replicas types.Int64 `tfsdk:"replicas"` - RetentionDays types.Int64 `tfsdk:"retention_days"` - Status types.String `tfsdk:"status"` - Storage StorageValue `tfsdk:"storage"` - Version types.String `tfsdk:"version"` -} - -var _ basetypes.ObjectTypable = EncryptionType{} - -type EncryptionType struct { - basetypes.ObjectType -} - -func (t EncryptionType) Equal(o attr.Type) bool { - other, ok := o.(EncryptionType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t EncryptionType) String() string { - return "EncryptionType" -} - -func (t EncryptionType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - kekKeyIdAttribute, ok := attributes["kek_key_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_id is missing from object`) - - return nil, diags - } - - kekKeyIdVal, ok := kekKeyIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_id expected to be basetypes.StringValue, was: %T`, kekKeyIdAttribute)) - } - - kekKeyRingIdAttribute, ok := attributes["kek_key_ring_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_ring_id is missing from object`) - - return nil, diags - } - - kekKeyRingIdVal, ok := kekKeyRingIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_ring_id expected to be basetypes.StringValue, was: %T`, kekKeyRingIdAttribute)) - } - - kekKeyVersionAttribute, ok := attributes["kek_key_version"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_version is missing from object`) - - return nil, diags - } - - kekKeyVersionVal, ok := kekKeyVersionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_version expected to be basetypes.StringValue, was: %T`, kekKeyVersionAttribute)) - } - - serviceAccountAttribute, ok := attributes["service_account"] - - if !ok { - diags.AddError( - "Attribute Missing", - `service_account is missing from object`) - - return nil, diags - } - - serviceAccountVal, ok := serviceAccountAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`service_account expected to be basetypes.StringValue, was: %T`, serviceAccountAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return EncryptionValue{ - KekKeyId: kekKeyIdVal, - KekKeyRingId: kekKeyRingIdVal, - KekKeyVersion: kekKeyVersionVal, - ServiceAccount: serviceAccountVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewEncryptionValueNull() EncryptionValue { - return EncryptionValue{ - state: attr.ValueStateNull, - } -} - -func NewEncryptionValueUnknown() EncryptionValue { - return EncryptionValue{ - state: attr.ValueStateUnknown, - } -} - -func NewEncryptionValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (EncryptionValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing EncryptionValue Attribute Value", - "While creating a EncryptionValue value, a missing attribute value was detected. "+ - "A EncryptionValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("EncryptionValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid EncryptionValue Attribute Type", - "While creating a EncryptionValue value, an invalid attribute value was detected. "+ - "A EncryptionValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("EncryptionValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("EncryptionValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra EncryptionValue Attribute Value", - "While creating a EncryptionValue value, an extra attribute value was detected. "+ - "A EncryptionValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra EncryptionValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewEncryptionValueUnknown(), diags - } - - kekKeyIdAttribute, ok := attributes["kek_key_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_id is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - kekKeyIdVal, ok := kekKeyIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_id expected to be basetypes.StringValue, was: %T`, kekKeyIdAttribute)) - } - - kekKeyRingIdAttribute, ok := attributes["kek_key_ring_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_ring_id is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - kekKeyRingIdVal, ok := kekKeyRingIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_ring_id expected to be basetypes.StringValue, was: %T`, kekKeyRingIdAttribute)) - } - - kekKeyVersionAttribute, ok := attributes["kek_key_version"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_version is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - kekKeyVersionVal, ok := kekKeyVersionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_version expected to be basetypes.StringValue, was: %T`, kekKeyVersionAttribute)) - } - - serviceAccountAttribute, ok := attributes["service_account"] - - if !ok { - diags.AddError( - "Attribute Missing", - `service_account is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - serviceAccountVal, ok := serviceAccountAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`service_account expected to be basetypes.StringValue, was: %T`, serviceAccountAttribute)) - } - - if diags.HasError() { - return NewEncryptionValueUnknown(), diags - } - - return EncryptionValue{ - KekKeyId: kekKeyIdVal, - KekKeyRingId: kekKeyRingIdVal, - KekKeyVersion: kekKeyVersionVal, - ServiceAccount: serviceAccountVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewEncryptionValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) EncryptionValue { - object, diags := NewEncryptionValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewEncryptionValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t EncryptionType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewEncryptionValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewEncryptionValueUnknown(), nil - } - - if in.IsNull() { - return NewEncryptionValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewEncryptionValueMust(EncryptionValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t EncryptionType) ValueType(ctx context.Context) attr.Value { - return EncryptionValue{} -} - -var _ basetypes.ObjectValuable = EncryptionValue{} - -type EncryptionValue struct { - KekKeyId basetypes.StringValue `tfsdk:"kek_key_id"` - KekKeyRingId basetypes.StringValue `tfsdk:"kek_key_ring_id"` - KekKeyVersion basetypes.StringValue `tfsdk:"kek_key_version"` - ServiceAccount basetypes.StringValue `tfsdk:"service_account"` - state attr.ValueState -} - -func (v EncryptionValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 4) - - var val tftypes.Value - var err error - - attrTypes["kek_key_id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["kek_key_ring_id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["kek_key_version"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["service_account"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 4) - - val, err = v.KekKeyId.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["kek_key_id"] = val - - val, err = v.KekKeyRingId.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["kek_key_ring_id"] = val - - val, err = v.KekKeyVersion.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["kek_key_version"] = val - - val, err = v.ServiceAccount.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["service_account"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v EncryptionValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v EncryptionValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v EncryptionValue) String() string { - return "EncryptionValue" -} - -func (v EncryptionValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "kek_key_id": basetypes.StringType{}, - "kek_key_ring_id": basetypes.StringType{}, - "kek_key_version": basetypes.StringType{}, - "service_account": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "kek_key_id": v.KekKeyId, - "kek_key_ring_id": v.KekKeyRingId, - "kek_key_version": v.KekKeyVersion, - "service_account": v.ServiceAccount, - }) - - return objVal, diags -} - -func (v EncryptionValue) Equal(o attr.Value) bool { - other, ok := o.(EncryptionValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.KekKeyId.Equal(other.KekKeyId) { - return false - } - - if !v.KekKeyRingId.Equal(other.KekKeyRingId) { - return false - } - - if !v.KekKeyVersion.Equal(other.KekKeyVersion) { - return false - } - - if !v.ServiceAccount.Equal(other.ServiceAccount) { - return false - } - - return true -} - -func (v EncryptionValue) Type(ctx context.Context) attr.Type { - return EncryptionType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v EncryptionValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "kek_key_id": basetypes.StringType{}, - "kek_key_ring_id": basetypes.StringType{}, - "kek_key_version": basetypes.StringType{}, - "service_account": basetypes.StringType{}, - } -} - -var _ basetypes.ObjectTypable = NetworkType{} - -type NetworkType struct { - basetypes.ObjectType -} - -func (t NetworkType) Equal(o attr.Type) bool { - other, ok := o.(NetworkType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t NetworkType) String() string { - return "NetworkType" -} - -func (t NetworkType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - accessScopeAttribute, ok := attributes["access_scope"] - - if !ok { - diags.AddError( - "Attribute Missing", - `access_scope is missing from object`) - - return nil, diags - } - - accessScopeVal, ok := accessScopeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`access_scope expected to be basetypes.StringValue, was: %T`, accessScopeAttribute)) - } - - aclAttribute, ok := attributes["acl"] - - if !ok { - diags.AddError( - "Attribute Missing", - `acl is missing from object`) - - return nil, diags - } - - aclVal, ok := aclAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`acl expected to be basetypes.ListValue, was: %T`, aclAttribute)) - } - - instanceAddressAttribute, ok := attributes["instance_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `instance_address is missing from object`) - - return nil, diags - } - - instanceAddressVal, ok := instanceAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`instance_address expected to be basetypes.StringValue, was: %T`, instanceAddressAttribute)) - } - - routerAddressAttribute, ok := attributes["router_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `router_address is missing from object`) - - return nil, diags - } - - routerAddressVal, ok := routerAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`router_address expected to be basetypes.StringValue, was: %T`, routerAddressAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return NetworkValue{ - AccessScope: accessScopeVal, - Acl: aclVal, - InstanceAddress: instanceAddressVal, - RouterAddress: routerAddressVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewNetworkValueNull() NetworkValue { - return NetworkValue{ - state: attr.ValueStateNull, - } -} - -func NewNetworkValueUnknown() NetworkValue { - return NetworkValue{ - state: attr.ValueStateUnknown, - } -} - -func NewNetworkValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (NetworkValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing NetworkValue Attribute Value", - "While creating a NetworkValue value, a missing attribute value was detected. "+ - "A NetworkValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("NetworkValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid NetworkValue Attribute Type", - "While creating a NetworkValue value, an invalid attribute value was detected. "+ - "A NetworkValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("NetworkValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("NetworkValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra NetworkValue Attribute Value", - "While creating a NetworkValue value, an extra attribute value was detected. "+ - "A NetworkValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra NetworkValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewNetworkValueUnknown(), diags - } - - accessScopeAttribute, ok := attributes["access_scope"] - - if !ok { - diags.AddError( - "Attribute Missing", - `access_scope is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - accessScopeVal, ok := accessScopeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`access_scope expected to be basetypes.StringValue, was: %T`, accessScopeAttribute)) - } - - aclAttribute, ok := attributes["acl"] - - if !ok { - diags.AddError( - "Attribute Missing", - `acl is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - aclVal, ok := aclAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`acl expected to be basetypes.ListValue, was: %T`, aclAttribute)) - } - - instanceAddressAttribute, ok := attributes["instance_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `instance_address is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - instanceAddressVal, ok := instanceAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`instance_address expected to be basetypes.StringValue, was: %T`, instanceAddressAttribute)) - } - - routerAddressAttribute, ok := attributes["router_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `router_address is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - routerAddressVal, ok := routerAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`router_address expected to be basetypes.StringValue, was: %T`, routerAddressAttribute)) - } - - if diags.HasError() { - return NewNetworkValueUnknown(), diags - } - - return NetworkValue{ - AccessScope: accessScopeVal, - Acl: aclVal, - InstanceAddress: instanceAddressVal, - RouterAddress: routerAddressVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewNetworkValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) NetworkValue { - object, diags := NewNetworkValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewNetworkValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t NetworkType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewNetworkValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewNetworkValueUnknown(), nil - } - - if in.IsNull() { - return NewNetworkValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewNetworkValueMust(NetworkValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t NetworkType) ValueType(ctx context.Context) attr.Value { - return NetworkValue{} -} - -var _ basetypes.ObjectValuable = NetworkValue{} - -type NetworkValue struct { - AccessScope basetypes.StringValue `tfsdk:"access_scope"` - Acl basetypes.ListValue `tfsdk:"acl"` - InstanceAddress basetypes.StringValue `tfsdk:"instance_address"` - RouterAddress basetypes.StringValue `tfsdk:"router_address"` - state attr.ValueState -} - -func (v NetworkValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 4) - - var val tftypes.Value - var err error - - attrTypes["access_scope"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["acl"] = basetypes.ListType{ - ElemType: types.StringType, - }.TerraformType(ctx) - attrTypes["instance_address"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["router_address"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 4) - - val, err = v.AccessScope.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["access_scope"] = val - - val, err = v.Acl.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["acl"] = val - - val, err = v.InstanceAddress.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["instance_address"] = val - - val, err = v.RouterAddress.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["router_address"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v NetworkValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v NetworkValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v NetworkValue) String() string { - return "NetworkValue" -} - -func (v NetworkValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - var aclVal basetypes.ListValue - switch { - case v.Acl.IsUnknown(): - aclVal = types.ListUnknown(types.StringType) - case v.Acl.IsNull(): - aclVal = types.ListNull(types.StringType) - default: - var d diag.Diagnostics - aclVal, d = types.ListValue(types.StringType, v.Acl.Elements()) - diags.Append(d...) - } - - if diags.HasError() { - return types.ObjectUnknown(map[string]attr.Type{ - "access_scope": basetypes.StringType{}, - "acl": basetypes.ListType{ - ElemType: types.StringType, - }, - "instance_address": basetypes.StringType{}, - "router_address": basetypes.StringType{}, - }), diags - } - - attributeTypes := map[string]attr.Type{ - "access_scope": basetypes.StringType{}, - "acl": basetypes.ListType{ - ElemType: types.StringType, - }, - "instance_address": basetypes.StringType{}, - "router_address": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "access_scope": v.AccessScope, - "acl": aclVal, - "instance_address": v.InstanceAddress, - "router_address": v.RouterAddress, - }) - - return objVal, diags -} - -func (v NetworkValue) Equal(o attr.Value) bool { - other, ok := o.(NetworkValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.AccessScope.Equal(other.AccessScope) { - return false - } - - if !v.Acl.Equal(other.Acl) { - return false - } - - if !v.InstanceAddress.Equal(other.InstanceAddress) { - return false - } - - if !v.RouterAddress.Equal(other.RouterAddress) { - return false - } - - return true -} - -func (v NetworkValue) Type(ctx context.Context) attr.Type { - return NetworkType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v NetworkValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "access_scope": basetypes.StringType{}, - "acl": basetypes.ListType{ - ElemType: types.StringType, - }, - "instance_address": basetypes.StringType{}, - "router_address": basetypes.StringType{}, - } -} - -var _ basetypes.ObjectTypable = StorageType{} - -type StorageType struct { - basetypes.ObjectType -} - -func (t StorageType) Equal(o attr.Type) bool { - other, ok := o.(StorageType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t StorageType) String() string { - return "StorageType" -} - -func (t StorageType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - classAttribute, ok := attributes["class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `class is missing from object`) - - return nil, diags - } - - classVal, ok := classAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`class expected to be basetypes.StringValue, was: %T`, classAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return StorageValue{ - Class: classVal, - Size: sizeVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageValueNull() StorageValue { - return StorageValue{ - state: attr.ValueStateNull, - } -} - -func NewStorageValueUnknown() StorageValue { - return StorageValue{ - state: attr.ValueStateUnknown, - } -} - -func NewStorageValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (StorageValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing StorageValue Attribute Value", - "While creating a StorageValue value, a missing attribute value was detected. "+ - "A StorageValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid StorageValue Attribute Type", - "While creating a StorageValue value, an invalid attribute value was detected. "+ - "A StorageValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("StorageValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra StorageValue Attribute Value", - "While creating a StorageValue value, an extra attribute value was detected. "+ - "A StorageValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra StorageValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewStorageValueUnknown(), diags - } - - classAttribute, ok := attributes["class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `class is missing from object`) - - return NewStorageValueUnknown(), diags - } - - classVal, ok := classAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`class expected to be basetypes.StringValue, was: %T`, classAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewStorageValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - if diags.HasError() { - return NewStorageValueUnknown(), diags - } - - return StorageValue{ - Class: classVal, - Size: sizeVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) StorageValue { - object, diags := NewStorageValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewStorageValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t StorageType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewStorageValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewStorageValueUnknown(), nil - } - - if in.IsNull() { - return NewStorageValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewStorageValueMust(StorageValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t StorageType) ValueType(ctx context.Context) attr.Value { - return StorageValue{} -} - -var _ basetypes.ObjectValuable = StorageValue{} - -type StorageValue struct { - Class basetypes.StringValue `tfsdk:"class"` - Size basetypes.Int64Value `tfsdk:"size"` - state attr.ValueState -} - -func (v StorageValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 2) - - var val tftypes.Value - var err error - - attrTypes["class"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 2) - - val, err = v.Class.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["class"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v StorageValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v StorageValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v StorageValue) String() string { - return "StorageValue" -} - -func (v StorageValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "class": basetypes.StringType{}, - "size": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "class": v.Class, - "size": v.Size, - }) - - return objVal, diags -} - -func (v StorageValue) Equal(o attr.Value) bool { - other, ok := o.(StorageValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Class.Equal(other.Class) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - return true -} - -func (v StorageValue) Type(ctx context.Context) attr.Type { - return StorageType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v StorageValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "class": basetypes.StringType{}, - "size": basetypes.Int64Type{}, - } -} diff --git a/stackit/internal/services/sqlserverflexalpha/user/datasources_gen/user_data_source_gen.go b/stackit/internal/services/sqlserverflexalpha/user/datasources_gen/user_data_source_gen.go deleted file mode 100644 index 329469ea..00000000 --- a/stackit/internal/services/sqlserverflexalpha/user/datasources_gen/user_data_source_gen.go +++ /dev/null @@ -1,1118 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package sqlserverflexalpha - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -func UserDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "instance_id": schema.StringAttribute{ - Required: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "page": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of the page of items list to be returned.", - MarkdownDescription: "Number of the page of items list to be returned.", - }, - "pagination": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "page": schema.Int64Attribute{ - Computed: true, - }, - "size": schema.Int64Attribute{ - Computed: true, - }, - "sort": schema.StringAttribute{ - Computed: true, - }, - "total_pages": schema.Int64Attribute{ - Computed: true, - }, - "total_rows": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: PaginationType{ - ObjectType: types.ObjectType{ - AttrTypes: PaginationValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - }, - "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", - ), - }, - }, - "size": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of items to be returned on each page.", - MarkdownDescription: "Number of items to be returned on each page.", - }, - "sort": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "Sorting of the users to be returned on each page.", - MarkdownDescription: "Sorting of the users to be returned on each page.", - Validators: []validator.String{ - stringvalidator.OneOf( - "id.asc", - "id.desc", - "index.desc", - "index.asc", - "name.desc", - "name.asc", - "status.desc", - "status.asc", - ), - }, - }, - "users": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "tf_original_api_id": schema.Int64Attribute{ - Computed: true, - Description: "The ID of the user.", - MarkdownDescription: "The ID of the user.", - }, - "status": schema.StringAttribute{ - Computed: true, - Description: "The current status of the user.", - MarkdownDescription: "The current status of the user.", - }, - "username": schema.StringAttribute{ - Computed: true, - Description: "The name of the user.", - MarkdownDescription: "The name of the user.", - }, - }, - CustomType: UsersType{ - ObjectType: types.ObjectType{ - AttrTypes: UsersValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "List of all users inside an instance", - MarkdownDescription: "List of all users inside an instance", - }, - }, - } -} - -type UserModel struct { - InstanceId types.String `tfsdk:"instance_id"` - Page types.Int64 `tfsdk:"page"` - Pagination PaginationValue `tfsdk:"pagination"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Size types.Int64 `tfsdk:"size"` - Sort types.String `tfsdk:"sort"` - Users types.List `tfsdk:"users"` -} - -var _ basetypes.ObjectTypable = PaginationType{} - -type PaginationType struct { - basetypes.ObjectType -} - -func (t PaginationType) Equal(o attr.Type) bool { - other, ok := o.(PaginationType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t PaginationType) String() string { - return "PaginationType" -} - -func (t PaginationType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return nil, diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return nil, diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return nil, diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return nil, diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueNull() PaginationValue { - return PaginationValue{ - state: attr.ValueStateNull, - } -} - -func NewPaginationValueUnknown() PaginationValue { - return PaginationValue{ - state: attr.ValueStateUnknown, - } -} - -func NewPaginationValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (PaginationValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing PaginationValue Attribute Value", - "While creating a PaginationValue value, a missing attribute value was detected. "+ - "A PaginationValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid PaginationValue Attribute Type", - "While creating a PaginationValue value, an invalid attribute value was detected. "+ - "A PaginationValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra PaginationValue Attribute Value", - "While creating a PaginationValue value, an extra attribute value was detected. "+ - "A PaginationValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra PaginationValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) PaginationValue { - object, diags := NewPaginationValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewPaginationValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t PaginationType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewPaginationValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewPaginationValueUnknown(), nil - } - - if in.IsNull() { - return NewPaginationValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewPaginationValueMust(PaginationValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t PaginationType) ValueType(ctx context.Context) attr.Value { - return PaginationValue{} -} - -var _ basetypes.ObjectValuable = PaginationValue{} - -type PaginationValue struct { - Page basetypes.Int64Value `tfsdk:"page"` - Size basetypes.Int64Value `tfsdk:"size"` - Sort basetypes.StringValue `tfsdk:"sort"` - TotalPages basetypes.Int64Value `tfsdk:"total_pages"` - TotalRows basetypes.Int64Value `tfsdk:"total_rows"` - state attr.ValueState -} - -func (v PaginationValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 5) - - var val tftypes.Value - var err error - - attrTypes["page"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["sort"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["total_pages"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["total_rows"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 5) - - val, err = v.Page.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["page"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - val, err = v.Sort.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["sort"] = val - - val, err = v.TotalPages.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_pages"] = val - - val, err = v.TotalRows.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_rows"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v PaginationValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v PaginationValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v PaginationValue) String() string { - return "PaginationValue" -} - -func (v PaginationValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "page": v.Page, - "size": v.Size, - "sort": v.Sort, - "total_pages": v.TotalPages, - "total_rows": v.TotalRows, - }) - - return objVal, diags -} - -func (v PaginationValue) Equal(o attr.Value) bool { - other, ok := o.(PaginationValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Page.Equal(other.Page) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - if !v.Sort.Equal(other.Sort) { - return false - } - - if !v.TotalPages.Equal(other.TotalPages) { - return false - } - - if !v.TotalRows.Equal(other.TotalRows) { - return false - } - - return true -} - -func (v PaginationValue) Type(ctx context.Context) attr.Type { - return PaginationType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v PaginationValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } -} - -var _ basetypes.ObjectTypable = UsersType{} - -type UsersType struct { - basetypes.ObjectType -} - -func (t UsersType) Equal(o attr.Type) bool { - other, ok := o.(UsersType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t UsersType) String() string { - return "UsersType" -} - -func (t UsersType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return nil, diags - } - - idVal, ok := idAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.Int64Value, was: %T`, idAttribute)) - } - - statusAttribute, ok := attributes["status"] - - if !ok { - diags.AddError( - "Attribute Missing", - `status is missing from object`) - - return nil, diags - } - - statusVal, ok := statusAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`status expected to be basetypes.StringValue, was: %T`, statusAttribute)) - } - - usernameAttribute, ok := attributes["username"] - - if !ok { - diags.AddError( - "Attribute Missing", - `username is missing from object`) - - return nil, diags - } - - usernameVal, ok := usernameAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`username expected to be basetypes.StringValue, was: %T`, usernameAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return UsersValue{ - Id: idVal, - Status: statusVal, - Username: usernameVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewUsersValueNull() UsersValue { - return UsersValue{ - state: attr.ValueStateNull, - } -} - -func NewUsersValueUnknown() UsersValue { - return UsersValue{ - state: attr.ValueStateUnknown, - } -} - -func NewUsersValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (UsersValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing UsersValue Attribute Value", - "While creating a UsersValue value, a missing attribute value was detected. "+ - "A UsersValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("UsersValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid UsersValue Attribute Type", - "While creating a UsersValue value, an invalid attribute value was detected. "+ - "A UsersValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("UsersValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("UsersValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra UsersValue Attribute Value", - "While creating a UsersValue value, an extra attribute value was detected. "+ - "A UsersValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra UsersValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewUsersValueUnknown(), diags - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return NewUsersValueUnknown(), diags - } - - idVal, ok := idAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.Int64Value, was: %T`, idAttribute)) - } - - statusAttribute, ok := attributes["status"] - - if !ok { - diags.AddError( - "Attribute Missing", - `status is missing from object`) - - return NewUsersValueUnknown(), diags - } - - statusVal, ok := statusAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`status expected to be basetypes.StringValue, was: %T`, statusAttribute)) - } - - usernameAttribute, ok := attributes["username"] - - if !ok { - diags.AddError( - "Attribute Missing", - `username is missing from object`) - - return NewUsersValueUnknown(), diags - } - - usernameVal, ok := usernameAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`username expected to be basetypes.StringValue, was: %T`, usernameAttribute)) - } - - if diags.HasError() { - return NewUsersValueUnknown(), diags - } - - return UsersValue{ - Id: idVal, - Status: statusVal, - Username: usernameVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewUsersValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) UsersValue { - object, diags := NewUsersValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewUsersValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t UsersType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewUsersValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewUsersValueUnknown(), nil - } - - if in.IsNull() { - return NewUsersValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewUsersValueMust(UsersValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t UsersType) ValueType(ctx context.Context) attr.Value { - return UsersValue{} -} - -var _ basetypes.ObjectValuable = UsersValue{} - -type UsersValue struct { - Id basetypes.Int64Value `tfsdk:"id"` - Status basetypes.StringValue `tfsdk:"status"` - Username basetypes.StringValue `tfsdk:"username"` - state attr.ValueState -} - -func (v UsersValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 3) - - var val tftypes.Value - var err error - - attrTypes["id"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["status"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["username"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 3) - - val, err = v.Id.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["id"] = val - - val, err = v.Status.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["status"] = val - - val, err = v.Username.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["username"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v UsersValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v UsersValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v UsersValue) String() string { - return "UsersValue" -} - -func (v UsersValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "id": basetypes.Int64Type{}, - "status": basetypes.StringType{}, - "username": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "id": v.Id, - "status": v.Status, - "username": v.Username, - }) - - return objVal, diags -} - -func (v UsersValue) Equal(o attr.Value) bool { - other, ok := o.(UsersValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Id.Equal(other.Id) { - return false - } - - if !v.Status.Equal(other.Status) { - return false - } - - if !v.Username.Equal(other.Username) { - return false - } - - return true -} - -func (v UsersValue) Type(ctx context.Context) attr.Type { - return UsersType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v UsersValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "id": basetypes.Int64Type{}, - "status": basetypes.StringType{}, - "username": basetypes.StringType{}, - } -} diff --git a/stackit/internal/services/sqlserverflexalpha/user/resources_gen/user_resource_gen.go b/stackit/internal/services/sqlserverflexalpha/user/resources_gen/user_resource_gen.go deleted file mode 100644 index 2b456e79..00000000 --- a/stackit/internal/services/sqlserverflexalpha/user/resources_gen/user_resource_gen.go +++ /dev/null @@ -1,111 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package sqlserverflexalpha - -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 UserResourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "default_database": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "The default database for a user of the instance.", - MarkdownDescription: "The default database for a user of 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.", - MarkdownDescription: "The ID of the user.", - }, - "instance_id": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "password": schema.StringAttribute{ - Computed: true, - 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, - 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", - ), - }, - }, - "roles": schema.ListAttribute{ - ElementType: types.StringType, - Required: true, - Description: "A list containing the user roles for the instance.", - MarkdownDescription: "A list containing the user roles for the instance.", - }, - "status": schema.StringAttribute{ - Computed: true, - Description: "The current status of the user.", - MarkdownDescription: "The current status of the user.", - }, - "uri": schema.StringAttribute{ - Computed: true, - Description: "The connection string for the user to the instance.", - MarkdownDescription: "The connection string for the user to the instance.", - }, - "user_id": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "The ID of the user.", - MarkdownDescription: "The ID of the user.", - }, - "username": schema.StringAttribute{ - Required: true, - Description: "The name of the user.", - MarkdownDescription: "The name of the user.", - }, - }, - } -} - -type UserModel struct { - DefaultDatabase types.String `tfsdk:"default_database"` - Host types.String `tfsdk:"host"` - Id types.Int64 `tfsdk:"id"` - InstanceId types.String `tfsdk:"instance_id"` - 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"` - Status types.String `tfsdk:"status"` - Uri types.String `tfsdk:"uri"` - UserId types.Int64 `tfsdk:"user_id"` - Username types.String `tfsdk:"username"` -} diff --git a/stackit/internal/services/sqlserverflexbeta/database/datasources_gen/database_data_source_gen.go b/stackit/internal/services/sqlserverflexbeta/database/datasources_gen/database_data_source_gen.go deleted file mode 100644 index 92b1064e..00000000 --- a/stackit/internal/services/sqlserverflexbeta/database/datasources_gen/database_data_source_gen.go +++ /dev/null @@ -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"` -} diff --git a/stackit/internal/services/sqlserverflexbeta/database/datasources_gen/databases_data_source_gen.go b/stackit/internal/services/sqlserverflexbeta/database/datasources_gen/databases_data_source_gen.go deleted file mode 100644 index 71ec8fb4..00000000 --- a/stackit/internal/services/sqlserverflexbeta/database/datasources_gen/databases_data_source_gen.go +++ /dev/null @@ -1,1180 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package sqlserverflexbeta - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -func DatabasesDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "databases": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "created": schema.StringAttribute{ - Computed: true, - Description: "The date when the database was created in RFC3339 format.", - MarkdownDescription: "The date when the database was created in RFC3339 format.", - }, - "id": schema.Int64Attribute{ - Computed: true, - Description: "The id of the database.", - MarkdownDescription: "The id of the database.", - }, - "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.", - }, - }, - CustomType: DatabasesType{ - ObjectType: types.ObjectType{ - AttrTypes: DatabasesValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "A list containing all databases for the instance.", - MarkdownDescription: "A list containing all databases for the instance.", - }, - "instance_id": schema.StringAttribute{ - Required: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "page": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of the page of items list to be returned.", - MarkdownDescription: "Number of the page of items list to be returned.", - }, - "pagination": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "page": schema.Int64Attribute{ - Computed: true, - }, - "size": schema.Int64Attribute{ - Computed: true, - }, - "sort": schema.StringAttribute{ - Computed: true, - }, - "total_pages": schema.Int64Attribute{ - Computed: true, - }, - "total_rows": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: PaginationType{ - ObjectType: types.ObjectType{ - AttrTypes: PaginationValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - }, - "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", - ), - }, - }, - "size": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of items to be returned on each page.", - MarkdownDescription: "Number of items to be returned on each page.", - }, - "sort": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "Sorting of the databases to be returned on each page.", - MarkdownDescription: "Sorting of the databases to be returned on each page.", - Validators: []validator.String{ - stringvalidator.OneOf( - "created_at.desc", - "created_at.asc", - "database_id.desc", - "database_id.asc", - "database_name.desc", - "database_name.asc", - "database_owner.desc", - "database_owner.asc", - "index.asc", - "index.desc", - ), - }, - }, - }, - } -} - -type DatabasesModel struct { - Databases types.List `tfsdk:"databases"` - InstanceId types.String `tfsdk:"instance_id"` - Page types.Int64 `tfsdk:"page"` - Pagination PaginationValue `tfsdk:"pagination"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Size types.Int64 `tfsdk:"size"` - Sort types.String `tfsdk:"sort"` -} - -var _ basetypes.ObjectTypable = DatabasesType{} - -type DatabasesType struct { - basetypes.ObjectType -} - -func (t DatabasesType) Equal(o attr.Type) bool { - other, ok := o.(DatabasesType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t DatabasesType) String() string { - return "DatabasesType" -} - -func (t DatabasesType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - createdAttribute, ok := attributes["created"] - - if !ok { - diags.AddError( - "Attribute Missing", - `created is missing from object`) - - return nil, diags - } - - createdVal, ok := createdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`created expected to be basetypes.StringValue, was: %T`, createdAttribute)) - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return nil, diags - } - - idVal, ok := idAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.Int64Value, was: %T`, idAttribute)) - } - - nameAttribute, ok := attributes["name"] - - if !ok { - diags.AddError( - "Attribute Missing", - `name is missing from object`) - - return nil, diags - } - - nameVal, ok := nameAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`name expected to be basetypes.StringValue, was: %T`, nameAttribute)) - } - - ownerAttribute, ok := attributes["owner"] - - if !ok { - diags.AddError( - "Attribute Missing", - `owner is missing from object`) - - return nil, diags - } - - ownerVal, ok := ownerAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`owner expected to be basetypes.StringValue, was: %T`, ownerAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return DatabasesValue{ - Created: createdVal, - Id: idVal, - Name: nameVal, - Owner: ownerVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewDatabasesValueNull() DatabasesValue { - return DatabasesValue{ - state: attr.ValueStateNull, - } -} - -func NewDatabasesValueUnknown() DatabasesValue { - return DatabasesValue{ - state: attr.ValueStateUnknown, - } -} - -func NewDatabasesValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (DatabasesValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing DatabasesValue Attribute Value", - "While creating a DatabasesValue value, a missing attribute value was detected. "+ - "A DatabasesValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("DatabasesValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid DatabasesValue Attribute Type", - "While creating a DatabasesValue value, an invalid attribute value was detected. "+ - "A DatabasesValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("DatabasesValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("DatabasesValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra DatabasesValue Attribute Value", - "While creating a DatabasesValue value, an extra attribute value was detected. "+ - "A DatabasesValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra DatabasesValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewDatabasesValueUnknown(), diags - } - - createdAttribute, ok := attributes["created"] - - if !ok { - diags.AddError( - "Attribute Missing", - `created is missing from object`) - - return NewDatabasesValueUnknown(), diags - } - - createdVal, ok := createdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`created expected to be basetypes.StringValue, was: %T`, createdAttribute)) - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return NewDatabasesValueUnknown(), diags - } - - idVal, ok := idAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.Int64Value, was: %T`, idAttribute)) - } - - nameAttribute, ok := attributes["name"] - - if !ok { - diags.AddError( - "Attribute Missing", - `name is missing from object`) - - return NewDatabasesValueUnknown(), diags - } - - nameVal, ok := nameAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`name expected to be basetypes.StringValue, was: %T`, nameAttribute)) - } - - ownerAttribute, ok := attributes["owner"] - - if !ok { - diags.AddError( - "Attribute Missing", - `owner is missing from object`) - - return NewDatabasesValueUnknown(), diags - } - - ownerVal, ok := ownerAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`owner expected to be basetypes.StringValue, was: %T`, ownerAttribute)) - } - - if diags.HasError() { - return NewDatabasesValueUnknown(), diags - } - - return DatabasesValue{ - Created: createdVal, - Id: idVal, - Name: nameVal, - Owner: ownerVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewDatabasesValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) DatabasesValue { - object, diags := NewDatabasesValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewDatabasesValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t DatabasesType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewDatabasesValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewDatabasesValueUnknown(), nil - } - - if in.IsNull() { - return NewDatabasesValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewDatabasesValueMust(DatabasesValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t DatabasesType) ValueType(ctx context.Context) attr.Value { - return DatabasesValue{} -} - -var _ basetypes.ObjectValuable = DatabasesValue{} - -type DatabasesValue struct { - Created basetypes.StringValue `tfsdk:"created"` - Id basetypes.Int64Value `tfsdk:"id"` - Name basetypes.StringValue `tfsdk:"name"` - Owner basetypes.StringValue `tfsdk:"owner"` - state attr.ValueState -} - -func (v DatabasesValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 4) - - var val tftypes.Value - var err error - - attrTypes["created"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["id"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["name"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["owner"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 4) - - val, err = v.Created.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["created"] = val - - val, err = v.Id.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["id"] = val - - val, err = v.Name.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["name"] = val - - val, err = v.Owner.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["owner"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v DatabasesValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v DatabasesValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v DatabasesValue) String() string { - return "DatabasesValue" -} - -func (v DatabasesValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "created": basetypes.StringType{}, - "id": basetypes.Int64Type{}, - "name": basetypes.StringType{}, - "owner": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "created": v.Created, - "id": v.Id, - "name": v.Name, - "owner": v.Owner, - }) - - return objVal, diags -} - -func (v DatabasesValue) Equal(o attr.Value) bool { - other, ok := o.(DatabasesValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Created.Equal(other.Created) { - return false - } - - if !v.Id.Equal(other.Id) { - return false - } - - if !v.Name.Equal(other.Name) { - return false - } - - if !v.Owner.Equal(other.Owner) { - return false - } - - return true -} - -func (v DatabasesValue) Type(ctx context.Context) attr.Type { - return DatabasesType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v DatabasesValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "created": basetypes.StringType{}, - "id": basetypes.Int64Type{}, - "name": basetypes.StringType{}, - "owner": basetypes.StringType{}, - } -} - -var _ basetypes.ObjectTypable = PaginationType{} - -type PaginationType struct { - basetypes.ObjectType -} - -func (t PaginationType) Equal(o attr.Type) bool { - other, ok := o.(PaginationType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t PaginationType) String() string { - return "PaginationType" -} - -func (t PaginationType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return nil, diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return nil, diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return nil, diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return nil, diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueNull() PaginationValue { - return PaginationValue{ - state: attr.ValueStateNull, - } -} - -func NewPaginationValueUnknown() PaginationValue { - return PaginationValue{ - state: attr.ValueStateUnknown, - } -} - -func NewPaginationValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (PaginationValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing PaginationValue Attribute Value", - "While creating a PaginationValue value, a missing attribute value was detected. "+ - "A PaginationValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid PaginationValue Attribute Type", - "While creating a PaginationValue value, an invalid attribute value was detected. "+ - "A PaginationValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra PaginationValue Attribute Value", - "While creating a PaginationValue value, an extra attribute value was detected. "+ - "A PaginationValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra PaginationValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) PaginationValue { - object, diags := NewPaginationValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewPaginationValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t PaginationType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewPaginationValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewPaginationValueUnknown(), nil - } - - if in.IsNull() { - return NewPaginationValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewPaginationValueMust(PaginationValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t PaginationType) ValueType(ctx context.Context) attr.Value { - return PaginationValue{} -} - -var _ basetypes.ObjectValuable = PaginationValue{} - -type PaginationValue struct { - Page basetypes.Int64Value `tfsdk:"page"` - Size basetypes.Int64Value `tfsdk:"size"` - Sort basetypes.StringValue `tfsdk:"sort"` - TotalPages basetypes.Int64Value `tfsdk:"total_pages"` - TotalRows basetypes.Int64Value `tfsdk:"total_rows"` - state attr.ValueState -} - -func (v PaginationValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 5) - - var val tftypes.Value - var err error - - attrTypes["page"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["sort"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["total_pages"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["total_rows"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 5) - - val, err = v.Page.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["page"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - val, err = v.Sort.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["sort"] = val - - val, err = v.TotalPages.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_pages"] = val - - val, err = v.TotalRows.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_rows"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v PaginationValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v PaginationValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v PaginationValue) String() string { - return "PaginationValue" -} - -func (v PaginationValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "page": v.Page, - "size": v.Size, - "sort": v.Sort, - "total_pages": v.TotalPages, - "total_rows": v.TotalRows, - }) - - return objVal, diags -} - -func (v PaginationValue) Equal(o attr.Value) bool { - other, ok := o.(PaginationValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Page.Equal(other.Page) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - if !v.Sort.Equal(other.Sort) { - return false - } - - if !v.TotalPages.Equal(other.TotalPages) { - return false - } - - if !v.TotalRows.Equal(other.TotalRows) { - return false - } - - return true -} - -func (v PaginationValue) Type(ctx context.Context) attr.Type { - return PaginationType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v PaginationValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } -} diff --git a/stackit/internal/services/sqlserverflexbeta/database/resources_gen/database_resource_gen.go b/stackit/internal/services/sqlserverflexbeta/database/resources_gen/database_resource_gen.go deleted file mode 100644 index dccae0c4..00000000 --- a/stackit/internal/services/sqlserverflexbeta/database/resources_gen/database_resource_gen.go +++ /dev/null @@ -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"` -} diff --git a/stackit/internal/services/sqlserverflexbeta/flavor/datasources_gen/flavor_data_source_gen.go b/stackit/internal/services/sqlserverflexbeta/flavor/datasources_gen/flavor_data_source_gen.go deleted file mode 100644 index a766197e..00000000 --- a/stackit/internal/services/sqlserverflexbeta/flavor/datasources_gen/flavor_data_source_gen.go +++ /dev/null @@ -1,1909 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package sqlserverflexbeta - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -func FlavorDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "flavors": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "cpu": schema.Int64Attribute{ - Computed: true, - Description: "The cpu count of the instance.", - MarkdownDescription: "The cpu count of the instance.", - }, - "description": schema.StringAttribute{ - Computed: true, - Description: "The flavor description.", - MarkdownDescription: "The flavor description.", - }, - "id": schema.StringAttribute{ - Computed: true, - Description: "The id of the instance flavor.", - MarkdownDescription: "The id of the instance flavor.", - }, - "max_gb": schema.Int64Attribute{ - Computed: true, - Description: "maximum storage which can be ordered for the flavor in Gigabyte.", - MarkdownDescription: "maximum storage which can be ordered for the flavor in Gigabyte.", - }, - "memory": schema.Int64Attribute{ - Computed: true, - Description: "The memory of the instance in Gibibyte.", - MarkdownDescription: "The memory of the instance in Gibibyte.", - }, - "min_gb": schema.Int64Attribute{ - Computed: true, - Description: "minimum storage which is required to order in Gigabyte.", - MarkdownDescription: "minimum storage which is required to order in Gigabyte.", - }, - "node_type": schema.StringAttribute{ - Computed: true, - Description: "defines the nodeType it can be either single or HA", - MarkdownDescription: "defines the nodeType it can be either single or HA", - }, - "storage_classes": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "class": schema.StringAttribute{ - Computed: true, - }, - "max_io_per_sec": schema.Int64Attribute{ - Computed: true, - }, - "max_through_in_mb": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: StorageClassesType{ - ObjectType: types.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "maximum storage which can be ordered for the flavor in Gigabyte.", - MarkdownDescription: "maximum storage which can be ordered for the flavor in Gigabyte.", - }, - }, - CustomType: FlavorsType{ - ObjectType: types.ObjectType{ - AttrTypes: FlavorsValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "List of flavors available for the project.", - MarkdownDescription: "List of flavors available for the project.", - }, - "page": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of the page of items list to be returned.", - MarkdownDescription: "Number of the page of items list to be returned.", - }, - "pagination": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "page": schema.Int64Attribute{ - Computed: true, - }, - "size": schema.Int64Attribute{ - Computed: true, - }, - "sort": schema.StringAttribute{ - Computed: true, - }, - "total_pages": schema.Int64Attribute{ - Computed: true, - }, - "total_rows": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: PaginationType{ - ObjectType: types.ObjectType{ - AttrTypes: PaginationValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - }, - "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", - ), - }, - }, - "size": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of items to be returned on each page.", - MarkdownDescription: "Number of items to be returned on each page.", - }, - "sort": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "Sorting of the flavors to be returned on each page.", - MarkdownDescription: "Sorting of the flavors to be returned on each page.", - Validators: []validator.String{ - stringvalidator.OneOf( - "index.desc", - "index.asc", - "cpu.desc", - "cpu.asc", - "flavor_description.asc", - "flavor_description.desc", - "id.desc", - "id.asc", - "size_max.desc", - "size_max.asc", - "ram.desc", - "ram.asc", - "size_min.desc", - "size_min.asc", - "storage_class.asc", - "storage_class.desc", - "node_type.asc", - "node_type.desc", - ), - }, - }, - }, - } -} - -type FlavorModel struct { - Flavors types.List `tfsdk:"flavors"` - Page types.Int64 `tfsdk:"page"` - Pagination PaginationValue `tfsdk:"pagination"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Size types.Int64 `tfsdk:"size"` - Sort types.String `tfsdk:"sort"` -} - -var _ basetypes.ObjectTypable = FlavorsType{} - -type FlavorsType struct { - basetypes.ObjectType -} - -func (t FlavorsType) Equal(o attr.Type) bool { - other, ok := o.(FlavorsType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t FlavorsType) String() string { - return "FlavorsType" -} - -func (t FlavorsType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - cpuAttribute, ok := attributes["cpu"] - - if !ok { - diags.AddError( - "Attribute Missing", - `cpu is missing from object`) - - return nil, diags - } - - cpuVal, ok := cpuAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`cpu expected to be basetypes.Int64Value, was: %T`, cpuAttribute)) - } - - descriptionAttribute, ok := attributes["description"] - - if !ok { - diags.AddError( - "Attribute Missing", - `description is missing from object`) - - return nil, diags - } - - descriptionVal, ok := descriptionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`description expected to be basetypes.StringValue, was: %T`, descriptionAttribute)) - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return nil, diags - } - - idVal, ok := idAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.StringValue, was: %T`, idAttribute)) - } - - maxGbAttribute, ok := attributes["max_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_gb is missing from object`) - - return nil, diags - } - - maxGbVal, ok := maxGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_gb expected to be basetypes.Int64Value, was: %T`, maxGbAttribute)) - } - - memoryAttribute, ok := attributes["memory"] - - if !ok { - diags.AddError( - "Attribute Missing", - `memory is missing from object`) - - return nil, diags - } - - memoryVal, ok := memoryAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`memory expected to be basetypes.Int64Value, was: %T`, memoryAttribute)) - } - - minGbAttribute, ok := attributes["min_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `min_gb is missing from object`) - - return nil, diags - } - - minGbVal, ok := minGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`min_gb expected to be basetypes.Int64Value, was: %T`, minGbAttribute)) - } - - nodeTypeAttribute, ok := attributes["node_type"] - - if !ok { - diags.AddError( - "Attribute Missing", - `node_type is missing from object`) - - return nil, diags - } - - nodeTypeVal, ok := nodeTypeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`node_type expected to be basetypes.StringValue, was: %T`, nodeTypeAttribute)) - } - - storageClassesAttribute, ok := attributes["storage_classes"] - - if !ok { - diags.AddError( - "Attribute Missing", - `storage_classes is missing from object`) - - return nil, diags - } - - storageClassesVal, ok := storageClassesAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`storage_classes expected to be basetypes.ListValue, was: %T`, storageClassesAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return FlavorsValue{ - Cpu: cpuVal, - Description: descriptionVal, - Id: idVal, - MaxGb: maxGbVal, - Memory: memoryVal, - MinGb: minGbVal, - NodeType: nodeTypeVal, - StorageClasses: storageClassesVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewFlavorsValueNull() FlavorsValue { - return FlavorsValue{ - state: attr.ValueStateNull, - } -} - -func NewFlavorsValueUnknown() FlavorsValue { - return FlavorsValue{ - state: attr.ValueStateUnknown, - } -} - -func NewFlavorsValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (FlavorsValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing FlavorsValue Attribute Value", - "While creating a FlavorsValue value, a missing attribute value was detected. "+ - "A FlavorsValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("FlavorsValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid FlavorsValue Attribute Type", - "While creating a FlavorsValue value, an invalid attribute value was detected. "+ - "A FlavorsValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("FlavorsValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("FlavorsValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra FlavorsValue Attribute Value", - "While creating a FlavorsValue value, an extra attribute value was detected. "+ - "A FlavorsValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra FlavorsValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewFlavorsValueUnknown(), diags - } - - cpuAttribute, ok := attributes["cpu"] - - if !ok { - diags.AddError( - "Attribute Missing", - `cpu is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - cpuVal, ok := cpuAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`cpu expected to be basetypes.Int64Value, was: %T`, cpuAttribute)) - } - - descriptionAttribute, ok := attributes["description"] - - if !ok { - diags.AddError( - "Attribute Missing", - `description is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - descriptionVal, ok := descriptionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`description expected to be basetypes.StringValue, was: %T`, descriptionAttribute)) - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - idVal, ok := idAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.StringValue, was: %T`, idAttribute)) - } - - maxGbAttribute, ok := attributes["max_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_gb is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - maxGbVal, ok := maxGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_gb expected to be basetypes.Int64Value, was: %T`, maxGbAttribute)) - } - - memoryAttribute, ok := attributes["memory"] - - if !ok { - diags.AddError( - "Attribute Missing", - `memory is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - memoryVal, ok := memoryAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`memory expected to be basetypes.Int64Value, was: %T`, memoryAttribute)) - } - - minGbAttribute, ok := attributes["min_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `min_gb is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - minGbVal, ok := minGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`min_gb expected to be basetypes.Int64Value, was: %T`, minGbAttribute)) - } - - nodeTypeAttribute, ok := attributes["node_type"] - - if !ok { - diags.AddError( - "Attribute Missing", - `node_type is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - nodeTypeVal, ok := nodeTypeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`node_type expected to be basetypes.StringValue, was: %T`, nodeTypeAttribute)) - } - - storageClassesAttribute, ok := attributes["storage_classes"] - - if !ok { - diags.AddError( - "Attribute Missing", - `storage_classes is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - storageClassesVal, ok := storageClassesAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`storage_classes expected to be basetypes.ListValue, was: %T`, storageClassesAttribute)) - } - - if diags.HasError() { - return NewFlavorsValueUnknown(), diags - } - - return FlavorsValue{ - Cpu: cpuVal, - Description: descriptionVal, - Id: idVal, - MaxGb: maxGbVal, - Memory: memoryVal, - MinGb: minGbVal, - NodeType: nodeTypeVal, - StorageClasses: storageClassesVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewFlavorsValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) FlavorsValue { - object, diags := NewFlavorsValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewFlavorsValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t FlavorsType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewFlavorsValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewFlavorsValueUnknown(), nil - } - - if in.IsNull() { - return NewFlavorsValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewFlavorsValueMust(FlavorsValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t FlavorsType) ValueType(ctx context.Context) attr.Value { - return FlavorsValue{} -} - -var _ basetypes.ObjectValuable = FlavorsValue{} - -type FlavorsValue struct { - Cpu basetypes.Int64Value `tfsdk:"cpu"` - Description basetypes.StringValue `tfsdk:"description"` - Id basetypes.StringValue `tfsdk:"id"` - MaxGb basetypes.Int64Value `tfsdk:"max_gb"` - Memory basetypes.Int64Value `tfsdk:"memory"` - MinGb basetypes.Int64Value `tfsdk:"min_gb"` - NodeType basetypes.StringValue `tfsdk:"node_type"` - StorageClasses basetypes.ListValue `tfsdk:"storage_classes"` - state attr.ValueState -} - -func (v FlavorsValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 8) - - var val tftypes.Value - var err error - - attrTypes["cpu"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["description"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["max_gb"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["memory"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["min_gb"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["node_type"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["storage_classes"] = basetypes.ListType{ - ElemType: StorageClassesValue{}.Type(ctx), - }.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 8) - - val, err = v.Cpu.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["cpu"] = val - - val, err = v.Description.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["description"] = val - - val, err = v.Id.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["id"] = val - - val, err = v.MaxGb.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["max_gb"] = val - - val, err = v.Memory.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["memory"] = val - - val, err = v.MinGb.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["min_gb"] = val - - val, err = v.NodeType.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["node_type"] = val - - val, err = v.StorageClasses.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["storage_classes"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v FlavorsValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v FlavorsValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v FlavorsValue) String() string { - return "FlavorsValue" -} - -func (v FlavorsValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - storageClasses := types.ListValueMust( - StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - v.StorageClasses.Elements(), - ) - - if v.StorageClasses.IsNull() { - storageClasses = types.ListNull( - StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - ) - } - - if v.StorageClasses.IsUnknown() { - storageClasses = types.ListUnknown( - StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - ) - } - - attributeTypes := map[string]attr.Type{ - "cpu": basetypes.Int64Type{}, - "description": basetypes.StringType{}, - "id": basetypes.StringType{}, - "max_gb": basetypes.Int64Type{}, - "memory": basetypes.Int64Type{}, - "min_gb": basetypes.Int64Type{}, - "node_type": basetypes.StringType{}, - "storage_classes": basetypes.ListType{ - ElemType: StorageClassesValue{}.Type(ctx), - }, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "cpu": v.Cpu, - "description": v.Description, - "id": v.Id, - "max_gb": v.MaxGb, - "memory": v.Memory, - "min_gb": v.MinGb, - "node_type": v.NodeType, - "storage_classes": storageClasses, - }) - - return objVal, diags -} - -func (v FlavorsValue) Equal(o attr.Value) bool { - other, ok := o.(FlavorsValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Cpu.Equal(other.Cpu) { - return false - } - - if !v.Description.Equal(other.Description) { - return false - } - - if !v.Id.Equal(other.Id) { - return false - } - - if !v.MaxGb.Equal(other.MaxGb) { - return false - } - - if !v.Memory.Equal(other.Memory) { - return false - } - - if !v.MinGb.Equal(other.MinGb) { - return false - } - - if !v.NodeType.Equal(other.NodeType) { - return false - } - - if !v.StorageClasses.Equal(other.StorageClasses) { - return false - } - - return true -} - -func (v FlavorsValue) Type(ctx context.Context) attr.Type { - return FlavorsType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v FlavorsValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "cpu": basetypes.Int64Type{}, - "description": basetypes.StringType{}, - "id": basetypes.StringType{}, - "max_gb": basetypes.Int64Type{}, - "memory": basetypes.Int64Type{}, - "min_gb": basetypes.Int64Type{}, - "node_type": basetypes.StringType{}, - "storage_classes": basetypes.ListType{ - ElemType: StorageClassesValue{}.Type(ctx), - }, - } -} - -var _ basetypes.ObjectTypable = StorageClassesType{} - -type StorageClassesType struct { - basetypes.ObjectType -} - -func (t StorageClassesType) Equal(o attr.Type) bool { - other, ok := o.(StorageClassesType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t StorageClassesType) String() string { - return "StorageClassesType" -} - -func (t StorageClassesType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - classAttribute, ok := attributes["class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `class is missing from object`) - - return nil, diags - } - - classVal, ok := classAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`class expected to be basetypes.StringValue, was: %T`, classAttribute)) - } - - maxIoPerSecAttribute, ok := attributes["max_io_per_sec"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_io_per_sec is missing from object`) - - return nil, diags - } - - maxIoPerSecVal, ok := maxIoPerSecAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_io_per_sec expected to be basetypes.Int64Value, was: %T`, maxIoPerSecAttribute)) - } - - maxThroughInMbAttribute, ok := attributes["max_through_in_mb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_through_in_mb is missing from object`) - - return nil, diags - } - - maxThroughInMbVal, ok := maxThroughInMbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_through_in_mb expected to be basetypes.Int64Value, was: %T`, maxThroughInMbAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return StorageClassesValue{ - Class: classVal, - MaxIoPerSec: maxIoPerSecVal, - MaxThroughInMb: maxThroughInMbVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageClassesValueNull() StorageClassesValue { - return StorageClassesValue{ - state: attr.ValueStateNull, - } -} - -func NewStorageClassesValueUnknown() StorageClassesValue { - return StorageClassesValue{ - state: attr.ValueStateUnknown, - } -} - -func NewStorageClassesValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (StorageClassesValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing StorageClassesValue Attribute Value", - "While creating a StorageClassesValue value, a missing attribute value was detected. "+ - "A StorageClassesValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageClassesValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid StorageClassesValue Attribute Type", - "While creating a StorageClassesValue value, an invalid attribute value was detected. "+ - "A StorageClassesValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageClassesValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("StorageClassesValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra StorageClassesValue Attribute Value", - "While creating a StorageClassesValue value, an extra attribute value was detected. "+ - "A StorageClassesValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra StorageClassesValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewStorageClassesValueUnknown(), diags - } - - classAttribute, ok := attributes["class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `class is missing from object`) - - return NewStorageClassesValueUnknown(), diags - } - - classVal, ok := classAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`class expected to be basetypes.StringValue, was: %T`, classAttribute)) - } - - maxIoPerSecAttribute, ok := attributes["max_io_per_sec"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_io_per_sec is missing from object`) - - return NewStorageClassesValueUnknown(), diags - } - - maxIoPerSecVal, ok := maxIoPerSecAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_io_per_sec expected to be basetypes.Int64Value, was: %T`, maxIoPerSecAttribute)) - } - - maxThroughInMbAttribute, ok := attributes["max_through_in_mb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_through_in_mb is missing from object`) - - return NewStorageClassesValueUnknown(), diags - } - - maxThroughInMbVal, ok := maxThroughInMbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_through_in_mb expected to be basetypes.Int64Value, was: %T`, maxThroughInMbAttribute)) - } - - if diags.HasError() { - return NewStorageClassesValueUnknown(), diags - } - - return StorageClassesValue{ - Class: classVal, - MaxIoPerSec: maxIoPerSecVal, - MaxThroughInMb: maxThroughInMbVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageClassesValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) StorageClassesValue { - object, diags := NewStorageClassesValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewStorageClassesValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t StorageClassesType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewStorageClassesValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewStorageClassesValueUnknown(), nil - } - - if in.IsNull() { - return NewStorageClassesValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewStorageClassesValueMust(StorageClassesValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t StorageClassesType) ValueType(ctx context.Context) attr.Value { - return StorageClassesValue{} -} - -var _ basetypes.ObjectValuable = StorageClassesValue{} - -type StorageClassesValue struct { - Class basetypes.StringValue `tfsdk:"class"` - MaxIoPerSec basetypes.Int64Value `tfsdk:"max_io_per_sec"` - MaxThroughInMb basetypes.Int64Value `tfsdk:"max_through_in_mb"` - state attr.ValueState -} - -func (v StorageClassesValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 3) - - var val tftypes.Value - var err error - - attrTypes["class"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["max_io_per_sec"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["max_through_in_mb"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 3) - - val, err = v.Class.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["class"] = val - - val, err = v.MaxIoPerSec.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["max_io_per_sec"] = val - - val, err = v.MaxThroughInMb.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["max_through_in_mb"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v StorageClassesValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v StorageClassesValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v StorageClassesValue) String() string { - return "StorageClassesValue" -} - -func (v StorageClassesValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "class": basetypes.StringType{}, - "max_io_per_sec": basetypes.Int64Type{}, - "max_through_in_mb": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "class": v.Class, - "max_io_per_sec": v.MaxIoPerSec, - "max_through_in_mb": v.MaxThroughInMb, - }) - - return objVal, diags -} - -func (v StorageClassesValue) Equal(o attr.Value) bool { - other, ok := o.(StorageClassesValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Class.Equal(other.Class) { - return false - } - - if !v.MaxIoPerSec.Equal(other.MaxIoPerSec) { - return false - } - - if !v.MaxThroughInMb.Equal(other.MaxThroughInMb) { - return false - } - - return true -} - -func (v StorageClassesValue) Type(ctx context.Context) attr.Type { - return StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v StorageClassesValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "class": basetypes.StringType{}, - "max_io_per_sec": basetypes.Int64Type{}, - "max_through_in_mb": basetypes.Int64Type{}, - } -} - -var _ basetypes.ObjectTypable = PaginationType{} - -type PaginationType struct { - basetypes.ObjectType -} - -func (t PaginationType) Equal(o attr.Type) bool { - other, ok := o.(PaginationType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t PaginationType) String() string { - return "PaginationType" -} - -func (t PaginationType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return nil, diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return nil, diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return nil, diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return nil, diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueNull() PaginationValue { - return PaginationValue{ - state: attr.ValueStateNull, - } -} - -func NewPaginationValueUnknown() PaginationValue { - return PaginationValue{ - state: attr.ValueStateUnknown, - } -} - -func NewPaginationValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (PaginationValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing PaginationValue Attribute Value", - "While creating a PaginationValue value, a missing attribute value was detected. "+ - "A PaginationValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid PaginationValue Attribute Type", - "While creating a PaginationValue value, an invalid attribute value was detected. "+ - "A PaginationValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra PaginationValue Attribute Value", - "While creating a PaginationValue value, an extra attribute value was detected. "+ - "A PaginationValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra PaginationValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) PaginationValue { - object, diags := NewPaginationValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewPaginationValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t PaginationType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewPaginationValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewPaginationValueUnknown(), nil - } - - if in.IsNull() { - return NewPaginationValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewPaginationValueMust(PaginationValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t PaginationType) ValueType(ctx context.Context) attr.Value { - return PaginationValue{} -} - -var _ basetypes.ObjectValuable = PaginationValue{} - -type PaginationValue struct { - Page basetypes.Int64Value `tfsdk:"page"` - Size basetypes.Int64Value `tfsdk:"size"` - Sort basetypes.StringValue `tfsdk:"sort"` - TotalPages basetypes.Int64Value `tfsdk:"total_pages"` - TotalRows basetypes.Int64Value `tfsdk:"total_rows"` - state attr.ValueState -} - -func (v PaginationValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 5) - - var val tftypes.Value - var err error - - attrTypes["page"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["sort"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["total_pages"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["total_rows"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 5) - - val, err = v.Page.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["page"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - val, err = v.Sort.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["sort"] = val - - val, err = v.TotalPages.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_pages"] = val - - val, err = v.TotalRows.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_rows"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v PaginationValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v PaginationValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v PaginationValue) String() string { - return "PaginationValue" -} - -func (v PaginationValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "page": v.Page, - "size": v.Size, - "sort": v.Sort, - "total_pages": v.TotalPages, - "total_rows": v.TotalRows, - }) - - return objVal, diags -} - -func (v PaginationValue) Equal(o attr.Value) bool { - other, ok := o.(PaginationValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Page.Equal(other.Page) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - if !v.Sort.Equal(other.Sort) { - return false - } - - if !v.TotalPages.Equal(other.TotalPages) { - return false - } - - if !v.TotalRows.Equal(other.TotalRows) { - return false - } - - return true -} - -func (v PaginationValue) Type(ctx context.Context) attr.Type { - return PaginationType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v PaginationValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } -} diff --git a/stackit/internal/services/sqlserverflexbeta/flavors/datasources_gen/flavors_data_source_gen.go b/stackit/internal/services/sqlserverflexbeta/flavors/datasources_gen/flavors_data_source_gen.go deleted file mode 100644 index a9d35ba1..00000000 --- a/stackit/internal/services/sqlserverflexbeta/flavors/datasources_gen/flavors_data_source_gen.go +++ /dev/null @@ -1,1909 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package sqlserverflexbeta - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -func FlavorsDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "flavors": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "cpu": schema.Int64Attribute{ - Computed: true, - Description: "The cpu count of the instance.", - MarkdownDescription: "The cpu count of the instance.", - }, - "description": schema.StringAttribute{ - Computed: true, - Description: "The flavor description.", - MarkdownDescription: "The flavor description.", - }, - "tf_original_api_id": schema.StringAttribute{ - Computed: true, - Description: "The id of the instance flavor.", - MarkdownDescription: "The id of the instance flavor.", - }, - "max_gb": schema.Int64Attribute{ - Computed: true, - Description: "maximum storage which can be ordered for the flavor in Gigabyte.", - MarkdownDescription: "maximum storage which can be ordered for the flavor in Gigabyte.", - }, - "memory": schema.Int64Attribute{ - Computed: true, - Description: "The memory of the instance in Gibibyte.", - MarkdownDescription: "The memory of the instance in Gibibyte.", - }, - "min_gb": schema.Int64Attribute{ - Computed: true, - Description: "minimum storage which is required to order in Gigabyte.", - MarkdownDescription: "minimum storage which is required to order in Gigabyte.", - }, - "node_type": schema.StringAttribute{ - Computed: true, - Description: "defines the nodeType it can be either single or HA", - MarkdownDescription: "defines the nodeType it can be either single or HA", - }, - "storage_classes": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "class": schema.StringAttribute{ - Computed: true, - }, - "max_io_per_sec": schema.Int64Attribute{ - Computed: true, - }, - "max_through_in_mb": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: StorageClassesType{ - ObjectType: types.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "maximum storage which can be ordered for the flavor in Gigabyte.", - MarkdownDescription: "maximum storage which can be ordered for the flavor in Gigabyte.", - }, - }, - CustomType: FlavorsType{ - ObjectType: types.ObjectType{ - AttrTypes: FlavorsValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "List of flavors available for the project.", - MarkdownDescription: "List of flavors available for the project.", - }, - "page": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of the page of items list to be returned.", - MarkdownDescription: "Number of the page of items list to be returned.", - }, - "pagination": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "page": schema.Int64Attribute{ - Computed: true, - }, - "size": schema.Int64Attribute{ - Computed: true, - }, - "sort": schema.StringAttribute{ - Computed: true, - }, - "total_pages": schema.Int64Attribute{ - Computed: true, - }, - "total_rows": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: PaginationType{ - ObjectType: types.ObjectType{ - AttrTypes: PaginationValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - }, - "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", - ), - }, - }, - "size": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of items to be returned on each page.", - MarkdownDescription: "Number of items to be returned on each page.", - }, - "sort": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "Sorting of the flavors to be returned on each page.", - MarkdownDescription: "Sorting of the flavors to be returned on each page.", - Validators: []validator.String{ - stringvalidator.OneOf( - "index.desc", - "index.asc", - "cpu.desc", - "cpu.asc", - "flavor_description.asc", - "flavor_description.desc", - "id.desc", - "id.asc", - "size_max.desc", - "size_max.asc", - "ram.desc", - "ram.asc", - "size_min.desc", - "size_min.asc", - "storage_class.asc", - "storage_class.desc", - "node_type.asc", - "node_type.desc", - ), - }, - }, - }, - } -} - -type FlavorsModel struct { - Flavors types.List `tfsdk:"flavors"` - Page types.Int64 `tfsdk:"page"` - Pagination PaginationValue `tfsdk:"pagination"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Size types.Int64 `tfsdk:"size"` - Sort types.String `tfsdk:"sort"` -} - -var _ basetypes.ObjectTypable = FlavorsType{} - -type FlavorsType struct { - basetypes.ObjectType -} - -func (t FlavorsType) Equal(o attr.Type) bool { - other, ok := o.(FlavorsType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t FlavorsType) String() string { - return "FlavorsType" -} - -func (t FlavorsType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - cpuAttribute, ok := attributes["cpu"] - - if !ok { - diags.AddError( - "Attribute Missing", - `cpu is missing from object`) - - return nil, diags - } - - cpuVal, ok := cpuAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`cpu expected to be basetypes.Int64Value, was: %T`, cpuAttribute)) - } - - descriptionAttribute, ok := attributes["description"] - - if !ok { - diags.AddError( - "Attribute Missing", - `description is missing from object`) - - return nil, diags - } - - descriptionVal, ok := descriptionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`description expected to be basetypes.StringValue, was: %T`, descriptionAttribute)) - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return nil, diags - } - - idVal, ok := idAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.StringValue, was: %T`, idAttribute)) - } - - maxGbAttribute, ok := attributes["max_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_gb is missing from object`) - - return nil, diags - } - - maxGbVal, ok := maxGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_gb expected to be basetypes.Int64Value, was: %T`, maxGbAttribute)) - } - - memoryAttribute, ok := attributes["memory"] - - if !ok { - diags.AddError( - "Attribute Missing", - `memory is missing from object`) - - return nil, diags - } - - memoryVal, ok := memoryAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`memory expected to be basetypes.Int64Value, was: %T`, memoryAttribute)) - } - - minGbAttribute, ok := attributes["min_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `min_gb is missing from object`) - - return nil, diags - } - - minGbVal, ok := minGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`min_gb expected to be basetypes.Int64Value, was: %T`, minGbAttribute)) - } - - nodeTypeAttribute, ok := attributes["node_type"] - - if !ok { - diags.AddError( - "Attribute Missing", - `node_type is missing from object`) - - return nil, diags - } - - nodeTypeVal, ok := nodeTypeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`node_type expected to be basetypes.StringValue, was: %T`, nodeTypeAttribute)) - } - - storageClassesAttribute, ok := attributes["storage_classes"] - - if !ok { - diags.AddError( - "Attribute Missing", - `storage_classes is missing from object`) - - return nil, diags - } - - storageClassesVal, ok := storageClassesAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`storage_classes expected to be basetypes.ListValue, was: %T`, storageClassesAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return FlavorsValue{ - Cpu: cpuVal, - Description: descriptionVal, - Id: idVal, - MaxGb: maxGbVal, - Memory: memoryVal, - MinGb: minGbVal, - NodeType: nodeTypeVal, - StorageClasses: storageClassesVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewFlavorsValueNull() FlavorsValue { - return FlavorsValue{ - state: attr.ValueStateNull, - } -} - -func NewFlavorsValueUnknown() FlavorsValue { - return FlavorsValue{ - state: attr.ValueStateUnknown, - } -} - -func NewFlavorsValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (FlavorsValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing FlavorsValue Attribute Value", - "While creating a FlavorsValue value, a missing attribute value was detected. "+ - "A FlavorsValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("FlavorsValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid FlavorsValue Attribute Type", - "While creating a FlavorsValue value, an invalid attribute value was detected. "+ - "A FlavorsValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("FlavorsValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("FlavorsValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra FlavorsValue Attribute Value", - "While creating a FlavorsValue value, an extra attribute value was detected. "+ - "A FlavorsValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra FlavorsValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewFlavorsValueUnknown(), diags - } - - cpuAttribute, ok := attributes["cpu"] - - if !ok { - diags.AddError( - "Attribute Missing", - `cpu is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - cpuVal, ok := cpuAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`cpu expected to be basetypes.Int64Value, was: %T`, cpuAttribute)) - } - - descriptionAttribute, ok := attributes["description"] - - if !ok { - diags.AddError( - "Attribute Missing", - `description is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - descriptionVal, ok := descriptionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`description expected to be basetypes.StringValue, was: %T`, descriptionAttribute)) - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - idVal, ok := idAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.StringValue, was: %T`, idAttribute)) - } - - maxGbAttribute, ok := attributes["max_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_gb is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - maxGbVal, ok := maxGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_gb expected to be basetypes.Int64Value, was: %T`, maxGbAttribute)) - } - - memoryAttribute, ok := attributes["memory"] - - if !ok { - diags.AddError( - "Attribute Missing", - `memory is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - memoryVal, ok := memoryAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`memory expected to be basetypes.Int64Value, was: %T`, memoryAttribute)) - } - - minGbAttribute, ok := attributes["min_gb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `min_gb is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - minGbVal, ok := minGbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`min_gb expected to be basetypes.Int64Value, was: %T`, minGbAttribute)) - } - - nodeTypeAttribute, ok := attributes["node_type"] - - if !ok { - diags.AddError( - "Attribute Missing", - `node_type is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - nodeTypeVal, ok := nodeTypeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`node_type expected to be basetypes.StringValue, was: %T`, nodeTypeAttribute)) - } - - storageClassesAttribute, ok := attributes["storage_classes"] - - if !ok { - diags.AddError( - "Attribute Missing", - `storage_classes is missing from object`) - - return NewFlavorsValueUnknown(), diags - } - - storageClassesVal, ok := storageClassesAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`storage_classes expected to be basetypes.ListValue, was: %T`, storageClassesAttribute)) - } - - if diags.HasError() { - return NewFlavorsValueUnknown(), diags - } - - return FlavorsValue{ - Cpu: cpuVal, - Description: descriptionVal, - Id: idVal, - MaxGb: maxGbVal, - Memory: memoryVal, - MinGb: minGbVal, - NodeType: nodeTypeVal, - StorageClasses: storageClassesVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewFlavorsValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) FlavorsValue { - object, diags := NewFlavorsValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewFlavorsValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t FlavorsType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewFlavorsValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewFlavorsValueUnknown(), nil - } - - if in.IsNull() { - return NewFlavorsValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewFlavorsValueMust(FlavorsValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t FlavorsType) ValueType(ctx context.Context) attr.Value { - return FlavorsValue{} -} - -var _ basetypes.ObjectValuable = FlavorsValue{} - -type FlavorsValue struct { - Cpu basetypes.Int64Value `tfsdk:"cpu"` - Description basetypes.StringValue `tfsdk:"description"` - Id basetypes.StringValue `tfsdk:"id"` - MaxGb basetypes.Int64Value `tfsdk:"max_gb"` - Memory basetypes.Int64Value `tfsdk:"memory"` - MinGb basetypes.Int64Value `tfsdk:"min_gb"` - NodeType basetypes.StringValue `tfsdk:"node_type"` - StorageClasses basetypes.ListValue `tfsdk:"storage_classes"` - state attr.ValueState -} - -func (v FlavorsValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 8) - - var val tftypes.Value - var err error - - attrTypes["cpu"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["description"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["max_gb"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["memory"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["min_gb"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["node_type"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["storage_classes"] = basetypes.ListType{ - ElemType: StorageClassesValue{}.Type(ctx), - }.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 8) - - val, err = v.Cpu.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["cpu"] = val - - val, err = v.Description.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["description"] = val - - val, err = v.Id.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["id"] = val - - val, err = v.MaxGb.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["max_gb"] = val - - val, err = v.Memory.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["memory"] = val - - val, err = v.MinGb.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["min_gb"] = val - - val, err = v.NodeType.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["node_type"] = val - - val, err = v.StorageClasses.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["storage_classes"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v FlavorsValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v FlavorsValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v FlavorsValue) String() string { - return "FlavorsValue" -} - -func (v FlavorsValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - storageClasses := types.ListValueMust( - StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - v.StorageClasses.Elements(), - ) - - if v.StorageClasses.IsNull() { - storageClasses = types.ListNull( - StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - ) - } - - if v.StorageClasses.IsUnknown() { - storageClasses = types.ListUnknown( - StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: StorageClassesValue{}.AttributeTypes(ctx), - }, - }, - ) - } - - attributeTypes := map[string]attr.Type{ - "cpu": basetypes.Int64Type{}, - "description": basetypes.StringType{}, - "id": basetypes.StringType{}, - "max_gb": basetypes.Int64Type{}, - "memory": basetypes.Int64Type{}, - "min_gb": basetypes.Int64Type{}, - "node_type": basetypes.StringType{}, - "storage_classes": basetypes.ListType{ - ElemType: StorageClassesValue{}.Type(ctx), - }, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "cpu": v.Cpu, - "description": v.Description, - "id": v.Id, - "max_gb": v.MaxGb, - "memory": v.Memory, - "min_gb": v.MinGb, - "node_type": v.NodeType, - "storage_classes": storageClasses, - }) - - return objVal, diags -} - -func (v FlavorsValue) Equal(o attr.Value) bool { - other, ok := o.(FlavorsValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Cpu.Equal(other.Cpu) { - return false - } - - if !v.Description.Equal(other.Description) { - return false - } - - if !v.Id.Equal(other.Id) { - return false - } - - if !v.MaxGb.Equal(other.MaxGb) { - return false - } - - if !v.Memory.Equal(other.Memory) { - return false - } - - if !v.MinGb.Equal(other.MinGb) { - return false - } - - if !v.NodeType.Equal(other.NodeType) { - return false - } - - if !v.StorageClasses.Equal(other.StorageClasses) { - return false - } - - return true -} - -func (v FlavorsValue) Type(ctx context.Context) attr.Type { - return FlavorsType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v FlavorsValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "cpu": basetypes.Int64Type{}, - "description": basetypes.StringType{}, - "id": basetypes.StringType{}, - "max_gb": basetypes.Int64Type{}, - "memory": basetypes.Int64Type{}, - "min_gb": basetypes.Int64Type{}, - "node_type": basetypes.StringType{}, - "storage_classes": basetypes.ListType{ - ElemType: StorageClassesValue{}.Type(ctx), - }, - } -} - -var _ basetypes.ObjectTypable = StorageClassesType{} - -type StorageClassesType struct { - basetypes.ObjectType -} - -func (t StorageClassesType) Equal(o attr.Type) bool { - other, ok := o.(StorageClassesType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t StorageClassesType) String() string { - return "StorageClassesType" -} - -func (t StorageClassesType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - classAttribute, ok := attributes["class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `class is missing from object`) - - return nil, diags - } - - classVal, ok := classAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`class expected to be basetypes.StringValue, was: %T`, classAttribute)) - } - - maxIoPerSecAttribute, ok := attributes["max_io_per_sec"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_io_per_sec is missing from object`) - - return nil, diags - } - - maxIoPerSecVal, ok := maxIoPerSecAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_io_per_sec expected to be basetypes.Int64Value, was: %T`, maxIoPerSecAttribute)) - } - - maxThroughInMbAttribute, ok := attributes["max_through_in_mb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_through_in_mb is missing from object`) - - return nil, diags - } - - maxThroughInMbVal, ok := maxThroughInMbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_through_in_mb expected to be basetypes.Int64Value, was: %T`, maxThroughInMbAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return StorageClassesValue{ - Class: classVal, - MaxIoPerSec: maxIoPerSecVal, - MaxThroughInMb: maxThroughInMbVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageClassesValueNull() StorageClassesValue { - return StorageClassesValue{ - state: attr.ValueStateNull, - } -} - -func NewStorageClassesValueUnknown() StorageClassesValue { - return StorageClassesValue{ - state: attr.ValueStateUnknown, - } -} - -func NewStorageClassesValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (StorageClassesValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing StorageClassesValue Attribute Value", - "While creating a StorageClassesValue value, a missing attribute value was detected. "+ - "A StorageClassesValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageClassesValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid StorageClassesValue Attribute Type", - "While creating a StorageClassesValue value, an invalid attribute value was detected. "+ - "A StorageClassesValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageClassesValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("StorageClassesValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra StorageClassesValue Attribute Value", - "While creating a StorageClassesValue value, an extra attribute value was detected. "+ - "A StorageClassesValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra StorageClassesValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewStorageClassesValueUnknown(), diags - } - - classAttribute, ok := attributes["class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `class is missing from object`) - - return NewStorageClassesValueUnknown(), diags - } - - classVal, ok := classAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`class expected to be basetypes.StringValue, was: %T`, classAttribute)) - } - - maxIoPerSecAttribute, ok := attributes["max_io_per_sec"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_io_per_sec is missing from object`) - - return NewStorageClassesValueUnknown(), diags - } - - maxIoPerSecVal, ok := maxIoPerSecAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_io_per_sec expected to be basetypes.Int64Value, was: %T`, maxIoPerSecAttribute)) - } - - maxThroughInMbAttribute, ok := attributes["max_through_in_mb"] - - if !ok { - diags.AddError( - "Attribute Missing", - `max_through_in_mb is missing from object`) - - return NewStorageClassesValueUnknown(), diags - } - - maxThroughInMbVal, ok := maxThroughInMbAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`max_through_in_mb expected to be basetypes.Int64Value, was: %T`, maxThroughInMbAttribute)) - } - - if diags.HasError() { - return NewStorageClassesValueUnknown(), diags - } - - return StorageClassesValue{ - Class: classVal, - MaxIoPerSec: maxIoPerSecVal, - MaxThroughInMb: maxThroughInMbVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageClassesValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) StorageClassesValue { - object, diags := NewStorageClassesValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewStorageClassesValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t StorageClassesType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewStorageClassesValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewStorageClassesValueUnknown(), nil - } - - if in.IsNull() { - return NewStorageClassesValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewStorageClassesValueMust(StorageClassesValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t StorageClassesType) ValueType(ctx context.Context) attr.Value { - return StorageClassesValue{} -} - -var _ basetypes.ObjectValuable = StorageClassesValue{} - -type StorageClassesValue struct { - Class basetypes.StringValue `tfsdk:"class"` - MaxIoPerSec basetypes.Int64Value `tfsdk:"max_io_per_sec"` - MaxThroughInMb basetypes.Int64Value `tfsdk:"max_through_in_mb"` - state attr.ValueState -} - -func (v StorageClassesValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 3) - - var val tftypes.Value - var err error - - attrTypes["class"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["max_io_per_sec"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["max_through_in_mb"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 3) - - val, err = v.Class.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["class"] = val - - val, err = v.MaxIoPerSec.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["max_io_per_sec"] = val - - val, err = v.MaxThroughInMb.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["max_through_in_mb"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v StorageClassesValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v StorageClassesValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v StorageClassesValue) String() string { - return "StorageClassesValue" -} - -func (v StorageClassesValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "class": basetypes.StringType{}, - "max_io_per_sec": basetypes.Int64Type{}, - "max_through_in_mb": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "class": v.Class, - "max_io_per_sec": v.MaxIoPerSec, - "max_through_in_mb": v.MaxThroughInMb, - }) - - return objVal, diags -} - -func (v StorageClassesValue) Equal(o attr.Value) bool { - other, ok := o.(StorageClassesValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Class.Equal(other.Class) { - return false - } - - if !v.MaxIoPerSec.Equal(other.MaxIoPerSec) { - return false - } - - if !v.MaxThroughInMb.Equal(other.MaxThroughInMb) { - return false - } - - return true -} - -func (v StorageClassesValue) Type(ctx context.Context) attr.Type { - return StorageClassesType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v StorageClassesValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "class": basetypes.StringType{}, - "max_io_per_sec": basetypes.Int64Type{}, - "max_through_in_mb": basetypes.Int64Type{}, - } -} - -var _ basetypes.ObjectTypable = PaginationType{} - -type PaginationType struct { - basetypes.ObjectType -} - -func (t PaginationType) Equal(o attr.Type) bool { - other, ok := o.(PaginationType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t PaginationType) String() string { - return "PaginationType" -} - -func (t PaginationType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return nil, diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return nil, diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return nil, diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return nil, diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueNull() PaginationValue { - return PaginationValue{ - state: attr.ValueStateNull, - } -} - -func NewPaginationValueUnknown() PaginationValue { - return PaginationValue{ - state: attr.ValueStateUnknown, - } -} - -func NewPaginationValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (PaginationValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing PaginationValue Attribute Value", - "While creating a PaginationValue value, a missing attribute value was detected. "+ - "A PaginationValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid PaginationValue Attribute Type", - "While creating a PaginationValue value, an invalid attribute value was detected. "+ - "A PaginationValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra PaginationValue Attribute Value", - "While creating a PaginationValue value, an extra attribute value was detected. "+ - "A PaginationValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra PaginationValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) PaginationValue { - object, diags := NewPaginationValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewPaginationValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t PaginationType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewPaginationValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewPaginationValueUnknown(), nil - } - - if in.IsNull() { - return NewPaginationValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewPaginationValueMust(PaginationValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t PaginationType) ValueType(ctx context.Context) attr.Value { - return PaginationValue{} -} - -var _ basetypes.ObjectValuable = PaginationValue{} - -type PaginationValue struct { - Page basetypes.Int64Value `tfsdk:"page"` - Size basetypes.Int64Value `tfsdk:"size"` - Sort basetypes.StringValue `tfsdk:"sort"` - TotalPages basetypes.Int64Value `tfsdk:"total_pages"` - TotalRows basetypes.Int64Value `tfsdk:"total_rows"` - state attr.ValueState -} - -func (v PaginationValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 5) - - var val tftypes.Value - var err error - - attrTypes["page"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["sort"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["total_pages"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["total_rows"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 5) - - val, err = v.Page.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["page"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - val, err = v.Sort.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["sort"] = val - - val, err = v.TotalPages.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_pages"] = val - - val, err = v.TotalRows.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_rows"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v PaginationValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v PaginationValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v PaginationValue) String() string { - return "PaginationValue" -} - -func (v PaginationValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "page": v.Page, - "size": v.Size, - "sort": v.Sort, - "total_pages": v.TotalPages, - "total_rows": v.TotalRows, - }) - - return objVal, diags -} - -func (v PaginationValue) Equal(o attr.Value) bool { - other, ok := o.(PaginationValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Page.Equal(other.Page) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - if !v.Sort.Equal(other.Sort) { - return false - } - - if !v.TotalPages.Equal(other.TotalPages) { - return false - } - - if !v.TotalRows.Equal(other.TotalRows) { - return false - } - - return true -} - -func (v PaginationValue) Type(ctx context.Context) attr.Type { - return PaginationType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v PaginationValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } -} diff --git a/stackit/internal/services/sqlserverflexbeta/instance/datasources_gen/instance_data_source_gen.go b/stackit/internal/services/sqlserverflexbeta/instance/datasources_gen/instance_data_source_gen.go deleted file mode 100644 index f3226581..00000000 --- a/stackit/internal/services/sqlserverflexbeta/instance/datasources_gen/instance_data_source_gen.go +++ /dev/null @@ -1,1579 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package sqlserverflexbeta - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -func InstanceDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "backup_schedule": schema.StringAttribute{ - Computed: true, - Description: "The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.", - MarkdownDescription: "The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.", - }, - "edition": schema.StringAttribute{ - Computed: true, - Description: "Edition of the MSSQL server instance", - MarkdownDescription: "Edition of the MSSQL server instance", - }, - "encryption": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "kek_key_id": schema.StringAttribute{ - Computed: true, - Description: "The key identifier", - MarkdownDescription: "The key identifier", - }, - "kek_key_ring_id": schema.StringAttribute{ - Computed: true, - Description: "The keyring identifier", - MarkdownDescription: "The keyring identifier", - }, - "kek_key_version": schema.StringAttribute{ - Computed: true, - Description: "The key version", - MarkdownDescription: "The key version", - }, - "service_account": schema.StringAttribute{ - Computed: true, - }, - }, - CustomType: EncryptionType{ - ObjectType: types.ObjectType{ - AttrTypes: EncryptionValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - Description: "this defines which key to use for storage encryption", - MarkdownDescription: "this defines which key to use for storage encryption", - }, - "flavor_id": schema.StringAttribute{ - Computed: true, - Description: "The id of the instance flavor.", - MarkdownDescription: "The id of the instance flavor.", - }, - "tf_original_api_id": schema.StringAttribute{ - Computed: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "instance_id": schema.StringAttribute{ - Required: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "is_deletable": schema.BoolAttribute{ - Computed: true, - Description: "Whether the instance can be deleted or not.", - MarkdownDescription: "Whether the instance can be deleted or not.", - }, - "name": schema.StringAttribute{ - Computed: true, - Description: "The name of the instance.", - MarkdownDescription: "The name of the instance.", - }, - "network": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "access_scope": schema.StringAttribute{ - Computed: true, - Description: "The network access scope of the instance\n\n⚠️ **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.\n", - MarkdownDescription: "The network access scope of the instance\n\n⚠️ **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.\n", - }, - "acl": schema.ListAttribute{ - ElementType: types.StringType, - Computed: true, - Description: "List of IPV4 cidr.", - MarkdownDescription: "List of IPV4 cidr.", - }, - "instance_address": schema.StringAttribute{ - Computed: true, - }, - "router_address": schema.StringAttribute{ - Computed: true, - }, - }, - CustomType: NetworkType{ - ObjectType: types.ObjectType{ - AttrTypes: NetworkValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - Description: "The access configuration of the instance", - MarkdownDescription: "The access configuration of the instance", - }, - "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", - ), - }, - }, - "replicas": schema.Int64Attribute{ - Computed: true, - Description: "How many replicas the instance should have.", - MarkdownDescription: "How many replicas the instance should have.", - }, - "retention_days": schema.Int64Attribute{ - Computed: true, - Description: "The days for how long the backup files should be stored before cleaned up. 30 to 365", - MarkdownDescription: "The days for how long the backup files should be stored before cleaned up. 30 to 365", - }, - "status": schema.StringAttribute{ - Computed: true, - }, - "storage": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "class": schema.StringAttribute{ - Computed: true, - Description: "The storage class for the storage.", - MarkdownDescription: "The storage class for the storage.", - }, - "size": schema.Int64Attribute{ - Computed: true, - Description: "The storage size in Gigabytes.", - MarkdownDescription: "The storage size in Gigabytes.", - }, - }, - CustomType: StorageType{ - ObjectType: types.ObjectType{ - AttrTypes: StorageValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - Description: "The object containing information about the storage size and class.", - MarkdownDescription: "The object containing information about the storage size and class.", - }, - "version": schema.StringAttribute{ - Computed: true, - Description: "The sqlserver version used for the instance.", - MarkdownDescription: "The sqlserver version used for the instance.", - }, - }, - } -} - -type InstanceModel struct { - BackupSchedule types.String `tfsdk:"backup_schedule"` - Edition types.String `tfsdk:"edition"` - Encryption EncryptionValue `tfsdk:"encryption"` - FlavorId types.String `tfsdk:"flavor_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"` - Network NetworkValue `tfsdk:"network"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Replicas types.Int64 `tfsdk:"replicas"` - RetentionDays types.Int64 `tfsdk:"retention_days"` - Status types.String `tfsdk:"status"` - Storage StorageValue `tfsdk:"storage"` - Version types.String `tfsdk:"version"` -} - -var _ basetypes.ObjectTypable = EncryptionType{} - -type EncryptionType struct { - basetypes.ObjectType -} - -func (t EncryptionType) Equal(o attr.Type) bool { - other, ok := o.(EncryptionType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t EncryptionType) String() string { - return "EncryptionType" -} - -func (t EncryptionType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - kekKeyIdAttribute, ok := attributes["kek_key_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_id is missing from object`) - - return nil, diags - } - - kekKeyIdVal, ok := kekKeyIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_id expected to be basetypes.StringValue, was: %T`, kekKeyIdAttribute)) - } - - kekKeyRingIdAttribute, ok := attributes["kek_key_ring_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_ring_id is missing from object`) - - return nil, diags - } - - kekKeyRingIdVal, ok := kekKeyRingIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_ring_id expected to be basetypes.StringValue, was: %T`, kekKeyRingIdAttribute)) - } - - kekKeyVersionAttribute, ok := attributes["kek_key_version"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_version is missing from object`) - - return nil, diags - } - - kekKeyVersionVal, ok := kekKeyVersionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_version expected to be basetypes.StringValue, was: %T`, kekKeyVersionAttribute)) - } - - serviceAccountAttribute, ok := attributes["service_account"] - - if !ok { - diags.AddError( - "Attribute Missing", - `service_account is missing from object`) - - return nil, diags - } - - serviceAccountVal, ok := serviceAccountAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`service_account expected to be basetypes.StringValue, was: %T`, serviceAccountAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return EncryptionValue{ - KekKeyId: kekKeyIdVal, - KekKeyRingId: kekKeyRingIdVal, - KekKeyVersion: kekKeyVersionVal, - ServiceAccount: serviceAccountVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewEncryptionValueNull() EncryptionValue { - return EncryptionValue{ - state: attr.ValueStateNull, - } -} - -func NewEncryptionValueUnknown() EncryptionValue { - return EncryptionValue{ - state: attr.ValueStateUnknown, - } -} - -func NewEncryptionValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (EncryptionValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing EncryptionValue Attribute Value", - "While creating a EncryptionValue value, a missing attribute value was detected. "+ - "A EncryptionValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("EncryptionValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid EncryptionValue Attribute Type", - "While creating a EncryptionValue value, an invalid attribute value was detected. "+ - "A EncryptionValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("EncryptionValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("EncryptionValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra EncryptionValue Attribute Value", - "While creating a EncryptionValue value, an extra attribute value was detected. "+ - "A EncryptionValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra EncryptionValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewEncryptionValueUnknown(), diags - } - - kekKeyIdAttribute, ok := attributes["kek_key_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_id is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - kekKeyIdVal, ok := kekKeyIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_id expected to be basetypes.StringValue, was: %T`, kekKeyIdAttribute)) - } - - kekKeyRingIdAttribute, ok := attributes["kek_key_ring_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_ring_id is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - kekKeyRingIdVal, ok := kekKeyRingIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_ring_id expected to be basetypes.StringValue, was: %T`, kekKeyRingIdAttribute)) - } - - kekKeyVersionAttribute, ok := attributes["kek_key_version"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_version is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - kekKeyVersionVal, ok := kekKeyVersionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_version expected to be basetypes.StringValue, was: %T`, kekKeyVersionAttribute)) - } - - serviceAccountAttribute, ok := attributes["service_account"] - - if !ok { - diags.AddError( - "Attribute Missing", - `service_account is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - serviceAccountVal, ok := serviceAccountAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`service_account expected to be basetypes.StringValue, was: %T`, serviceAccountAttribute)) - } - - if diags.HasError() { - return NewEncryptionValueUnknown(), diags - } - - return EncryptionValue{ - KekKeyId: kekKeyIdVal, - KekKeyRingId: kekKeyRingIdVal, - KekKeyVersion: kekKeyVersionVal, - ServiceAccount: serviceAccountVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewEncryptionValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) EncryptionValue { - object, diags := NewEncryptionValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewEncryptionValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t EncryptionType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewEncryptionValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewEncryptionValueUnknown(), nil - } - - if in.IsNull() { - return NewEncryptionValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewEncryptionValueMust(EncryptionValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t EncryptionType) ValueType(ctx context.Context) attr.Value { - return EncryptionValue{} -} - -var _ basetypes.ObjectValuable = EncryptionValue{} - -type EncryptionValue struct { - KekKeyId basetypes.StringValue `tfsdk:"kek_key_id"` - KekKeyRingId basetypes.StringValue `tfsdk:"kek_key_ring_id"` - KekKeyVersion basetypes.StringValue `tfsdk:"kek_key_version"` - ServiceAccount basetypes.StringValue `tfsdk:"service_account"` - state attr.ValueState -} - -func (v EncryptionValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 4) - - var val tftypes.Value - var err error - - attrTypes["kek_key_id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["kek_key_ring_id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["kek_key_version"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["service_account"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 4) - - val, err = v.KekKeyId.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["kek_key_id"] = val - - val, err = v.KekKeyRingId.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["kek_key_ring_id"] = val - - val, err = v.KekKeyVersion.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["kek_key_version"] = val - - val, err = v.ServiceAccount.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["service_account"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v EncryptionValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v EncryptionValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v EncryptionValue) String() string { - return "EncryptionValue" -} - -func (v EncryptionValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "kek_key_id": basetypes.StringType{}, - "kek_key_ring_id": basetypes.StringType{}, - "kek_key_version": basetypes.StringType{}, - "service_account": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "kek_key_id": v.KekKeyId, - "kek_key_ring_id": v.KekKeyRingId, - "kek_key_version": v.KekKeyVersion, - "service_account": v.ServiceAccount, - }) - - return objVal, diags -} - -func (v EncryptionValue) Equal(o attr.Value) bool { - other, ok := o.(EncryptionValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.KekKeyId.Equal(other.KekKeyId) { - return false - } - - if !v.KekKeyRingId.Equal(other.KekKeyRingId) { - return false - } - - if !v.KekKeyVersion.Equal(other.KekKeyVersion) { - return false - } - - if !v.ServiceAccount.Equal(other.ServiceAccount) { - return false - } - - return true -} - -func (v EncryptionValue) Type(ctx context.Context) attr.Type { - return EncryptionType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v EncryptionValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "kek_key_id": basetypes.StringType{}, - "kek_key_ring_id": basetypes.StringType{}, - "kek_key_version": basetypes.StringType{}, - "service_account": basetypes.StringType{}, - } -} - -var _ basetypes.ObjectTypable = NetworkType{} - -type NetworkType struct { - basetypes.ObjectType -} - -func (t NetworkType) Equal(o attr.Type) bool { - other, ok := o.(NetworkType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t NetworkType) String() string { - return "NetworkType" -} - -func (t NetworkType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - accessScopeAttribute, ok := attributes["access_scope"] - - if !ok { - diags.AddError( - "Attribute Missing", - `access_scope is missing from object`) - - return nil, diags - } - - accessScopeVal, ok := accessScopeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`access_scope expected to be basetypes.StringValue, was: %T`, accessScopeAttribute)) - } - - aclAttribute, ok := attributes["acl"] - - if !ok { - diags.AddError( - "Attribute Missing", - `acl is missing from object`) - - return nil, diags - } - - aclVal, ok := aclAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`acl expected to be basetypes.ListValue, was: %T`, aclAttribute)) - } - - instanceAddressAttribute, ok := attributes["instance_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `instance_address is missing from object`) - - return nil, diags - } - - instanceAddressVal, ok := instanceAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`instance_address expected to be basetypes.StringValue, was: %T`, instanceAddressAttribute)) - } - - routerAddressAttribute, ok := attributes["router_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `router_address is missing from object`) - - return nil, diags - } - - routerAddressVal, ok := routerAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`router_address expected to be basetypes.StringValue, was: %T`, routerAddressAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return NetworkValue{ - AccessScope: accessScopeVal, - Acl: aclVal, - InstanceAddress: instanceAddressVal, - RouterAddress: routerAddressVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewNetworkValueNull() NetworkValue { - return NetworkValue{ - state: attr.ValueStateNull, - } -} - -func NewNetworkValueUnknown() NetworkValue { - return NetworkValue{ - state: attr.ValueStateUnknown, - } -} - -func NewNetworkValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (NetworkValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing NetworkValue Attribute Value", - "While creating a NetworkValue value, a missing attribute value was detected. "+ - "A NetworkValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("NetworkValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid NetworkValue Attribute Type", - "While creating a NetworkValue value, an invalid attribute value was detected. "+ - "A NetworkValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("NetworkValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("NetworkValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra NetworkValue Attribute Value", - "While creating a NetworkValue value, an extra attribute value was detected. "+ - "A NetworkValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra NetworkValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewNetworkValueUnknown(), diags - } - - accessScopeAttribute, ok := attributes["access_scope"] - - if !ok { - diags.AddError( - "Attribute Missing", - `access_scope is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - accessScopeVal, ok := accessScopeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`access_scope expected to be basetypes.StringValue, was: %T`, accessScopeAttribute)) - } - - aclAttribute, ok := attributes["acl"] - - if !ok { - diags.AddError( - "Attribute Missing", - `acl is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - aclVal, ok := aclAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`acl expected to be basetypes.ListValue, was: %T`, aclAttribute)) - } - - instanceAddressAttribute, ok := attributes["instance_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `instance_address is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - instanceAddressVal, ok := instanceAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`instance_address expected to be basetypes.StringValue, was: %T`, instanceAddressAttribute)) - } - - routerAddressAttribute, ok := attributes["router_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `router_address is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - routerAddressVal, ok := routerAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`router_address expected to be basetypes.StringValue, was: %T`, routerAddressAttribute)) - } - - if diags.HasError() { - return NewNetworkValueUnknown(), diags - } - - return NetworkValue{ - AccessScope: accessScopeVal, - Acl: aclVal, - InstanceAddress: instanceAddressVal, - RouterAddress: routerAddressVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewNetworkValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) NetworkValue { - object, diags := NewNetworkValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewNetworkValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t NetworkType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewNetworkValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewNetworkValueUnknown(), nil - } - - if in.IsNull() { - return NewNetworkValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewNetworkValueMust(NetworkValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t NetworkType) ValueType(ctx context.Context) attr.Value { - return NetworkValue{} -} - -var _ basetypes.ObjectValuable = NetworkValue{} - -type NetworkValue struct { - AccessScope basetypes.StringValue `tfsdk:"access_scope"` - Acl basetypes.ListValue `tfsdk:"acl"` - InstanceAddress basetypes.StringValue `tfsdk:"instance_address"` - RouterAddress basetypes.StringValue `tfsdk:"router_address"` - state attr.ValueState -} - -func (v NetworkValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 4) - - var val tftypes.Value - var err error - - attrTypes["access_scope"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["acl"] = basetypes.ListType{ - ElemType: types.StringType, - }.TerraformType(ctx) - attrTypes["instance_address"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["router_address"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 4) - - val, err = v.AccessScope.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["access_scope"] = val - - val, err = v.Acl.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["acl"] = val - - val, err = v.InstanceAddress.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["instance_address"] = val - - val, err = v.RouterAddress.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["router_address"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v NetworkValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v NetworkValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v NetworkValue) String() string { - return "NetworkValue" -} - -func (v NetworkValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - var aclVal basetypes.ListValue - switch { - case v.Acl.IsUnknown(): - aclVal = types.ListUnknown(types.StringType) - case v.Acl.IsNull(): - aclVal = types.ListNull(types.StringType) - default: - var d diag.Diagnostics - aclVal, d = types.ListValue(types.StringType, v.Acl.Elements()) - diags.Append(d...) - } - - if diags.HasError() { - return types.ObjectUnknown(map[string]attr.Type{ - "access_scope": basetypes.StringType{}, - "acl": basetypes.ListType{ - ElemType: types.StringType, - }, - "instance_address": basetypes.StringType{}, - "router_address": basetypes.StringType{}, - }), diags - } - - attributeTypes := map[string]attr.Type{ - "access_scope": basetypes.StringType{}, - "acl": basetypes.ListType{ - ElemType: types.StringType, - }, - "instance_address": basetypes.StringType{}, - "router_address": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "access_scope": v.AccessScope, - "acl": aclVal, - "instance_address": v.InstanceAddress, - "router_address": v.RouterAddress, - }) - - return objVal, diags -} - -func (v NetworkValue) Equal(o attr.Value) bool { - other, ok := o.(NetworkValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.AccessScope.Equal(other.AccessScope) { - return false - } - - if !v.Acl.Equal(other.Acl) { - return false - } - - if !v.InstanceAddress.Equal(other.InstanceAddress) { - return false - } - - if !v.RouterAddress.Equal(other.RouterAddress) { - return false - } - - return true -} - -func (v NetworkValue) Type(ctx context.Context) attr.Type { - return NetworkType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v NetworkValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "access_scope": basetypes.StringType{}, - "acl": basetypes.ListType{ - ElemType: types.StringType, - }, - "instance_address": basetypes.StringType{}, - "router_address": basetypes.StringType{}, - } -} - -var _ basetypes.ObjectTypable = StorageType{} - -type StorageType struct { - basetypes.ObjectType -} - -func (t StorageType) Equal(o attr.Type) bool { - other, ok := o.(StorageType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t StorageType) String() string { - return "StorageType" -} - -func (t StorageType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - classAttribute, ok := attributes["class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `class is missing from object`) - - return nil, diags - } - - classVal, ok := classAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`class expected to be basetypes.StringValue, was: %T`, classAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return StorageValue{ - Class: classVal, - Size: sizeVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageValueNull() StorageValue { - return StorageValue{ - state: attr.ValueStateNull, - } -} - -func NewStorageValueUnknown() StorageValue { - return StorageValue{ - state: attr.ValueStateUnknown, - } -} - -func NewStorageValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (StorageValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing StorageValue Attribute Value", - "While creating a StorageValue value, a missing attribute value was detected. "+ - "A StorageValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid StorageValue Attribute Type", - "While creating a StorageValue value, an invalid attribute value was detected. "+ - "A StorageValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("StorageValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra StorageValue Attribute Value", - "While creating a StorageValue value, an extra attribute value was detected. "+ - "A StorageValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra StorageValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewStorageValueUnknown(), diags - } - - classAttribute, ok := attributes["class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `class is missing from object`) - - return NewStorageValueUnknown(), diags - } - - classVal, ok := classAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`class expected to be basetypes.StringValue, was: %T`, classAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewStorageValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - if diags.HasError() { - return NewStorageValueUnknown(), diags - } - - return StorageValue{ - Class: classVal, - Size: sizeVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) StorageValue { - object, diags := NewStorageValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewStorageValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t StorageType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewStorageValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewStorageValueUnknown(), nil - } - - if in.IsNull() { - return NewStorageValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewStorageValueMust(StorageValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t StorageType) ValueType(ctx context.Context) attr.Value { - return StorageValue{} -} - -var _ basetypes.ObjectValuable = StorageValue{} - -type StorageValue struct { - Class basetypes.StringValue `tfsdk:"class"` - Size basetypes.Int64Value `tfsdk:"size"` - state attr.ValueState -} - -func (v StorageValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 2) - - var val tftypes.Value - var err error - - attrTypes["class"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 2) - - val, err = v.Class.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["class"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v StorageValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v StorageValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v StorageValue) String() string { - return "StorageValue" -} - -func (v StorageValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "class": basetypes.StringType{}, - "size": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "class": v.Class, - "size": v.Size, - }) - - return objVal, diags -} - -func (v StorageValue) Equal(o attr.Value) bool { - other, ok := o.(StorageValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Class.Equal(other.Class) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - return true -} - -func (v StorageValue) Type(ctx context.Context) attr.Type { - return StorageType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v StorageValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "class": basetypes.StringType{}, - "size": basetypes.Int64Type{}, - } -} diff --git a/stackit/internal/services/sqlserverflexbeta/instance/datasources_gen/instances_data_source_gen.go b/stackit/internal/services/sqlserverflexbeta/instance/datasources_gen/instances_data_source_gen.go deleted file mode 100644 index 04fff1f6..00000000 --- a/stackit/internal/services/sqlserverflexbeta/instance/datasources_gen/instances_data_source_gen.go +++ /dev/null @@ -1,1172 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package sqlserverflexbeta - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -func InstancesDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "instances": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "id": schema.StringAttribute{ - Computed: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "is_deletable": schema.BoolAttribute{ - Computed: true, - Description: "Whether the instance can be deleted or not.", - MarkdownDescription: "Whether the instance can be deleted or not.", - }, - "name": schema.StringAttribute{ - Computed: true, - Description: "The name of the instance.", - MarkdownDescription: "The name of the instance.", - }, - "status": schema.StringAttribute{ - Computed: true, - }, - }, - CustomType: InstancesType{ - ObjectType: types.ObjectType{ - AttrTypes: InstancesValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "List of owned instances and their current status.", - MarkdownDescription: "List of owned instances and their current status.", - }, - "page": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of the page of items list to be returned.", - MarkdownDescription: "Number of the page of items list to be returned.", - }, - "pagination": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "page": schema.Int64Attribute{ - Computed: true, - }, - "size": schema.Int64Attribute{ - Computed: true, - }, - "sort": schema.StringAttribute{ - Computed: true, - }, - "total_pages": schema.Int64Attribute{ - Computed: true, - }, - "total_rows": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: PaginationType{ - ObjectType: types.ObjectType{ - AttrTypes: PaginationValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - }, - "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", - ), - }, - }, - "size": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of items to be returned on each page.", - MarkdownDescription: "Number of items to be returned on each page.", - }, - "sort": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "Sorting of the items to be returned on each page.", - MarkdownDescription: "Sorting of the items to be returned on each page.", - Validators: []validator.String{ - stringvalidator.OneOf( - "index.desc", - "index.asc", - "id.desc", - "id.asc", - "is_deletable.desc", - "is_deletable.asc", - "name.asc", - "name.desc", - "status.asc", - "status.desc", - ), - }, - }, - }, - } -} - -type InstancesModel struct { - Instances types.List `tfsdk:"instances"` - Page types.Int64 `tfsdk:"page"` - Pagination PaginationValue `tfsdk:"pagination"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Size types.Int64 `tfsdk:"size"` - Sort types.String `tfsdk:"sort"` -} - -var _ basetypes.ObjectTypable = InstancesType{} - -type InstancesType struct { - basetypes.ObjectType -} - -func (t InstancesType) Equal(o attr.Type) bool { - other, ok := o.(InstancesType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t InstancesType) String() string { - return "InstancesType" -} - -func (t InstancesType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return nil, diags - } - - idVal, ok := idAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.StringValue, was: %T`, idAttribute)) - } - - isDeletableAttribute, ok := attributes["is_deletable"] - - if !ok { - diags.AddError( - "Attribute Missing", - `is_deletable is missing from object`) - - return nil, diags - } - - isDeletableVal, ok := isDeletableAttribute.(basetypes.BoolValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`is_deletable expected to be basetypes.BoolValue, was: %T`, isDeletableAttribute)) - } - - nameAttribute, ok := attributes["name"] - - if !ok { - diags.AddError( - "Attribute Missing", - `name is missing from object`) - - return nil, diags - } - - nameVal, ok := nameAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`name expected to be basetypes.StringValue, was: %T`, nameAttribute)) - } - - statusAttribute, ok := attributes["status"] - - if !ok { - diags.AddError( - "Attribute Missing", - `status is missing from object`) - - return nil, diags - } - - statusVal, ok := statusAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`status expected to be basetypes.StringValue, was: %T`, statusAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return InstancesValue{ - Id: idVal, - IsDeletable: isDeletableVal, - Name: nameVal, - Status: statusVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewInstancesValueNull() InstancesValue { - return InstancesValue{ - state: attr.ValueStateNull, - } -} - -func NewInstancesValueUnknown() InstancesValue { - return InstancesValue{ - state: attr.ValueStateUnknown, - } -} - -func NewInstancesValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (InstancesValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing InstancesValue Attribute Value", - "While creating a InstancesValue value, a missing attribute value was detected. "+ - "A InstancesValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("InstancesValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid InstancesValue Attribute Type", - "While creating a InstancesValue value, an invalid attribute value was detected. "+ - "A InstancesValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("InstancesValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("InstancesValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra InstancesValue Attribute Value", - "While creating a InstancesValue value, an extra attribute value was detected. "+ - "A InstancesValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra InstancesValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewInstancesValueUnknown(), diags - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return NewInstancesValueUnknown(), diags - } - - idVal, ok := idAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.StringValue, was: %T`, idAttribute)) - } - - isDeletableAttribute, ok := attributes["is_deletable"] - - if !ok { - diags.AddError( - "Attribute Missing", - `is_deletable is missing from object`) - - return NewInstancesValueUnknown(), diags - } - - isDeletableVal, ok := isDeletableAttribute.(basetypes.BoolValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`is_deletable expected to be basetypes.BoolValue, was: %T`, isDeletableAttribute)) - } - - nameAttribute, ok := attributes["name"] - - if !ok { - diags.AddError( - "Attribute Missing", - `name is missing from object`) - - return NewInstancesValueUnknown(), diags - } - - nameVal, ok := nameAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`name expected to be basetypes.StringValue, was: %T`, nameAttribute)) - } - - statusAttribute, ok := attributes["status"] - - if !ok { - diags.AddError( - "Attribute Missing", - `status is missing from object`) - - return NewInstancesValueUnknown(), diags - } - - statusVal, ok := statusAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`status expected to be basetypes.StringValue, was: %T`, statusAttribute)) - } - - if diags.HasError() { - return NewInstancesValueUnknown(), diags - } - - return InstancesValue{ - Id: idVal, - IsDeletable: isDeletableVal, - Name: nameVal, - Status: statusVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewInstancesValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) InstancesValue { - object, diags := NewInstancesValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewInstancesValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t InstancesType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewInstancesValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewInstancesValueUnknown(), nil - } - - if in.IsNull() { - return NewInstancesValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewInstancesValueMust(InstancesValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t InstancesType) ValueType(ctx context.Context) attr.Value { - return InstancesValue{} -} - -var _ basetypes.ObjectValuable = InstancesValue{} - -type InstancesValue struct { - Id basetypes.StringValue `tfsdk:"id"` - IsDeletable basetypes.BoolValue `tfsdk:"is_deletable"` - Name basetypes.StringValue `tfsdk:"name"` - Status basetypes.StringValue `tfsdk:"status"` - state attr.ValueState -} - -func (v InstancesValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 4) - - var val tftypes.Value - var err error - - attrTypes["id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["is_deletable"] = basetypes.BoolType{}.TerraformType(ctx) - attrTypes["name"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["status"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 4) - - val, err = v.Id.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["id"] = val - - val, err = v.IsDeletable.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["is_deletable"] = val - - val, err = v.Name.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["name"] = val - - val, err = v.Status.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["status"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v InstancesValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v InstancesValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v InstancesValue) String() string { - return "InstancesValue" -} - -func (v InstancesValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "id": basetypes.StringType{}, - "is_deletable": basetypes.BoolType{}, - "name": basetypes.StringType{}, - "status": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "id": v.Id, - "is_deletable": v.IsDeletable, - "name": v.Name, - "status": v.Status, - }) - - return objVal, diags -} - -func (v InstancesValue) Equal(o attr.Value) bool { - other, ok := o.(InstancesValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Id.Equal(other.Id) { - return false - } - - if !v.IsDeletable.Equal(other.IsDeletable) { - return false - } - - if !v.Name.Equal(other.Name) { - return false - } - - if !v.Status.Equal(other.Status) { - return false - } - - return true -} - -func (v InstancesValue) Type(ctx context.Context) attr.Type { - return InstancesType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v InstancesValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "id": basetypes.StringType{}, - "is_deletable": basetypes.BoolType{}, - "name": basetypes.StringType{}, - "status": basetypes.StringType{}, - } -} - -var _ basetypes.ObjectTypable = PaginationType{} - -type PaginationType struct { - basetypes.ObjectType -} - -func (t PaginationType) Equal(o attr.Type) bool { - other, ok := o.(PaginationType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t PaginationType) String() string { - return "PaginationType" -} - -func (t PaginationType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return nil, diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return nil, diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return nil, diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return nil, diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueNull() PaginationValue { - return PaginationValue{ - state: attr.ValueStateNull, - } -} - -func NewPaginationValueUnknown() PaginationValue { - return PaginationValue{ - state: attr.ValueStateUnknown, - } -} - -func NewPaginationValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (PaginationValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing PaginationValue Attribute Value", - "While creating a PaginationValue value, a missing attribute value was detected. "+ - "A PaginationValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid PaginationValue Attribute Type", - "While creating a PaginationValue value, an invalid attribute value was detected. "+ - "A PaginationValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra PaginationValue Attribute Value", - "While creating a PaginationValue value, an extra attribute value was detected. "+ - "A PaginationValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra PaginationValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) PaginationValue { - object, diags := NewPaginationValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewPaginationValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t PaginationType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewPaginationValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewPaginationValueUnknown(), nil - } - - if in.IsNull() { - return NewPaginationValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewPaginationValueMust(PaginationValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t PaginationType) ValueType(ctx context.Context) attr.Value { - return PaginationValue{} -} - -var _ basetypes.ObjectValuable = PaginationValue{} - -type PaginationValue struct { - Page basetypes.Int64Value `tfsdk:"page"` - Size basetypes.Int64Value `tfsdk:"size"` - Sort basetypes.StringValue `tfsdk:"sort"` - TotalPages basetypes.Int64Value `tfsdk:"total_pages"` - TotalRows basetypes.Int64Value `tfsdk:"total_rows"` - state attr.ValueState -} - -func (v PaginationValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 5) - - var val tftypes.Value - var err error - - attrTypes["page"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["sort"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["total_pages"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["total_rows"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 5) - - val, err = v.Page.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["page"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - val, err = v.Sort.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["sort"] = val - - val, err = v.TotalPages.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_pages"] = val - - val, err = v.TotalRows.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_rows"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v PaginationValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v PaginationValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v PaginationValue) String() string { - return "PaginationValue" -} - -func (v PaginationValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "page": v.Page, - "size": v.Size, - "sort": v.Sort, - "total_pages": v.TotalPages, - "total_rows": v.TotalRows, - }) - - return objVal, diags -} - -func (v PaginationValue) Equal(o attr.Value) bool { - other, ok := o.(PaginationValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Page.Equal(other.Page) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - if !v.Sort.Equal(other.Sort) { - return false - } - - if !v.TotalPages.Equal(other.TotalPages) { - return false - } - - if !v.TotalRows.Equal(other.TotalRows) { - return false - } - - return true -} - -func (v PaginationValue) Type(ctx context.Context) attr.Type { - return PaginationType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v PaginationValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } -} diff --git a/stackit/internal/services/sqlserverflexbeta/instance/resources_gen/instance_resource_gen.go b/stackit/internal/services/sqlserverflexbeta/instance/resources_gen/instance_resource_gen.go deleted file mode 100644 index f8865ae5..00000000 --- a/stackit/internal/services/sqlserverflexbeta/instance/resources_gen/instance_resource_gen.go +++ /dev/null @@ -1,1597 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package sqlserverflexbeta - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/resource/schema" -) - -func InstanceResourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "backup_schedule": schema.StringAttribute{ - Required: true, - Description: "The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.", - MarkdownDescription: "The schedule for on what time and how often the database backup will be created. The schedule is written as a cron schedule.", - }, - "edition": schema.StringAttribute{ - Computed: true, - Description: "Edition of the MSSQL server instance", - MarkdownDescription: "Edition of the MSSQL server instance", - }, - "encryption": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "kek_key_id": schema.StringAttribute{ - Required: true, - Description: "The key identifier", - MarkdownDescription: "The key identifier", - }, - "kek_key_ring_id": schema.StringAttribute{ - Required: true, - Description: "The keyring identifier", - MarkdownDescription: "The keyring identifier", - }, - "kek_key_version": schema.StringAttribute{ - Required: true, - Description: "The key version", - MarkdownDescription: "The key version", - }, - "service_account": schema.StringAttribute{ - Required: true, - }, - }, - CustomType: EncryptionType{ - ObjectType: types.ObjectType{ - AttrTypes: EncryptionValue{}.AttributeTypes(ctx), - }, - }, - Optional: true, - Computed: true, - Description: "this defines which key to use for storage encryption", - MarkdownDescription: "this defines which key to use for storage encryption", - }, - "flavor_id": schema.StringAttribute{ - Required: true, - Description: "The id of the instance flavor.", - MarkdownDescription: "The id of the instance flavor.", - }, - "id": schema.StringAttribute{ - Computed: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "instance_id": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "is_deletable": schema.BoolAttribute{ - Computed: true, - Description: "Whether the instance can be deleted or not.", - MarkdownDescription: "Whether the instance can be deleted or not.", - }, - "name": schema.StringAttribute{ - Required: true, - Description: "The name of the instance.", - MarkdownDescription: "The name of the instance.", - }, - "network": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "access_scope": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "The network access scope of the instance\n\n⚠️ **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.\n", - MarkdownDescription: "The network access scope of the instance\n\n⚠️ **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.\n", - Validators: []validator.String{ - stringvalidator.OneOf( - "PUBLIC", - "SNA", - ), - }, - Default: stringdefault.StaticString("PUBLIC"), - }, - "acl": schema.ListAttribute{ - ElementType: types.StringType, - Required: true, - Description: "List of IPV4 cidr.", - MarkdownDescription: "List of IPV4 cidr.", - }, - "instance_address": schema.StringAttribute{ - Computed: true, - }, - "router_address": schema.StringAttribute{ - Computed: true, - }, - }, - CustomType: NetworkType{ - ObjectType: types.ObjectType{ - AttrTypes: NetworkValue{}.AttributeTypes(ctx), - }, - }, - Required: true, - Description: "the network configuration of the instance.", - MarkdownDescription: "the network configuration of the instance.", - }, - "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", - ), - }, - }, - "replicas": schema.Int64Attribute{ - Computed: true, - Description: "How many replicas the instance should have.", - MarkdownDescription: "How many replicas the instance should have.", - }, - "retention_days": schema.Int64Attribute{ - Required: true, - Description: "The days for how long the backup files should be stored before cleaned up. 30 to 365", - MarkdownDescription: "The days for how long the backup files should be stored before cleaned up. 30 to 365", - }, - "status": schema.StringAttribute{ - Computed: true, - }, - "storage": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "class": schema.StringAttribute{ - Required: true, - Description: "The storage class for the storage.", - MarkdownDescription: "The storage class for the storage.", - }, - "size": schema.Int64Attribute{ - Required: true, - Description: "The storage size in Gigabytes.", - MarkdownDescription: "The storage size in Gigabytes.", - }, - }, - CustomType: StorageType{ - ObjectType: types.ObjectType{ - AttrTypes: StorageValue{}.AttributeTypes(ctx), - }, - }, - Required: true, - Description: "The object containing information about the storage size and class.", - MarkdownDescription: "The object containing information about the storage size and class.", - }, - "version": schema.StringAttribute{ - Required: true, - Description: "The sqlserver version used for the instance.", - MarkdownDescription: "The sqlserver version used for the instance.", - Validators: []validator.String{ - stringvalidator.OneOf( - "2022", - ), - }, - }, - }, - } -} - -type InstanceModel struct { - BackupSchedule types.String `tfsdk:"backup_schedule"` - Edition types.String `tfsdk:"edition"` - Encryption EncryptionValue `tfsdk:"encryption"` - FlavorId types.String `tfsdk:"flavor_id"` - Id types.String `tfsdk:"id"` - InstanceId types.String `tfsdk:"instance_id"` - IsDeletable types.Bool `tfsdk:"is_deletable"` - Name types.String `tfsdk:"name"` - Network NetworkValue `tfsdk:"network"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Replicas types.Int64 `tfsdk:"replicas"` - RetentionDays types.Int64 `tfsdk:"retention_days"` - Status types.String `tfsdk:"status"` - Storage StorageValue `tfsdk:"storage"` - Version types.String `tfsdk:"version"` -} - -var _ basetypes.ObjectTypable = EncryptionType{} - -type EncryptionType struct { - basetypes.ObjectType -} - -func (t EncryptionType) Equal(o attr.Type) bool { - other, ok := o.(EncryptionType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t EncryptionType) String() string { - return "EncryptionType" -} - -func (t EncryptionType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - kekKeyIdAttribute, ok := attributes["kek_key_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_id is missing from object`) - - return nil, diags - } - - kekKeyIdVal, ok := kekKeyIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_id expected to be basetypes.StringValue, was: %T`, kekKeyIdAttribute)) - } - - kekKeyRingIdAttribute, ok := attributes["kek_key_ring_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_ring_id is missing from object`) - - return nil, diags - } - - kekKeyRingIdVal, ok := kekKeyRingIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_ring_id expected to be basetypes.StringValue, was: %T`, kekKeyRingIdAttribute)) - } - - kekKeyVersionAttribute, ok := attributes["kek_key_version"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_version is missing from object`) - - return nil, diags - } - - kekKeyVersionVal, ok := kekKeyVersionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_version expected to be basetypes.StringValue, was: %T`, kekKeyVersionAttribute)) - } - - serviceAccountAttribute, ok := attributes["service_account"] - - if !ok { - diags.AddError( - "Attribute Missing", - `service_account is missing from object`) - - return nil, diags - } - - serviceAccountVal, ok := serviceAccountAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`service_account expected to be basetypes.StringValue, was: %T`, serviceAccountAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return EncryptionValue{ - KekKeyId: kekKeyIdVal, - KekKeyRingId: kekKeyRingIdVal, - KekKeyVersion: kekKeyVersionVal, - ServiceAccount: serviceAccountVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewEncryptionValueNull() EncryptionValue { - return EncryptionValue{ - state: attr.ValueStateNull, - } -} - -func NewEncryptionValueUnknown() EncryptionValue { - return EncryptionValue{ - state: attr.ValueStateUnknown, - } -} - -func NewEncryptionValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (EncryptionValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing EncryptionValue Attribute Value", - "While creating a EncryptionValue value, a missing attribute value was detected. "+ - "A EncryptionValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("EncryptionValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid EncryptionValue Attribute Type", - "While creating a EncryptionValue value, an invalid attribute value was detected. "+ - "A EncryptionValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("EncryptionValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("EncryptionValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra EncryptionValue Attribute Value", - "While creating a EncryptionValue value, an extra attribute value was detected. "+ - "A EncryptionValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra EncryptionValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewEncryptionValueUnknown(), diags - } - - kekKeyIdAttribute, ok := attributes["kek_key_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_id is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - kekKeyIdVal, ok := kekKeyIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_id expected to be basetypes.StringValue, was: %T`, kekKeyIdAttribute)) - } - - kekKeyRingIdAttribute, ok := attributes["kek_key_ring_id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_ring_id is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - kekKeyRingIdVal, ok := kekKeyRingIdAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_ring_id expected to be basetypes.StringValue, was: %T`, kekKeyRingIdAttribute)) - } - - kekKeyVersionAttribute, ok := attributes["kek_key_version"] - - if !ok { - diags.AddError( - "Attribute Missing", - `kek_key_version is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - kekKeyVersionVal, ok := kekKeyVersionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`kek_key_version expected to be basetypes.StringValue, was: %T`, kekKeyVersionAttribute)) - } - - serviceAccountAttribute, ok := attributes["service_account"] - - if !ok { - diags.AddError( - "Attribute Missing", - `service_account is missing from object`) - - return NewEncryptionValueUnknown(), diags - } - - serviceAccountVal, ok := serviceAccountAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`service_account expected to be basetypes.StringValue, was: %T`, serviceAccountAttribute)) - } - - if diags.HasError() { - return NewEncryptionValueUnknown(), diags - } - - return EncryptionValue{ - KekKeyId: kekKeyIdVal, - KekKeyRingId: kekKeyRingIdVal, - KekKeyVersion: kekKeyVersionVal, - ServiceAccount: serviceAccountVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewEncryptionValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) EncryptionValue { - object, diags := NewEncryptionValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewEncryptionValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t EncryptionType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewEncryptionValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewEncryptionValueUnknown(), nil - } - - if in.IsNull() { - return NewEncryptionValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewEncryptionValueMust(EncryptionValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t EncryptionType) ValueType(ctx context.Context) attr.Value { - return EncryptionValue{} -} - -var _ basetypes.ObjectValuable = EncryptionValue{} - -type EncryptionValue struct { - KekKeyId basetypes.StringValue `tfsdk:"kek_key_id"` - KekKeyRingId basetypes.StringValue `tfsdk:"kek_key_ring_id"` - KekKeyVersion basetypes.StringValue `tfsdk:"kek_key_version"` - ServiceAccount basetypes.StringValue `tfsdk:"service_account"` - state attr.ValueState -} - -func (v EncryptionValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 4) - - var val tftypes.Value - var err error - - attrTypes["kek_key_id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["kek_key_ring_id"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["kek_key_version"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["service_account"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 4) - - val, err = v.KekKeyId.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["kek_key_id"] = val - - val, err = v.KekKeyRingId.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["kek_key_ring_id"] = val - - val, err = v.KekKeyVersion.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["kek_key_version"] = val - - val, err = v.ServiceAccount.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["service_account"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v EncryptionValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v EncryptionValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v EncryptionValue) String() string { - return "EncryptionValue" -} - -func (v EncryptionValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "kek_key_id": basetypes.StringType{}, - "kek_key_ring_id": basetypes.StringType{}, - "kek_key_version": basetypes.StringType{}, - "service_account": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "kek_key_id": v.KekKeyId, - "kek_key_ring_id": v.KekKeyRingId, - "kek_key_version": v.KekKeyVersion, - "service_account": v.ServiceAccount, - }) - - return objVal, diags -} - -func (v EncryptionValue) Equal(o attr.Value) bool { - other, ok := o.(EncryptionValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.KekKeyId.Equal(other.KekKeyId) { - return false - } - - if !v.KekKeyRingId.Equal(other.KekKeyRingId) { - return false - } - - if !v.KekKeyVersion.Equal(other.KekKeyVersion) { - return false - } - - if !v.ServiceAccount.Equal(other.ServiceAccount) { - return false - } - - return true -} - -func (v EncryptionValue) Type(ctx context.Context) attr.Type { - return EncryptionType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v EncryptionValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "kek_key_id": basetypes.StringType{}, - "kek_key_ring_id": basetypes.StringType{}, - "kek_key_version": basetypes.StringType{}, - "service_account": basetypes.StringType{}, - } -} - -var _ basetypes.ObjectTypable = NetworkType{} - -type NetworkType struct { - basetypes.ObjectType -} - -func (t NetworkType) Equal(o attr.Type) bool { - other, ok := o.(NetworkType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t NetworkType) String() string { - return "NetworkType" -} - -func (t NetworkType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - accessScopeAttribute, ok := attributes["access_scope"] - - if !ok { - diags.AddError( - "Attribute Missing", - `access_scope is missing from object`) - - return nil, diags - } - - accessScopeVal, ok := accessScopeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`access_scope expected to be basetypes.StringValue, was: %T`, accessScopeAttribute)) - } - - aclAttribute, ok := attributes["acl"] - - if !ok { - diags.AddError( - "Attribute Missing", - `acl is missing from object`) - - return nil, diags - } - - aclVal, ok := aclAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`acl expected to be basetypes.ListValue, was: %T`, aclAttribute)) - } - - instanceAddressAttribute, ok := attributes["instance_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `instance_address is missing from object`) - - return nil, diags - } - - instanceAddressVal, ok := instanceAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`instance_address expected to be basetypes.StringValue, was: %T`, instanceAddressAttribute)) - } - - routerAddressAttribute, ok := attributes["router_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `router_address is missing from object`) - - return nil, diags - } - - routerAddressVal, ok := routerAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`router_address expected to be basetypes.StringValue, was: %T`, routerAddressAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return NetworkValue{ - AccessScope: accessScopeVal, - Acl: aclVal, - InstanceAddress: instanceAddressVal, - RouterAddress: routerAddressVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewNetworkValueNull() NetworkValue { - return NetworkValue{ - state: attr.ValueStateNull, - } -} - -func NewNetworkValueUnknown() NetworkValue { - return NetworkValue{ - state: attr.ValueStateUnknown, - } -} - -func NewNetworkValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (NetworkValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing NetworkValue Attribute Value", - "While creating a NetworkValue value, a missing attribute value was detected. "+ - "A NetworkValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("NetworkValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid NetworkValue Attribute Type", - "While creating a NetworkValue value, an invalid attribute value was detected. "+ - "A NetworkValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("NetworkValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("NetworkValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra NetworkValue Attribute Value", - "While creating a NetworkValue value, an extra attribute value was detected. "+ - "A NetworkValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra NetworkValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewNetworkValueUnknown(), diags - } - - accessScopeAttribute, ok := attributes["access_scope"] - - if !ok { - diags.AddError( - "Attribute Missing", - `access_scope is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - accessScopeVal, ok := accessScopeAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`access_scope expected to be basetypes.StringValue, was: %T`, accessScopeAttribute)) - } - - aclAttribute, ok := attributes["acl"] - - if !ok { - diags.AddError( - "Attribute Missing", - `acl is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - aclVal, ok := aclAttribute.(basetypes.ListValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`acl expected to be basetypes.ListValue, was: %T`, aclAttribute)) - } - - instanceAddressAttribute, ok := attributes["instance_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `instance_address is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - instanceAddressVal, ok := instanceAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`instance_address expected to be basetypes.StringValue, was: %T`, instanceAddressAttribute)) - } - - routerAddressAttribute, ok := attributes["router_address"] - - if !ok { - diags.AddError( - "Attribute Missing", - `router_address is missing from object`) - - return NewNetworkValueUnknown(), diags - } - - routerAddressVal, ok := routerAddressAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`router_address expected to be basetypes.StringValue, was: %T`, routerAddressAttribute)) - } - - if diags.HasError() { - return NewNetworkValueUnknown(), diags - } - - return NetworkValue{ - AccessScope: accessScopeVal, - Acl: aclVal, - InstanceAddress: instanceAddressVal, - RouterAddress: routerAddressVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewNetworkValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) NetworkValue { - object, diags := NewNetworkValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewNetworkValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t NetworkType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewNetworkValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewNetworkValueUnknown(), nil - } - - if in.IsNull() { - return NewNetworkValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewNetworkValueMust(NetworkValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t NetworkType) ValueType(ctx context.Context) attr.Value { - return NetworkValue{} -} - -var _ basetypes.ObjectValuable = NetworkValue{} - -type NetworkValue struct { - AccessScope basetypes.StringValue `tfsdk:"access_scope"` - Acl basetypes.ListValue `tfsdk:"acl"` - InstanceAddress basetypes.StringValue `tfsdk:"instance_address"` - RouterAddress basetypes.StringValue `tfsdk:"router_address"` - state attr.ValueState -} - -func (v NetworkValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 4) - - var val tftypes.Value - var err error - - attrTypes["access_scope"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["acl"] = basetypes.ListType{ - ElemType: types.StringType, - }.TerraformType(ctx) - attrTypes["instance_address"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["router_address"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 4) - - val, err = v.AccessScope.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["access_scope"] = val - - val, err = v.Acl.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["acl"] = val - - val, err = v.InstanceAddress.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["instance_address"] = val - - val, err = v.RouterAddress.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["router_address"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v NetworkValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v NetworkValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v NetworkValue) String() string { - return "NetworkValue" -} - -func (v NetworkValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - var aclVal basetypes.ListValue - switch { - case v.Acl.IsUnknown(): - aclVal = types.ListUnknown(types.StringType) - case v.Acl.IsNull(): - aclVal = types.ListNull(types.StringType) - default: - var d diag.Diagnostics - aclVal, d = types.ListValue(types.StringType, v.Acl.Elements()) - diags.Append(d...) - } - - if diags.HasError() { - return types.ObjectUnknown(map[string]attr.Type{ - "access_scope": basetypes.StringType{}, - "acl": basetypes.ListType{ - ElemType: types.StringType, - }, - "instance_address": basetypes.StringType{}, - "router_address": basetypes.StringType{}, - }), diags - } - - attributeTypes := map[string]attr.Type{ - "access_scope": basetypes.StringType{}, - "acl": basetypes.ListType{ - ElemType: types.StringType, - }, - "instance_address": basetypes.StringType{}, - "router_address": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "access_scope": v.AccessScope, - "acl": aclVal, - "instance_address": v.InstanceAddress, - "router_address": v.RouterAddress, - }) - - return objVal, diags -} - -func (v NetworkValue) Equal(o attr.Value) bool { - other, ok := o.(NetworkValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.AccessScope.Equal(other.AccessScope) { - return false - } - - if !v.Acl.Equal(other.Acl) { - return false - } - - if !v.InstanceAddress.Equal(other.InstanceAddress) { - return false - } - - if !v.RouterAddress.Equal(other.RouterAddress) { - return false - } - - return true -} - -func (v NetworkValue) Type(ctx context.Context) attr.Type { - return NetworkType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v NetworkValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "access_scope": basetypes.StringType{}, - "acl": basetypes.ListType{ - ElemType: types.StringType, - }, - "instance_address": basetypes.StringType{}, - "router_address": basetypes.StringType{}, - } -} - -var _ basetypes.ObjectTypable = StorageType{} - -type StorageType struct { - basetypes.ObjectType -} - -func (t StorageType) Equal(o attr.Type) bool { - other, ok := o.(StorageType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t StorageType) String() string { - return "StorageType" -} - -func (t StorageType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - classAttribute, ok := attributes["class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `class is missing from object`) - - return nil, diags - } - - classVal, ok := classAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`class expected to be basetypes.StringValue, was: %T`, classAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return StorageValue{ - Class: classVal, - Size: sizeVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageValueNull() StorageValue { - return StorageValue{ - state: attr.ValueStateNull, - } -} - -func NewStorageValueUnknown() StorageValue { - return StorageValue{ - state: attr.ValueStateUnknown, - } -} - -func NewStorageValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (StorageValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing StorageValue Attribute Value", - "While creating a StorageValue value, a missing attribute value was detected. "+ - "A StorageValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid StorageValue Attribute Type", - "While creating a StorageValue value, an invalid attribute value was detected. "+ - "A StorageValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("StorageValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("StorageValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra StorageValue Attribute Value", - "While creating a StorageValue value, an extra attribute value was detected. "+ - "A StorageValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra StorageValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewStorageValueUnknown(), diags - } - - classAttribute, ok := attributes["class"] - - if !ok { - diags.AddError( - "Attribute Missing", - `class is missing from object`) - - return NewStorageValueUnknown(), diags - } - - classVal, ok := classAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`class expected to be basetypes.StringValue, was: %T`, classAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewStorageValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - if diags.HasError() { - return NewStorageValueUnknown(), diags - } - - return StorageValue{ - Class: classVal, - Size: sizeVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewStorageValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) StorageValue { - object, diags := NewStorageValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewStorageValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t StorageType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewStorageValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewStorageValueUnknown(), nil - } - - if in.IsNull() { - return NewStorageValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewStorageValueMust(StorageValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t StorageType) ValueType(ctx context.Context) attr.Value { - return StorageValue{} -} - -var _ basetypes.ObjectValuable = StorageValue{} - -type StorageValue struct { - Class basetypes.StringValue `tfsdk:"class"` - Size basetypes.Int64Value `tfsdk:"size"` - state attr.ValueState -} - -func (v StorageValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 2) - - var val tftypes.Value - var err error - - attrTypes["class"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 2) - - val, err = v.Class.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["class"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v StorageValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v StorageValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v StorageValue) String() string { - return "StorageValue" -} - -func (v StorageValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "class": basetypes.StringType{}, - "size": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "class": v.Class, - "size": v.Size, - }) - - return objVal, diags -} - -func (v StorageValue) Equal(o attr.Value) bool { - other, ok := o.(StorageValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Class.Equal(other.Class) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - return true -} - -func (v StorageValue) Type(ctx context.Context) attr.Type { - return StorageType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v StorageValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "class": basetypes.StringType{}, - "size": basetypes.Int64Type{}, - } -} diff --git a/stackit/internal/services/sqlserverflexbeta/user/datasources_gen/user_data_source_gen.go b/stackit/internal/services/sqlserverflexbeta/user/datasources_gen/user_data_source_gen.go deleted file mode 100644 index 34aef9ca..00000000 --- a/stackit/internal/services/sqlserverflexbeta/user/datasources_gen/user_data_source_gen.go +++ /dev/null @@ -1,1118 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package sqlserverflexbeta - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -func UserDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "instance_id": schema.StringAttribute{ - Required: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "page": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of the page of items list to be returned.", - MarkdownDescription: "Number of the page of items list to be returned.", - }, - "pagination": schema.SingleNestedAttribute{ - Attributes: map[string]schema.Attribute{ - "page": schema.Int64Attribute{ - Computed: true, - }, - "size": schema.Int64Attribute{ - Computed: true, - }, - "sort": schema.StringAttribute{ - Computed: true, - }, - "total_pages": schema.Int64Attribute{ - Computed: true, - }, - "total_rows": schema.Int64Attribute{ - Computed: true, - }, - }, - CustomType: PaginationType{ - ObjectType: types.ObjectType{ - AttrTypes: PaginationValue{}.AttributeTypes(ctx), - }, - }, - Computed: true, - }, - "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", - ), - }, - }, - "size": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "Number of items to be returned on each page.", - MarkdownDescription: "Number of items to be returned on each page.", - }, - "sort": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "Sorting of the users to be returned on each page.", - MarkdownDescription: "Sorting of the users to be returned on each page.", - Validators: []validator.String{ - stringvalidator.OneOf( - "id.asc", - "id.desc", - "index.desc", - "index.asc", - "name.desc", - "name.asc", - "status.desc", - "status.asc", - ), - }, - }, - "users": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "tf_original_api_id": schema.Int64Attribute{ - Computed: true, - Description: "The ID of the user.", - MarkdownDescription: "The ID of the user.", - }, - "status": schema.StringAttribute{ - Computed: true, - Description: "The current status of the user.", - MarkdownDescription: "The current status of the user.", - }, - "username": schema.StringAttribute{ - Computed: true, - Description: "The name of the user.", - MarkdownDescription: "The name of the user.", - }, - }, - CustomType: UsersType{ - ObjectType: types.ObjectType{ - AttrTypes: UsersValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "List of all users inside an instance", - MarkdownDescription: "List of all users inside an instance", - }, - }, - } -} - -type UserModel struct { - InstanceId types.String `tfsdk:"instance_id"` - Page types.Int64 `tfsdk:"page"` - Pagination PaginationValue `tfsdk:"pagination"` - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Size types.Int64 `tfsdk:"size"` - Sort types.String `tfsdk:"sort"` - Users types.List `tfsdk:"users"` -} - -var _ basetypes.ObjectTypable = PaginationType{} - -type PaginationType struct { - basetypes.ObjectType -} - -func (t PaginationType) Equal(o attr.Type) bool { - other, ok := o.(PaginationType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t PaginationType) String() string { - return "PaginationType" -} - -func (t PaginationType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return nil, diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return nil, diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return nil, diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return nil, diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return nil, diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueNull() PaginationValue { - return PaginationValue{ - state: attr.ValueStateNull, - } -} - -func NewPaginationValueUnknown() PaginationValue { - return PaginationValue{ - state: attr.ValueStateUnknown, - } -} - -func NewPaginationValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (PaginationValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing PaginationValue Attribute Value", - "While creating a PaginationValue value, a missing attribute value was detected. "+ - "A PaginationValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid PaginationValue Attribute Type", - "While creating a PaginationValue value, an invalid attribute value was detected. "+ - "A PaginationValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("PaginationValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra PaginationValue Attribute Value", - "While creating a PaginationValue value, an extra attribute value was detected. "+ - "A PaginationValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra PaginationValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - pageAttribute, ok := attributes["page"] - - if !ok { - diags.AddError( - "Attribute Missing", - `page is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - pageVal, ok := pageAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`page expected to be basetypes.Int64Value, was: %T`, pageAttribute)) - } - - sizeAttribute, ok := attributes["size"] - - if !ok { - diags.AddError( - "Attribute Missing", - `size is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sizeVal, ok := sizeAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`size expected to be basetypes.Int64Value, was: %T`, sizeAttribute)) - } - - sortAttribute, ok := attributes["sort"] - - if !ok { - diags.AddError( - "Attribute Missing", - `sort is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - sortVal, ok := sortAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`sort expected to be basetypes.StringValue, was: %T`, sortAttribute)) - } - - totalPagesAttribute, ok := attributes["total_pages"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_pages is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalPagesVal, ok := totalPagesAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_pages expected to be basetypes.Int64Value, was: %T`, totalPagesAttribute)) - } - - totalRowsAttribute, ok := attributes["total_rows"] - - if !ok { - diags.AddError( - "Attribute Missing", - `total_rows is missing from object`) - - return NewPaginationValueUnknown(), diags - } - - totalRowsVal, ok := totalRowsAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`total_rows expected to be basetypes.Int64Value, was: %T`, totalRowsAttribute)) - } - - if diags.HasError() { - return NewPaginationValueUnknown(), diags - } - - return PaginationValue{ - Page: pageVal, - Size: sizeVal, - Sort: sortVal, - TotalPages: totalPagesVal, - TotalRows: totalRowsVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewPaginationValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) PaginationValue { - object, diags := NewPaginationValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewPaginationValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t PaginationType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewPaginationValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewPaginationValueUnknown(), nil - } - - if in.IsNull() { - return NewPaginationValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewPaginationValueMust(PaginationValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t PaginationType) ValueType(ctx context.Context) attr.Value { - return PaginationValue{} -} - -var _ basetypes.ObjectValuable = PaginationValue{} - -type PaginationValue struct { - Page basetypes.Int64Value `tfsdk:"page"` - Size basetypes.Int64Value `tfsdk:"size"` - Sort basetypes.StringValue `tfsdk:"sort"` - TotalPages basetypes.Int64Value `tfsdk:"total_pages"` - TotalRows basetypes.Int64Value `tfsdk:"total_rows"` - state attr.ValueState -} - -func (v PaginationValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 5) - - var val tftypes.Value - var err error - - attrTypes["page"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["size"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["sort"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["total_pages"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["total_rows"] = basetypes.Int64Type{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 5) - - val, err = v.Page.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["page"] = val - - val, err = v.Size.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["size"] = val - - val, err = v.Sort.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["sort"] = val - - val, err = v.TotalPages.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_pages"] = val - - val, err = v.TotalRows.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["total_rows"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v PaginationValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v PaginationValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v PaginationValue) String() string { - return "PaginationValue" -} - -func (v PaginationValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "page": v.Page, - "size": v.Size, - "sort": v.Sort, - "total_pages": v.TotalPages, - "total_rows": v.TotalRows, - }) - - return objVal, diags -} - -func (v PaginationValue) Equal(o attr.Value) bool { - other, ok := o.(PaginationValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Page.Equal(other.Page) { - return false - } - - if !v.Size.Equal(other.Size) { - return false - } - - if !v.Sort.Equal(other.Sort) { - return false - } - - if !v.TotalPages.Equal(other.TotalPages) { - return false - } - - if !v.TotalRows.Equal(other.TotalRows) { - return false - } - - return true -} - -func (v PaginationValue) Type(ctx context.Context) attr.Type { - return PaginationType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v PaginationValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "page": basetypes.Int64Type{}, - "size": basetypes.Int64Type{}, - "sort": basetypes.StringType{}, - "total_pages": basetypes.Int64Type{}, - "total_rows": basetypes.Int64Type{}, - } -} - -var _ basetypes.ObjectTypable = UsersType{} - -type UsersType struct { - basetypes.ObjectType -} - -func (t UsersType) Equal(o attr.Type) bool { - other, ok := o.(UsersType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t UsersType) String() string { - return "UsersType" -} - -func (t UsersType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return nil, diags - } - - idVal, ok := idAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.Int64Value, was: %T`, idAttribute)) - } - - statusAttribute, ok := attributes["status"] - - if !ok { - diags.AddError( - "Attribute Missing", - `status is missing from object`) - - return nil, diags - } - - statusVal, ok := statusAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`status expected to be basetypes.StringValue, was: %T`, statusAttribute)) - } - - usernameAttribute, ok := attributes["username"] - - if !ok { - diags.AddError( - "Attribute Missing", - `username is missing from object`) - - return nil, diags - } - - usernameVal, ok := usernameAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`username expected to be basetypes.StringValue, was: %T`, usernameAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return UsersValue{ - Id: idVal, - Status: statusVal, - Username: usernameVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewUsersValueNull() UsersValue { - return UsersValue{ - state: attr.ValueStateNull, - } -} - -func NewUsersValueUnknown() UsersValue { - return UsersValue{ - state: attr.ValueStateUnknown, - } -} - -func NewUsersValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (UsersValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing UsersValue Attribute Value", - "While creating a UsersValue value, a missing attribute value was detected. "+ - "A UsersValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("UsersValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid UsersValue Attribute Type", - "While creating a UsersValue value, an invalid attribute value was detected. "+ - "A UsersValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("UsersValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("UsersValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra UsersValue Attribute Value", - "While creating a UsersValue value, an extra attribute value was detected. "+ - "A UsersValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra UsersValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewUsersValueUnknown(), diags - } - - idAttribute, ok := attributes["id"] - - if !ok { - diags.AddError( - "Attribute Missing", - `id is missing from object`) - - return NewUsersValueUnknown(), diags - } - - idVal, ok := idAttribute.(basetypes.Int64Value) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`id expected to be basetypes.Int64Value, was: %T`, idAttribute)) - } - - statusAttribute, ok := attributes["status"] - - if !ok { - diags.AddError( - "Attribute Missing", - `status is missing from object`) - - return NewUsersValueUnknown(), diags - } - - statusVal, ok := statusAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`status expected to be basetypes.StringValue, was: %T`, statusAttribute)) - } - - usernameAttribute, ok := attributes["username"] - - if !ok { - diags.AddError( - "Attribute Missing", - `username is missing from object`) - - return NewUsersValueUnknown(), diags - } - - usernameVal, ok := usernameAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`username expected to be basetypes.StringValue, was: %T`, usernameAttribute)) - } - - if diags.HasError() { - return NewUsersValueUnknown(), diags - } - - return UsersValue{ - Id: idVal, - Status: statusVal, - Username: usernameVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewUsersValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) UsersValue { - object, diags := NewUsersValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewUsersValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t UsersType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewUsersValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewUsersValueUnknown(), nil - } - - if in.IsNull() { - return NewUsersValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewUsersValueMust(UsersValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t UsersType) ValueType(ctx context.Context) attr.Value { - return UsersValue{} -} - -var _ basetypes.ObjectValuable = UsersValue{} - -type UsersValue struct { - Id basetypes.Int64Value `tfsdk:"id"` - Status basetypes.StringValue `tfsdk:"status"` - Username basetypes.StringValue `tfsdk:"username"` - state attr.ValueState -} - -func (v UsersValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 3) - - var val tftypes.Value - var err error - - attrTypes["id"] = basetypes.Int64Type{}.TerraformType(ctx) - attrTypes["status"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["username"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 3) - - val, err = v.Id.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["id"] = val - - val, err = v.Status.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["status"] = val - - val, err = v.Username.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["username"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v UsersValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v UsersValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v UsersValue) String() string { - return "UsersValue" -} - -func (v UsersValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "id": basetypes.Int64Type{}, - "status": basetypes.StringType{}, - "username": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "id": v.Id, - "status": v.Status, - "username": v.Username, - }) - - return objVal, diags -} - -func (v UsersValue) Equal(o attr.Value) bool { - other, ok := o.(UsersValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Id.Equal(other.Id) { - return false - } - - if !v.Status.Equal(other.Status) { - return false - } - - if !v.Username.Equal(other.Username) { - return false - } - - return true -} - -func (v UsersValue) Type(ctx context.Context) attr.Type { - return UsersType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v UsersValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "id": basetypes.Int64Type{}, - "status": basetypes.StringType{}, - "username": basetypes.StringType{}, - } -} diff --git a/stackit/internal/services/sqlserverflexbeta/user/resources_gen/user_resource_gen.go b/stackit/internal/services/sqlserverflexbeta/user/resources_gen/user_resource_gen.go deleted file mode 100644 index 3bf7f4fc..00000000 --- a/stackit/internal/services/sqlserverflexbeta/user/resources_gen/user_resource_gen.go +++ /dev/null @@ -1,111 +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 UserResourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "default_database": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "The default database for a user of the instance.", - MarkdownDescription: "The default database for a user of 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.", - MarkdownDescription: "The ID of the user.", - }, - "instance_id": schema.StringAttribute{ - Optional: true, - Computed: true, - Description: "The ID of the instance.", - MarkdownDescription: "The ID of the instance.", - }, - "password": schema.StringAttribute{ - Computed: true, - 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, - 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", - ), - }, - }, - "roles": schema.ListAttribute{ - ElementType: types.StringType, - Required: true, - Description: "A list containing the user roles for the instance.", - MarkdownDescription: "A list containing the user roles for the instance.", - }, - "status": schema.StringAttribute{ - Computed: true, - Description: "The current status of the user.", - MarkdownDescription: "The current status of the user.", - }, - "uri": schema.StringAttribute{ - Computed: true, - Description: "The connection string for the user to the instance.", - MarkdownDescription: "The connection string for the user to the instance.", - }, - "user_id": schema.Int64Attribute{ - Optional: true, - Computed: true, - Description: "The ID of the user.", - MarkdownDescription: "The ID of the user.", - }, - "username": schema.StringAttribute{ - Required: true, - Description: "The name of the user.", - MarkdownDescription: "The name of the user.", - }, - }, - } -} - -type UserModel struct { - DefaultDatabase types.String `tfsdk:"default_database"` - Host types.String `tfsdk:"host"` - Id types.Int64 `tfsdk:"id"` - InstanceId types.String `tfsdk:"instance_id"` - 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"` - Status types.String `tfsdk:"status"` - Uri types.String `tfsdk:"uri"` - UserId types.Int64 `tfsdk:"user_id"` - Username types.String `tfsdk:"username"` -} diff --git a/stackit/internal/services/sqlserverflexbeta/versions/datasources_gen/version_data_source_gen.go b/stackit/internal/services/sqlserverflexbeta/versions/datasources_gen/version_data_source_gen.go deleted file mode 100644 index 239b44d3..00000000 --- a/stackit/internal/services/sqlserverflexbeta/versions/datasources_gen/version_data_source_gen.go +++ /dev/null @@ -1,569 +0,0 @@ -// Code generated by terraform-plugin-framework-generator DO NOT EDIT. - -package sqlserverflexbeta - -import ( - "context" - "fmt" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" - "github.com/hashicorp/terraform-plugin-framework/attr" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/schema/validator" - "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" - "github.com/hashicorp/terraform-plugin-go/tftypes" - "strings" - - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" -) - -func VersionDataSourceSchema(ctx context.Context) schema.Schema { - return schema.Schema{ - Attributes: map[string]schema.Attribute{ - "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", - ), - }, - }, - "versions": schema.ListNestedAttribute{ - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "beta": schema.BoolAttribute{ - Computed: true, - Description: "Flag if the version is a beta version. If set the version may contain bugs and is not fully tested.", - MarkdownDescription: "Flag if the version is a beta version. If set the version may contain bugs and is not fully tested.", - }, - "deprecated": schema.StringAttribute{ - Computed: true, - Description: "Timestamp in RFC3339 format which says when the version will no longer be supported by STACKIT.", - MarkdownDescription: "Timestamp in RFC3339 format which says when the version will no longer be supported by STACKIT.", - }, - "recommend": schema.BoolAttribute{ - Computed: true, - Description: "Flag if the version is recommend by the STACKIT Team.", - MarkdownDescription: "Flag if the version is recommend by the STACKIT Team.", - }, - "version": schema.StringAttribute{ - Computed: true, - Description: "The sqlserver version used for the instance.", - MarkdownDescription: "The sqlserver version used for the instance.", - }, - }, - CustomType: VersionsType{ - ObjectType: types.ObjectType{ - AttrTypes: VersionsValue{}.AttributeTypes(ctx), - }, - }, - }, - Computed: true, - Description: "A list containing available sqlserver versions.", - MarkdownDescription: "A list containing available sqlserver versions.", - }, - }, - } -} - -type VersionModel struct { - ProjectId types.String `tfsdk:"project_id"` - Region types.String `tfsdk:"region"` - Versions types.List `tfsdk:"versions"` -} - -var _ basetypes.ObjectTypable = VersionsType{} - -type VersionsType struct { - basetypes.ObjectType -} - -func (t VersionsType) Equal(o attr.Type) bool { - other, ok := o.(VersionsType) - - if !ok { - return false - } - - return t.ObjectType.Equal(other.ObjectType) -} - -func (t VersionsType) String() string { - return "VersionsType" -} - -func (t VersionsType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { - var diags diag.Diagnostics - - attributes := in.Attributes() - - betaAttribute, ok := attributes["beta"] - - if !ok { - diags.AddError( - "Attribute Missing", - `beta is missing from object`) - - return nil, diags - } - - betaVal, ok := betaAttribute.(basetypes.BoolValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`beta expected to be basetypes.BoolValue, was: %T`, betaAttribute)) - } - - deprecatedAttribute, ok := attributes["deprecated"] - - if !ok { - diags.AddError( - "Attribute Missing", - `deprecated is missing from object`) - - return nil, diags - } - - deprecatedVal, ok := deprecatedAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`deprecated expected to be basetypes.StringValue, was: %T`, deprecatedAttribute)) - } - - recommendAttribute, ok := attributes["recommend"] - - if !ok { - diags.AddError( - "Attribute Missing", - `recommend is missing from object`) - - return nil, diags - } - - recommendVal, ok := recommendAttribute.(basetypes.BoolValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`recommend expected to be basetypes.BoolValue, was: %T`, recommendAttribute)) - } - - versionAttribute, ok := attributes["version"] - - if !ok { - diags.AddError( - "Attribute Missing", - `version is missing from object`) - - return nil, diags - } - - versionVal, ok := versionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`version expected to be basetypes.StringValue, was: %T`, versionAttribute)) - } - - if diags.HasError() { - return nil, diags - } - - return VersionsValue{ - Beta: betaVal, - Deprecated: deprecatedVal, - Recommend: recommendVal, - Version: versionVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewVersionsValueNull() VersionsValue { - return VersionsValue{ - state: attr.ValueStateNull, - } -} - -func NewVersionsValueUnknown() VersionsValue { - return VersionsValue{ - state: attr.ValueStateUnknown, - } -} - -func NewVersionsValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (VersionsValue, diag.Diagnostics) { - var diags diag.Diagnostics - - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/521 - ctx := context.Background() - - for name, attributeType := range attributeTypes { - attribute, ok := attributes[name] - - if !ok { - diags.AddError( - "Missing VersionsValue Attribute Value", - "While creating a VersionsValue value, a missing attribute value was detected. "+ - "A VersionsValue must contain values for all attributes, even if null or unknown. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("VersionsValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), - ) - - continue - } - - if !attributeType.Equal(attribute.Type(ctx)) { - diags.AddError( - "Invalid VersionsValue Attribute Type", - "While creating a VersionsValue value, an invalid attribute value was detected. "+ - "A VersionsValue must use a matching attribute type for the value. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("VersionsValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ - fmt.Sprintf("VersionsValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), - ) - } - } - - for name := range attributes { - _, ok := attributeTypes[name] - - if !ok { - diags.AddError( - "Extra VersionsValue Attribute Value", - "While creating a VersionsValue value, an extra attribute value was detected. "+ - "A VersionsValue must not contain values beyond the expected attribute types. "+ - "This is always an issue with the provider and should be reported to the provider developers.\n\n"+ - fmt.Sprintf("Extra VersionsValue Attribute Name: %s", name), - ) - } - } - - if diags.HasError() { - return NewVersionsValueUnknown(), diags - } - - betaAttribute, ok := attributes["beta"] - - if !ok { - diags.AddError( - "Attribute Missing", - `beta is missing from object`) - - return NewVersionsValueUnknown(), diags - } - - betaVal, ok := betaAttribute.(basetypes.BoolValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`beta expected to be basetypes.BoolValue, was: %T`, betaAttribute)) - } - - deprecatedAttribute, ok := attributes["deprecated"] - - if !ok { - diags.AddError( - "Attribute Missing", - `deprecated is missing from object`) - - return NewVersionsValueUnknown(), diags - } - - deprecatedVal, ok := deprecatedAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`deprecated expected to be basetypes.StringValue, was: %T`, deprecatedAttribute)) - } - - recommendAttribute, ok := attributes["recommend"] - - if !ok { - diags.AddError( - "Attribute Missing", - `recommend is missing from object`) - - return NewVersionsValueUnknown(), diags - } - - recommendVal, ok := recommendAttribute.(basetypes.BoolValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`recommend expected to be basetypes.BoolValue, was: %T`, recommendAttribute)) - } - - versionAttribute, ok := attributes["version"] - - if !ok { - diags.AddError( - "Attribute Missing", - `version is missing from object`) - - return NewVersionsValueUnknown(), diags - } - - versionVal, ok := versionAttribute.(basetypes.StringValue) - - if !ok { - diags.AddError( - "Attribute Wrong Type", - fmt.Sprintf(`version expected to be basetypes.StringValue, was: %T`, versionAttribute)) - } - - if diags.HasError() { - return NewVersionsValueUnknown(), diags - } - - return VersionsValue{ - Beta: betaVal, - Deprecated: deprecatedVal, - Recommend: recommendVal, - Version: versionVal, - state: attr.ValueStateKnown, - }, diags -} - -func NewVersionsValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) VersionsValue { - object, diags := NewVersionsValue(attributeTypes, attributes) - - if diags.HasError() { - // This could potentially be added to the diag package. - diagsStrings := make([]string, 0, len(diags)) - - for _, diagnostic := range diags { - diagsStrings = append(diagsStrings, fmt.Sprintf( - "%s | %s | %s", - diagnostic.Severity(), - diagnostic.Summary(), - diagnostic.Detail())) - } - - panic("NewVersionsValueMust received error(s): " + strings.Join(diagsStrings, "\n")) - } - - return object -} - -func (t VersionsType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - if in.Type() == nil { - return NewVersionsValueNull(), nil - } - - if !in.Type().Equal(t.TerraformType(ctx)) { - return nil, fmt.Errorf("expected %s, got %s", t.TerraformType(ctx), in.Type()) - } - - if !in.IsKnown() { - return NewVersionsValueUnknown(), nil - } - - if in.IsNull() { - return NewVersionsValueNull(), nil - } - - attributes := map[string]attr.Value{} - - val := map[string]tftypes.Value{} - - err := in.As(&val) - - if err != nil { - return nil, err - } - - for k, v := range val { - a, err := t.AttrTypes[k].ValueFromTerraform(ctx, v) - - if err != nil { - return nil, err - } - - attributes[k] = a - } - - return NewVersionsValueMust(VersionsValue{}.AttributeTypes(ctx), attributes), nil -} - -func (t VersionsType) ValueType(ctx context.Context) attr.Value { - return VersionsValue{} -} - -var _ basetypes.ObjectValuable = VersionsValue{} - -type VersionsValue struct { - Beta basetypes.BoolValue `tfsdk:"beta"` - Deprecated basetypes.StringValue `tfsdk:"deprecated"` - Recommend basetypes.BoolValue `tfsdk:"recommend"` - Version basetypes.StringValue `tfsdk:"version"` - state attr.ValueState -} - -func (v VersionsValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - attrTypes := make(map[string]tftypes.Type, 4) - - var val tftypes.Value - var err error - - attrTypes["beta"] = basetypes.BoolType{}.TerraformType(ctx) - attrTypes["deprecated"] = basetypes.StringType{}.TerraformType(ctx) - attrTypes["recommend"] = basetypes.BoolType{}.TerraformType(ctx) - attrTypes["version"] = basetypes.StringType{}.TerraformType(ctx) - - objectType := tftypes.Object{AttributeTypes: attrTypes} - - switch v.state { - case attr.ValueStateKnown: - vals := make(map[string]tftypes.Value, 4) - - val, err = v.Beta.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["beta"] = val - - val, err = v.Deprecated.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["deprecated"] = val - - val, err = v.Recommend.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["recommend"] = val - - val, err = v.Version.ToTerraformValue(ctx) - - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - vals["version"] = val - - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - - return tftypes.NewValue(objectType, vals), nil - case attr.ValueStateNull: - return tftypes.NewValue(objectType, nil), nil - case attr.ValueStateUnknown: - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - default: - panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", v.state)) - } -} - -func (v VersionsValue) IsNull() bool { - return v.state == attr.ValueStateNull -} - -func (v VersionsValue) IsUnknown() bool { - return v.state == attr.ValueStateUnknown -} - -func (v VersionsValue) String() string { - return "VersionsValue" -} - -func (v VersionsValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { - var diags diag.Diagnostics - - attributeTypes := map[string]attr.Type{ - "beta": basetypes.BoolType{}, - "deprecated": basetypes.StringType{}, - "recommend": basetypes.BoolType{}, - "version": basetypes.StringType{}, - } - - if v.IsNull() { - return types.ObjectNull(attributeTypes), diags - } - - if v.IsUnknown() { - return types.ObjectUnknown(attributeTypes), diags - } - - objVal, diags := types.ObjectValue( - attributeTypes, - map[string]attr.Value{ - "beta": v.Beta, - "deprecated": v.Deprecated, - "recommend": v.Recommend, - "version": v.Version, - }) - - return objVal, diags -} - -func (v VersionsValue) Equal(o attr.Value) bool { - other, ok := o.(VersionsValue) - - if !ok { - return false - } - - if v.state != other.state { - return false - } - - if v.state != attr.ValueStateKnown { - return true - } - - if !v.Beta.Equal(other.Beta) { - return false - } - - if !v.Deprecated.Equal(other.Deprecated) { - return false - } - - if !v.Recommend.Equal(other.Recommend) { - return false - } - - if !v.Version.Equal(other.Version) { - return false - } - - return true -} - -func (v VersionsValue) Type(ctx context.Context) attr.Type { - return VersionsType{ - basetypes.ObjectType{ - AttrTypes: v.AttributeTypes(ctx), - }, - } -} - -func (v VersionsValue) AttributeTypes(ctx context.Context) map[string]attr.Type { - return map[string]attr.Type{ - "beta": basetypes.BoolType{}, - "deprecated": basetypes.StringType{}, - "recommend": basetypes.BoolType{}, - "version": basetypes.StringType{}, - } -} -- 2.49.1