diff --git a/ovh/data_cloud_project_storage.go b/ovh/data_cloud_project_storage.go new file mode 100644 index 000000000..18d1c8acd --- /dev/null +++ b/ovh/data_cloud_project_storage.go @@ -0,0 +1,80 @@ +package ovh + +import ( + "context" + "fmt" + "net/url" + "strconv" + + "github.com/hashicorp/terraform-plugin-framework/datasource" +) + +var _ datasource.DataSourceWithConfigure = (*cloudProjectStorageDataSource)(nil) + +func NewCloudProjectStorageDataSource() datasource.DataSource { + return &cloudProjectStorageDataSource{} +} + +type cloudProjectStorageDataSource struct { + config *Config +} + +func (d *cloudProjectStorageDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_cloud_project_storage" +} + +func (d *cloudProjectStorageDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + if req.ProviderData == nil { + return + } + + config, ok := req.ProviderData.(*Config) + if !ok { + resp.Diagnostics.AddError( + "Unexpected Data Source Configure Type", + fmt.Sprintf("Expected *Config, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + return + } + + d.config = config +} + +func (d *cloudProjectStorageDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = CloudProjectStorageDataSourceSchema(ctx) +} + +func (d *cloudProjectStorageDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var data CloudProjectStorageModel + + // Read Terraform configuration data into the model + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + queryParams := url.Values{} + if !data.Limit.IsNull() && !data.Limit.IsUnknown() { + queryParams.Add("limit", strconv.FormatInt(data.Limit.ValueInt64(), 10)) + } + if !data.Marker.IsNull() && !data.Marker.IsUnknown() { + queryParams.Add("marker", data.Marker.ValueString()) + } + if !data.Prefix.IsNull() && !data.Prefix.IsUnknown() { + queryParams.Add("prefix", data.Prefix.ValueString()) + } + + // Read API call logic + endpoint := "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/region/" + url.PathEscape(data.RegionName.ValueString()) + "/storage/" + url.PathEscape(data.Name.ValueString()) + "?" + queryParams.Encode() + if err := d.config.OVHClient.Get(endpoint, &data); err != nil { + resp.Diagnostics.AddError( + fmt.Sprintf("Error calling Get %s", endpoint), + err.Error(), + ) + return + } + + // Save data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} diff --git a/ovh/data_cloud_project_storage_gen.go b/ovh/data_cloud_project_storage_gen.go new file mode 100644 index 000000000..54eda0147 --- /dev/null +++ b/ovh/data_cloud_project_storage_gen.go @@ -0,0 +1,325 @@ +// Code generated by terraform-plugin-framework-generator DO NOT EDIT. + +package ovh + +import ( + "context" + "github.com/hashicorp/terraform-plugin-framework/types" + ovhtypes "github.com/ovh/terraform-provider-ovh/ovh/types" + + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" +) + +func CloudProjectStorageDataSourceSchema(ctx context.Context) schema.Schema { + attrs := map[string]schema.Attribute{ + "created_at": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "The date and timestamp when the resource was created", + MarkdownDescription: "The date and timestamp when the resource was created", + }, + "encryption": schema.SingleNestedAttribute{ + Attributes: map[string]schema.Attribute{ + "sse_algorithm": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Encryption algorithm", + MarkdownDescription: "Encryption algorithm", + }, + }, + CustomType: EncryptionType{ + ObjectType: types.ObjectType{ + AttrTypes: EncryptionValue{}.AttributeTypes(ctx), + }, + }, + Computed: true, + Description: "Encryption configuration", + MarkdownDescription: "Encryption configuration", + }, + "limit": schema.Int64Attribute{ + CustomType: ovhtypes.TfInt64Type{}, + Optional: true, + Computed: true, + Description: "Limit the number of objects returned (1000 maximum, defaults to 1000)", + MarkdownDescription: "Limit the number of objects returned (1000 maximum, defaults to 1000)", + }, + "marker": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Optional: true, + Computed: true, + Description: "Key to start with when listing objects", + MarkdownDescription: "Key to start with when listing objects", + }, + "name": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Required: true, + Description: "Name", + MarkdownDescription: "Name", + }, + "objects": schema.ListNestedAttribute{ + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "etag": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "ETag", + MarkdownDescription: "ETag", + }, + "is_delete_marker": schema.BoolAttribute{ + CustomType: ovhtypes.TfBoolType{}, + Computed: true, + Description: "Whether this object is a delete marker", + MarkdownDescription: "Whether this object is a delete marker", + }, + "is_latest": schema.BoolAttribute{ + CustomType: ovhtypes.TfBoolType{}, + Computed: true, + Description: "Whether this is the latest version of the object", + MarkdownDescription: "Whether this is the latest version of the object", + }, + "key": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Key", + MarkdownDescription: "Key", + }, + "last_modified": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Last modification date", + MarkdownDescription: "Last modification date", + }, + "size": schema.Int64Attribute{ + CustomType: ovhtypes.TfInt64Type{}, + Computed: true, + Description: "Size (bytes)", + MarkdownDescription: "Size (bytes)", + }, + "storage_class": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Storage class", + MarkdownDescription: "Storage class", + }, + "version_id": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Version ID of the object", + MarkdownDescription: "Version ID of the object", + }, + }, + CustomType: ObjectsType{ + ObjectType: types.ObjectType{ + AttrTypes: ObjectsValue{}.AttributeTypes(ctx), + }, + }, + }, + CustomType: ovhtypes.NewTfListNestedType[ObjectsValue](ctx), + Computed: true, + Description: "Container objects", + MarkdownDescription: "Container objects", + }, + "objects_count": schema.Int64Attribute{ + CustomType: ovhtypes.TfInt64Type{}, + Computed: true, + Description: "Container total objects count", + MarkdownDescription: "Container total objects count", + }, + "objects_size": schema.Int64Attribute{ + CustomType: ovhtypes.TfInt64Type{}, + Computed: true, + Description: "Container total objects size (bytes)", + MarkdownDescription: "Container total objects size (bytes)", + }, + "owner_id": schema.Int64Attribute{ + CustomType: ovhtypes.TfInt64Type{}, + Computed: true, + Description: "Container owner user ID", + MarkdownDescription: "Container owner user ID", + }, + "prefix": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Optional: true, + Computed: true, + Description: "List objects whose key begins with this prefix", + MarkdownDescription: "List objects whose key begins with this prefix", + }, + "region": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Container region", + MarkdownDescription: "Container region", + }, + "region_name": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Required: true, + Description: "Region name", + MarkdownDescription: "Region name", + }, + "replication": schema.SingleNestedAttribute{ + Attributes: map[string]schema.Attribute{ + "rules": schema.ListNestedAttribute{ + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "delete_marker_replication": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Delete marker replication", + MarkdownDescription: "Delete marker replication", + }, + "destination": schema.SingleNestedAttribute{ + Attributes: map[string]schema.Attribute{ + "name": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Destination bucket name", + MarkdownDescription: "Destination bucket name", + }, + "region": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Destination region, can be null if destination bucket has been deleted", + MarkdownDescription: "Destination region, can be null if destination bucket has been deleted", + }, + "storage_class": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Destination storage class", + MarkdownDescription: "Destination storage class", + }, + }, + CustomType: ReplicationRulesDestinationType{ + ObjectType: types.ObjectType{ + AttrTypes: ReplicationRulesDestinationValue{}.AttributeTypes(ctx), + }, + }, + Computed: true, + Description: "Rule destination configuration", + MarkdownDescription: "Rule destination configuration", + }, + "filter": schema.SingleNestedAttribute{ + Attributes: map[string]schema.Attribute{ + "prefix": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Prefix filter", + MarkdownDescription: "Prefix filter", + }, + "tags": schema.MapAttribute{ + CustomType: ovhtypes.NewTfMapNestedType[ovhtypes.TfStringValue](ctx), + Computed: true, + Description: "Tags filter", + MarkdownDescription: "Tags filter", + }, + }, + CustomType: ReplicationRulesFilterType{ + ObjectType: types.ObjectType{ + AttrTypes: ReplicationRulesFilterValue{}.AttributeTypes(ctx), + }, + }, + Computed: true, + Description: "Rule filters", + MarkdownDescription: "Rule filters", + }, + "id": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Rule ID", + MarkdownDescription: "Rule ID", + }, + "priority": schema.Int64Attribute{ + CustomType: ovhtypes.TfInt64Type{}, + Computed: true, + Description: "Rule priority", + MarkdownDescription: "Rule priority", + }, + "status": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Rule status", + MarkdownDescription: "Rule status", + }, + }, + CustomType: ReplicationRulesType{ + ObjectType: types.ObjectType{ + AttrTypes: ReplicationRulesValue{}.AttributeTypes(ctx), + }, + }, + }, + CustomType: ovhtypes.NewTfListNestedType[ReplicationRulesValue](ctx), + Computed: true, + Description: "Replication rules", + MarkdownDescription: "Replication rules", + }, + }, + CustomType: ReplicationType{ + ObjectType: types.ObjectType{ + AttrTypes: ReplicationValue{}.AttributeTypes(ctx), + }, + }, + Computed: true, + Description: "Replication configuration", + MarkdownDescription: "Replication configuration", + }, + "service_name": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Required: true, + Description: "Service name", + MarkdownDescription: "Service name", + }, + "tags": schema.MapAttribute{ + CustomType: ovhtypes.NewTfMapNestedType[ovhtypes.TfStringValue](ctx), + Computed: true, + Description: "Container tags", + MarkdownDescription: "Container tags", + }, + "versioning": schema.SingleNestedAttribute{ + Attributes: map[string]schema.Attribute{ + "status": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Versioning status", + MarkdownDescription: "Versioning status", + }, + }, + CustomType: VersioningType{ + ObjectType: types.ObjectType{ + AttrTypes: VersioningValue{}.AttributeTypes(ctx), + }, + }, + Computed: true, + Description: "Versioning configuration", + MarkdownDescription: "Versioning configuration", + }, + "virtual_host": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Container virtual host", + MarkdownDescription: "Container virtual host", + }, + } + + return schema.Schema{ + Attributes: attrs, + } +} + +type CloudProjectStorageModel struct { + CreatedAt ovhtypes.TfStringValue `tfsdk:"created_at" json:"createdAt"` + Encryption EncryptionValue `tfsdk:"encryption" json:"encryption"` + Limit ovhtypes.TfInt64Value `tfsdk:"limit" json:"limit"` + Marker ovhtypes.TfStringValue `tfsdk:"marker" json:"marker"` + Name ovhtypes.TfStringValue `tfsdk:"name" json:"name"` + Objects ovhtypes.TfListNestedValue[ObjectsValue] `tfsdk:"objects" json:"objects"` + ObjectsCount ovhtypes.TfInt64Value `tfsdk:"objects_count" json:"objectsCount"` + ObjectsSize ovhtypes.TfInt64Value `tfsdk:"objects_size" json:"objectsSize"` + OwnerId ovhtypes.TfInt64Value `tfsdk:"owner_id" json:"ownerId"` + Prefix ovhtypes.TfStringValue `tfsdk:"prefix" json:"prefix"` + Region ovhtypes.TfStringValue `tfsdk:"region" json:"region"` + RegionName ovhtypes.TfStringValue `tfsdk:"region_name" json:"regionName"` + Replication ReplicationValue `tfsdk:"replication" json:"replication"` + ServiceName ovhtypes.TfStringValue `tfsdk:"service_name" json:"serviceName"` + Tags ovhtypes.TfMapNestedValue[ovhtypes.TfStringValue] `tfsdk:"tags" json:"tags"` + Versioning VersioningValue `tfsdk:"versioning" json:"versioning"` + VirtualHost ovhtypes.TfStringValue `tfsdk:"virtual_host" json:"virtualHost"` +} diff --git a/ovh/data_cloud_project_storages.go b/ovh/data_cloud_project_storages.go new file mode 100644 index 000000000..a456bf7fd --- /dev/null +++ b/ovh/data_cloud_project_storages.go @@ -0,0 +1,68 @@ +package ovh + +import ( + "context" + "fmt" + "net/url" + + "github.com/hashicorp/terraform-plugin-framework/datasource" +) + +var _ datasource.DataSourceWithConfigure = (*cloudProjectStoragesDataSource)(nil) + +func NewCloudProjectStoragesDataSource() datasource.DataSource { + return &cloudProjectStoragesDataSource{} +} + +type cloudProjectStoragesDataSource struct { + config *Config +} + +func (d *cloudProjectStoragesDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_cloud_project_storages" +} + +func (d *cloudProjectStoragesDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + if req.ProviderData == nil { + return + } + + config, ok := req.ProviderData.(*Config) + if !ok { + resp.Diagnostics.AddError( + "Unexpected Data Source Configure Type", + fmt.Sprintf("Expected *Config, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + return + } + + d.config = config +} + +func (d *cloudProjectStoragesDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = CloudProjectStoragesDataSourceSchema(ctx) +} + +func (d *cloudProjectStoragesDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var data CloudProjectStoragesModel + + // Read Terraform configuration data into the model + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) + + if resp.Diagnostics.HasError() { + return + } + + // Read API call logic + endpoint := "/cloud/project/" + url.PathEscape(data.ServiceName.ValueString()) + "/region/" + url.PathEscape(data.RegionName.ValueString()) + "/storage" + if err := d.config.OVHClient.Get(endpoint, &data.Containers); err != nil { + resp.Diagnostics.AddError( + fmt.Sprintf("Error calling Get %s", endpoint), + err.Error(), + ) + return + } + + // Save data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} diff --git a/ovh/data_cloud_project_storages_gen.go b/ovh/data_cloud_project_storages_gen.go new file mode 100644 index 000000000..349cc19d7 --- /dev/null +++ b/ovh/data_cloud_project_storages_gen.go @@ -0,0 +1,1361 @@ +// Code generated by terraform-plugin-framework-generator DO NOT EDIT. + +package ovh + +import ( + "context" + "encoding/json" + "fmt" + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" + "github.com/hashicorp/terraform-plugin-go/tftypes" + ovhtypes "github.com/ovh/terraform-provider-ovh/ovh/types" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" +) + +func CloudProjectStoragesDataSourceSchema(ctx context.Context) schema.Schema { + attrs := map[string]schema.Attribute{ + "containers": schema.SetNestedAttribute{ + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "created_at": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "The date and timestamp when the resource was created", + MarkdownDescription: "The date and timestamp when the resource was created", + }, + "encryption": schema.SingleNestedAttribute{ + Attributes: map[string]schema.Attribute{ + "sse_algorithm": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Encryption algorithm", + MarkdownDescription: "Encryption algorithm", + }, + }, + CustomType: EncryptionType{ + ObjectType: types.ObjectType{ + AttrTypes: EncryptionValue{}.AttributeTypes(ctx), + }, + }, + Computed: true, + Description: "Encryption configuration", + MarkdownDescription: "Encryption configuration", + }, + "name": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Container name", + MarkdownDescription: "Container name", + }, + "objects": schema.ListNestedAttribute{ + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "etag": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "ETag", + MarkdownDescription: "ETag", + }, + "is_delete_marker": schema.BoolAttribute{ + CustomType: ovhtypes.TfBoolType{}, + Computed: true, + Description: "Whether this object is a delete marker", + MarkdownDescription: "Whether this object is a delete marker", + }, + "is_latest": schema.BoolAttribute{ + CustomType: ovhtypes.TfBoolType{}, + Computed: true, + Description: "Whether this is the latest version of the object", + MarkdownDescription: "Whether this is the latest version of the object", + }, + "key": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Key", + MarkdownDescription: "Key", + }, + "last_modified": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Last modification date", + MarkdownDescription: "Last modification date", + }, + "size": schema.Int64Attribute{ + CustomType: ovhtypes.TfInt64Type{}, + Computed: true, + Description: "Size (bytes)", + MarkdownDescription: "Size (bytes)", + }, + "storage_class": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Storage class", + MarkdownDescription: "Storage class", + }, + "version_id": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Version ID of the object", + MarkdownDescription: "Version ID of the object", + }, + }, + CustomType: ObjectsType{ + ObjectType: types.ObjectType{ + AttrTypes: ObjectsValue{}.AttributeTypes(ctx), + }, + }, + }, + CustomType: ovhtypes.NewTfListNestedType[ObjectsValue](ctx), + Computed: true, + Description: "Container objects", + MarkdownDescription: "Container objects", + }, + "objects_count": schema.Int64Attribute{ + CustomType: ovhtypes.TfInt64Type{}, + Computed: true, + Description: "Container total objects count", + MarkdownDescription: "Container total objects count", + }, + "objects_size": schema.Int64Attribute{ + CustomType: ovhtypes.TfInt64Type{}, + Computed: true, + Description: "Container total objects size (bytes)", + MarkdownDescription: "Container total objects size (bytes)", + }, + "owner_id": schema.Int64Attribute{ + CustomType: ovhtypes.TfInt64Type{}, + Computed: true, + Description: "Container owner user ID", + MarkdownDescription: "Container owner user ID", + }, + "region": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Container region", + MarkdownDescription: "Container region", + }, + "replication": schema.SingleNestedAttribute{ + Attributes: map[string]schema.Attribute{ + "rules": schema.ListNestedAttribute{ + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "delete_marker_replication": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Delete marker replication", + MarkdownDescription: "Delete marker replication", + }, + "destination": schema.SingleNestedAttribute{ + Attributes: map[string]schema.Attribute{ + "name": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Destination bucket name", + MarkdownDescription: "Destination bucket name", + }, + "region": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Destination region, can be null if destination bucket has been deleted", + MarkdownDescription: "Destination region, can be null if destination bucket has been deleted", + }, + "storage_class": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Destination storage class", + MarkdownDescription: "Destination storage class", + }, + }, + CustomType: ReplicationRulesDestinationType{ + ObjectType: types.ObjectType{ + AttrTypes: ReplicationRulesDestinationValue{}.AttributeTypes(ctx), + }, + }, + Computed: true, + Description: "Rule destination configuration", + MarkdownDescription: "Rule destination configuration", + }, + "filter": schema.SingleNestedAttribute{ + Attributes: map[string]schema.Attribute{ + "prefix": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Prefix filter", + MarkdownDescription: "Prefix filter", + }, + "tags": schema.MapAttribute{ + CustomType: ovhtypes.NewTfMapNestedType[ovhtypes.TfStringValue](ctx), + Computed: true, + Description: "Tags filter", + MarkdownDescription: "Tags filter", + }, + }, + CustomType: ReplicationRulesFilterType{ + ObjectType: types.ObjectType{ + AttrTypes: ReplicationRulesFilterValue{}.AttributeTypes(ctx), + }, + }, + Computed: true, + Description: "Rule filters", + MarkdownDescription: "Rule filters", + }, + "id": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Rule ID", + MarkdownDescription: "Rule ID", + }, + "priority": schema.Int64Attribute{ + CustomType: ovhtypes.TfInt64Type{}, + Computed: true, + Description: "Rule priority", + MarkdownDescription: "Rule priority", + }, + "status": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Rule status", + MarkdownDescription: "Rule status", + }, + }, + CustomType: ReplicationRulesType{ + ObjectType: types.ObjectType{ + AttrTypes: ReplicationRulesValue{}.AttributeTypes(ctx), + }, + }, + }, + CustomType: ovhtypes.NewTfListNestedType[ReplicationRulesValue](ctx), + Computed: true, + Description: "Replication rules", + MarkdownDescription: "Replication rules", + }, + }, + CustomType: ReplicationType{ + ObjectType: types.ObjectType{ + AttrTypes: ReplicationValue{}.AttributeTypes(ctx), + }, + }, + Computed: true, + Description: "Replication configuration", + MarkdownDescription: "Replication configuration", + }, + "tags": schema.MapAttribute{ + CustomType: ovhtypes.NewTfMapNestedType[ovhtypes.TfStringValue](ctx), + Computed: true, + Description: "Container tags", + MarkdownDescription: "Container tags", + }, + "versioning": schema.SingleNestedAttribute{ + Attributes: map[string]schema.Attribute{ + "status": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Versioning status", + MarkdownDescription: "Versioning status", + }, + }, + CustomType: VersioningType{ + ObjectType: types.ObjectType{ + AttrTypes: VersioningValue{}.AttributeTypes(ctx), + }, + }, + Computed: true, + Description: "Versioning configuration", + MarkdownDescription: "Versioning configuration", + }, + "virtual_host": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Computed: true, + Description: "Container virtual host", + MarkdownDescription: "Container virtual host", + }, + }, + CustomType: CloudProjectStoragesType{ + ObjectType: types.ObjectType{ + AttrTypes: CloudProjectStoragesValue{}.AttributeTypes(ctx), + }, + }, + }, + CustomType: ovhtypes.NewTfListNestedType[CloudProjectStoragesValue](ctx), + Computed: true, + }, + "region_name": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Required: true, + Description: "Region name", + MarkdownDescription: "Region name", + }, + "service_name": schema.StringAttribute{ + CustomType: ovhtypes.TfStringType{}, + Required: true, + Description: "Service name", + MarkdownDescription: "Service name", + }, + } + + return schema.Schema{ + Attributes: attrs, + } +} + +type CloudProjectStoragesModel struct { + Containers ovhtypes.TfListNestedValue[CloudProjectStoragesValue] `tfsdk:"containers" json:"containers"` + RegionName ovhtypes.TfStringValue `tfsdk:"region_name" json:"regionName"` + ServiceName ovhtypes.TfStringValue `tfsdk:"service_name" json:"serviceName"` +} + +func (v *CloudProjectStoragesModel) MergeWith(other *CloudProjectStoragesModel) { + if (v.Containers.IsUnknown() || v.Containers.IsNull()) && !other.Containers.IsUnknown() { + v.Containers = other.Containers + } + + if (v.RegionName.IsUnknown() || v.RegionName.IsNull()) && !other.RegionName.IsUnknown() { + v.RegionName = other.RegionName + } + + if (v.ServiceName.IsUnknown() || v.ServiceName.IsNull()) && !other.ServiceName.IsUnknown() { + v.ServiceName = other.ServiceName + } +} + +var _ basetypes.ObjectTypable = CloudProjectStoragesType{} + +type CloudProjectStoragesType struct { + basetypes.ObjectType +} + +func (t CloudProjectStoragesType) Equal(o attr.Type) bool { + other, ok := o.(CloudProjectStoragesType) + + if !ok { + return false + } + + return t.ObjectType.Equal(other.ObjectType) +} + +func (t CloudProjectStoragesType) String() string { + return "CloudProjectStoragesType" +} + +func (t CloudProjectStoragesType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { + var diags diag.Diagnostics + + attributes := in.Attributes() + + createdAtAttribute, ok := attributes["created_at"] + + if !ok { + diags.AddError( + "Attribute Missing", + `created_at is missing from object`) + + return nil, diags + } + + createdAtVal, ok := createdAtAttribute.(ovhtypes.TfStringValue) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`created_at expected to be ovhtypes.TfStringValue, was: %T`, createdAtAttribute)) + } + + encryptionAttribute, ok := attributes["encryption"] + + if !ok { + diags.AddError( + "Attribute Missing", + `encryption is missing from object`) + + return nil, diags + } + + encryptionVal, ok := encryptionAttribute.(EncryptionValue) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`encryption expected to be EncryptionValue, was: %T`, encryptionAttribute)) + } + + nameAttribute, ok := attributes["name"] + + if !ok { + diags.AddError( + "Attribute Missing", + `name is missing from object`) + + return nil, diags + } + + nameVal, ok := nameAttribute.(ovhtypes.TfStringValue) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`name expected to be ovhtypes.TfStringValue, was: %T`, nameAttribute)) + } + + objectsAttribute, ok := attributes["objects"] + + if !ok { + diags.AddError( + "Attribute Missing", + `objects is missing from object`) + + return nil, diags + } + + objectsVal, ok := objectsAttribute.(ovhtypes.TfListNestedValue[ObjectsValue]) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`objects expected to be ovhtypes.TfListNestedValue[ObjectsValue], was: %T`, objectsAttribute)) + } + + objectsCountAttribute, ok := attributes["objects_count"] + + if !ok { + diags.AddError( + "Attribute Missing", + `objects_count is missing from object`) + + return nil, diags + } + + objectsCountVal, ok := objectsCountAttribute.(ovhtypes.TfInt64Value) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`objects_count expected to be ovhtypes.TfInt64Value, was: %T`, objectsCountAttribute)) + } + + objectsSizeAttribute, ok := attributes["objects_size"] + + if !ok { + diags.AddError( + "Attribute Missing", + `objects_size is missing from object`) + + return nil, diags + } + + objectsSizeVal, ok := objectsSizeAttribute.(ovhtypes.TfInt64Value) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`objects_size expected to be ovhtypes.TfInt64Value, was: %T`, objectsSizeAttribute)) + } + + ownerIdAttribute, ok := attributes["owner_id"] + + if !ok { + diags.AddError( + "Attribute Missing", + `owner_id is missing from object`) + + return nil, diags + } + + ownerIdVal, ok := ownerIdAttribute.(ovhtypes.TfInt64Value) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`owner_id expected to be ovhtypes.TfInt64Value, was: %T`, ownerIdAttribute)) + } + + regionAttribute, ok := attributes["region"] + + if !ok { + diags.AddError( + "Attribute Missing", + `region is missing from object`) + + return nil, diags + } + + regionVal, ok := regionAttribute.(ovhtypes.TfStringValue) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`region expected to be ovhtypes.TfStringValue, was: %T`, regionAttribute)) + } + + replicationAttribute, ok := attributes["replication"] + + if !ok { + diags.AddError( + "Attribute Missing", + `replication is missing from object`) + + return nil, diags + } + + replicationVal, ok := replicationAttribute.(ReplicationValue) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`replication expected to be ReplicationValue, was: %T`, replicationAttribute)) + } + + tagsAttribute, ok := attributes["tags"] + + if !ok { + diags.AddError( + "Attribute Missing", + `tags is missing from object`) + + return nil, diags + } + + tagsVal, ok := tagsAttribute.(ovhtypes.TfMapNestedValue[ovhtypes.TfStringValue]) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`tags expected to be ovhtypes.TfMapNestedValue[ovhtypes.TfStringValue], was: %T`, tagsAttribute)) + } + + versioningAttribute, ok := attributes["versioning"] + + if !ok { + diags.AddError( + "Attribute Missing", + `versioning is missing from object`) + + return nil, diags + } + + versioningVal, ok := versioningAttribute.(VersioningValue) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`versioning expected to be VersioningValue, was: %T`, versioningAttribute)) + } + + virtualHostAttribute, ok := attributes["virtual_host"] + + if !ok { + diags.AddError( + "Attribute Missing", + `virtual_host is missing from object`) + + return nil, diags + } + + virtualHostVal, ok := virtualHostAttribute.(ovhtypes.TfStringValue) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`virtual_host expected to be ovhtypes.TfStringValue, was: %T`, virtualHostAttribute)) + } + + if diags.HasError() { + return nil, diags + } + + return CloudProjectStoragesValue{ + CreatedAt: createdAtVal, + Encryption: encryptionVal, + Name: nameVal, + Objects: objectsVal, + ObjectsCount: objectsCountVal, + ObjectsSize: objectsSizeVal, + OwnerId: ownerIdVal, + Region: regionVal, + Replication: replicationVal, + Tags: tagsVal, + Versioning: versioningVal, + VirtualHost: virtualHostVal, + state: attr.ValueStateKnown, + }, diags +} + +func NewCloudProjectStoragesValueNull() CloudProjectStoragesValue { + return CloudProjectStoragesValue{ + state: attr.ValueStateNull, + } +} + +func NewCloudProjectStoragesValueUnknown() CloudProjectStoragesValue { + return CloudProjectStoragesValue{ + state: attr.ValueStateUnknown, + } +} + +func NewCloudProjectStoragesValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (CloudProjectStoragesValue, 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 CloudProjectStoragesValue Attribute Value", + "While creating a CloudProjectStoragesValue value, a missing attribute value was detected. "+ + "A CloudProjectStoragesValue 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("CloudProjectStoragesValue Attribute Name (%s) Expected Type: %s", name, attributeType.String()), + ) + + continue + } + + if !attributeType.Equal(attribute.Type(ctx)) { + diags.AddError( + "Invalid CloudProjectStoragesValue Attribute Type", + "While creating a CloudProjectStoragesValue value, an invalid attribute value was detected. "+ + "A CloudProjectStoragesValue 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("CloudProjectStoragesValue Attribute Name (%s) Expected Type: %s\n", name, attributeType.String())+ + fmt.Sprintf("CloudProjectStoragesValue Attribute Name (%s) Given Type: %s", name, attribute.Type(ctx)), + ) + } + } + + for name := range attributes { + _, ok := attributeTypes[name] + + if !ok { + diags.AddError( + "Extra CloudProjectStoragesValue Attribute Value", + "While creating a CloudProjectStoragesValue value, an extra attribute value was detected. "+ + "A CloudProjectStoragesValue 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 CloudProjectStoragesValue Attribute Name: %s", name), + ) + } + } + + if diags.HasError() { + return NewCloudProjectStoragesValueUnknown(), diags + } + + createdAtAttribute, ok := attributes["created_at"] + + if !ok { + diags.AddError( + "Attribute Missing", + `created_at is missing from object`) + + return NewCloudProjectStoragesValueUnknown(), diags + } + + createdAtVal, ok := createdAtAttribute.(ovhtypes.TfStringValue) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`created_at expected to be ovhtypes.TfStringValue, was: %T`, createdAtAttribute)) + } + + encryptionAttribute, ok := attributes["encryption"] + + if !ok { + diags.AddError( + "Attribute Missing", + `encryption is missing from object`) + + return NewCloudProjectStoragesValueUnknown(), diags + } + + encryptionVal, ok := encryptionAttribute.(EncryptionValue) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`encryption expected to be EncryptionValue, was: %T`, encryptionAttribute)) + } + + nameAttribute, ok := attributes["name"] + + if !ok { + diags.AddError( + "Attribute Missing", + `name is missing from object`) + + return NewCloudProjectStoragesValueUnknown(), diags + } + + nameVal, ok := nameAttribute.(ovhtypes.TfStringValue) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`name expected to be ovhtypes.TfStringValue, was: %T`, nameAttribute)) + } + + objectsAttribute, ok := attributes["objects"] + + if !ok { + diags.AddError( + "Attribute Missing", + `objects is missing from object`) + + return NewCloudProjectStoragesValueUnknown(), diags + } + + objectsVal, ok := objectsAttribute.(ovhtypes.TfListNestedValue[ObjectsValue]) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`objects expected to be ovhtypes.TfListNestedValue[ObjectsValue], was: %T`, objectsAttribute)) + } + + objectsCountAttribute, ok := attributes["objects_count"] + + if !ok { + diags.AddError( + "Attribute Missing", + `objects_count is missing from object`) + + return NewCloudProjectStoragesValueUnknown(), diags + } + + objectsCountVal, ok := objectsCountAttribute.(ovhtypes.TfInt64Value) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`objects_count expected to be ovhtypes.TfInt64Value, was: %T`, objectsCountAttribute)) + } + + objectsSizeAttribute, ok := attributes["objects_size"] + + if !ok { + diags.AddError( + "Attribute Missing", + `objects_size is missing from object`) + + return NewCloudProjectStoragesValueUnknown(), diags + } + + objectsSizeVal, ok := objectsSizeAttribute.(ovhtypes.TfInt64Value) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`objects_size expected to be ovhtypes.TfInt64Value, was: %T`, objectsSizeAttribute)) + } + + ownerIdAttribute, ok := attributes["owner_id"] + + if !ok { + diags.AddError( + "Attribute Missing", + `owner_id is missing from object`) + + return NewCloudProjectStoragesValueUnknown(), diags + } + + ownerIdVal, ok := ownerIdAttribute.(ovhtypes.TfInt64Value) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`owner_id expected to be ovhtypes.TfInt64Value, was: %T`, ownerIdAttribute)) + } + + regionAttribute, ok := attributes["region"] + + if !ok { + diags.AddError( + "Attribute Missing", + `region is missing from object`) + + return NewCloudProjectStoragesValueUnknown(), diags + } + + regionVal, ok := regionAttribute.(ovhtypes.TfStringValue) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`region expected to be ovhtypes.TfStringValue, was: %T`, regionAttribute)) + } + + replicationAttribute, ok := attributes["replication"] + + if !ok { + diags.AddError( + "Attribute Missing", + `replication is missing from object`) + + return NewCloudProjectStoragesValueUnknown(), diags + } + + replicationVal, ok := replicationAttribute.(ReplicationValue) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`replication expected to be ReplicationValue, was: %T`, replicationAttribute)) + } + + tagsAttribute, ok := attributes["tags"] + + if !ok { + diags.AddError( + "Attribute Missing", + `tags is missing from object`) + + return NewCloudProjectStoragesValueUnknown(), diags + } + + tagsVal, ok := tagsAttribute.(ovhtypes.TfMapNestedValue[ovhtypes.TfStringValue]) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`tags expected to be ovhtypes.TfMapNestedValue[ovhtypes.TfStringValue], was: %T`, tagsAttribute)) + } + + versioningAttribute, ok := attributes["versioning"] + + if !ok { + diags.AddError( + "Attribute Missing", + `versioning is missing from object`) + + return NewCloudProjectStoragesValueUnknown(), diags + } + + versioningVal, ok := versioningAttribute.(VersioningValue) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`versioning expected to be VersioningValue, was: %T`, versioningAttribute)) + } + + virtualHostAttribute, ok := attributes["virtual_host"] + + if !ok { + diags.AddError( + "Attribute Missing", + `virtual_host is missing from object`) + + return NewCloudProjectStoragesValueUnknown(), diags + } + + virtualHostVal, ok := virtualHostAttribute.(ovhtypes.TfStringValue) + + if !ok { + diags.AddError( + "Attribute Wrong Type", + fmt.Sprintf(`virtual_host expected to be ovhtypes.TfStringValue, was: %T`, virtualHostAttribute)) + } + + if diags.HasError() { + return NewCloudProjectStoragesValueUnknown(), diags + } + + return CloudProjectStoragesValue{ + CreatedAt: createdAtVal, + Encryption: encryptionVal, + Name: nameVal, + Objects: objectsVal, + ObjectsCount: objectsCountVal, + ObjectsSize: objectsSizeVal, + OwnerId: ownerIdVal, + Region: regionVal, + Replication: replicationVal, + Tags: tagsVal, + Versioning: versioningVal, + VirtualHost: virtualHostVal, + state: attr.ValueStateKnown, + }, diags +} + +func NewCloudProjectStoragesValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) CloudProjectStoragesValue { + object, diags := NewCloudProjectStoragesValue(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("NewCloudProjectStoragesValueMust received error(s): " + strings.Join(diagsStrings, "\n")) + } + + return object +} + +func (t CloudProjectStoragesType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { + if in.Type() == nil { + return NewCloudProjectStoragesValueNull(), 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 NewCloudProjectStoragesValueUnknown(), nil + } + + if in.IsNull() { + return NewCloudProjectStoragesValueNull(), 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 NewCloudProjectStoragesValueMust(CloudProjectStoragesValue{}.AttributeTypes(ctx), attributes), nil +} + +func (t CloudProjectStoragesType) ValueType(ctx context.Context) attr.Value { + return CloudProjectStoragesValue{} +} + +var _ basetypes.ObjectValuable = CloudProjectStoragesValue{} + +type CloudProjectStoragesValue struct { + CreatedAt ovhtypes.TfStringValue `tfsdk:"created_at" json:"createdAt"` + Encryption EncryptionValue `tfsdk:"encryption" json:"encryption"` + Name ovhtypes.TfStringValue `tfsdk:"name" json:"name"` + Objects ovhtypes.TfListNestedValue[ObjectsValue] `tfsdk:"objects" json:"objects"` + ObjectsCount ovhtypes.TfInt64Value `tfsdk:"objects_count" json:"objectsCount"` + ObjectsSize ovhtypes.TfInt64Value `tfsdk:"objects_size" json:"objectsSize"` + OwnerId ovhtypes.TfInt64Value `tfsdk:"owner_id" json:"ownerId"` + Region ovhtypes.TfStringValue `tfsdk:"region" json:"region"` + Replication ReplicationValue `tfsdk:"replication" json:"replication"` + Tags ovhtypes.TfMapNestedValue[ovhtypes.TfStringValue] `tfsdk:"tags" json:"tags"` + Versioning VersioningValue `tfsdk:"versioning" json:"versioning"` + VirtualHost ovhtypes.TfStringValue `tfsdk:"virtual_host" json:"virtualHost"` + state attr.ValueState +} + +func (v *CloudProjectStoragesValue) UnmarshalJSON(data []byte) error { + type JsonCloudProjectStoragesValue CloudProjectStoragesValue + + var tmp JsonCloudProjectStoragesValue + if err := json.Unmarshal(data, &tmp); err != nil { + return err + } + v.CreatedAt = tmp.CreatedAt + v.Encryption = tmp.Encryption + v.Name = tmp.Name + v.Objects = tmp.Objects + v.ObjectsCount = tmp.ObjectsCount + v.ObjectsSize = tmp.ObjectsSize + v.OwnerId = tmp.OwnerId + v.Region = tmp.Region + v.Replication = tmp.Replication + v.Tags = tmp.Tags + v.Versioning = tmp.Versioning + v.VirtualHost = tmp.VirtualHost + + v.state = attr.ValueStateKnown + + return nil +} + +func (v *CloudProjectStoragesValue) MergeWith(other *CloudProjectStoragesValue) { + + if (v.CreatedAt.IsUnknown() || v.CreatedAt.IsNull()) && !other.CreatedAt.IsUnknown() { + v.CreatedAt = other.CreatedAt + } + + if (v.Encryption.IsUnknown() || v.Encryption.IsNull()) && !other.Encryption.IsUnknown() { + v.Encryption = other.Encryption + } + + if (v.Name.IsUnknown() || v.Name.IsNull()) && !other.Name.IsUnknown() { + v.Name = other.Name + } + + if (v.Objects.IsUnknown() || v.Objects.IsNull()) && !other.Objects.IsUnknown() { + v.Objects = other.Objects + } + + if (v.ObjectsCount.IsUnknown() || v.ObjectsCount.IsNull()) && !other.ObjectsCount.IsUnknown() { + v.ObjectsCount = other.ObjectsCount + } + + if (v.ObjectsSize.IsUnknown() || v.ObjectsSize.IsNull()) && !other.ObjectsSize.IsUnknown() { + v.ObjectsSize = other.ObjectsSize + } + + if (v.OwnerId.IsUnknown() || v.OwnerId.IsNull()) && !other.OwnerId.IsUnknown() { + v.OwnerId = other.OwnerId + } + + if (v.Region.IsUnknown() || v.Region.IsNull()) && !other.Region.IsUnknown() { + v.Region = other.Region + } + + if (v.Replication.IsUnknown() || v.Replication.IsNull()) && !other.Replication.IsUnknown() { + v.Replication = other.Replication + } + + if (v.Tags.IsUnknown() || v.Tags.IsNull()) && !other.Tags.IsUnknown() { + v.Tags = other.Tags + } + + if (v.Versioning.IsUnknown() || v.Versioning.IsNull()) && !other.Versioning.IsUnknown() { + v.Versioning = other.Versioning + } + + if (v.VirtualHost.IsUnknown() || v.VirtualHost.IsNull()) && !other.VirtualHost.IsUnknown() { + v.VirtualHost = other.VirtualHost + } + + if (v.state == attr.ValueStateUnknown || v.state == attr.ValueStateNull) && other.state != attr.ValueStateUnknown { + v.state = other.state + } +} + +func (v CloudProjectStoragesValue) Attributes() map[string]attr.Value { + return map[string]attr.Value{ + "createdAt": v.CreatedAt, + "encryption": v.Encryption, + "name": v.Name, + "objects": v.Objects, + "objectsCount": v.ObjectsCount, + "objectsSize": v.ObjectsSize, + "ownerId": v.OwnerId, + "region": v.Region, + "replication": v.Replication, + "tags": v.Tags, + "versioning": v.Versioning, + "virtualHost": v.VirtualHost, + } +} +func (v CloudProjectStoragesValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { + attrTypes := make(map[string]tftypes.Type, 12) + + var val tftypes.Value + var err error + + attrTypes["created_at"] = basetypes.StringType{}.TerraformType(ctx) + attrTypes["encryption"] = basetypes.ObjectType{ + AttrTypes: EncryptionValue{}.AttributeTypes(ctx), + }.TerraformType(ctx) + attrTypes["name"] = basetypes.StringType{}.TerraformType(ctx) + attrTypes["objects"] = basetypes.ListType{ + ElemType: ObjectsValue{}.Type(ctx), + }.TerraformType(ctx) + attrTypes["objects_count"] = basetypes.Int64Type{}.TerraformType(ctx) + attrTypes["objects_size"] = basetypes.Int64Type{}.TerraformType(ctx) + attrTypes["owner_id"] = basetypes.Int64Type{}.TerraformType(ctx) + attrTypes["region"] = basetypes.StringType{}.TerraformType(ctx) + attrTypes["replication"] = basetypes.ObjectType{ + AttrTypes: ReplicationValue{}.AttributeTypes(ctx), + }.TerraformType(ctx) + attrTypes["tags"] = basetypes.MapType{ + ElemType: types.StringType, + }.TerraformType(ctx) + attrTypes["versioning"] = basetypes.ObjectType{ + AttrTypes: VersioningValue{}.AttributeTypes(ctx), + }.TerraformType(ctx) + attrTypes["virtual_host"] = basetypes.StringType{}.TerraformType(ctx) + + objectType := tftypes.Object{AttributeTypes: attrTypes} + + switch v.state { + case attr.ValueStateKnown: + vals := make(map[string]tftypes.Value, 12) + + val, err = v.CreatedAt.ToTerraformValue(ctx) + + if err != nil { + return tftypes.NewValue(objectType, tftypes.UnknownValue), err + } + + vals["created_at"] = val + + val, err = v.Encryption.ToTerraformValue(ctx) + + if err != nil { + return tftypes.NewValue(objectType, tftypes.UnknownValue), err + } + + vals["encryption"] = val + + val, err = v.Name.ToTerraformValue(ctx) + + if err != nil { + return tftypes.NewValue(objectType, tftypes.UnknownValue), err + } + + vals["name"] = val + + val, err = v.Objects.ToTerraformValue(ctx) + + if err != nil { + return tftypes.NewValue(objectType, tftypes.UnknownValue), err + } + + vals["objects"] = val + + val, err = v.ObjectsCount.ToTerraformValue(ctx) + + if err != nil { + return tftypes.NewValue(objectType, tftypes.UnknownValue), err + } + + vals["objects_count"] = val + + val, err = v.ObjectsSize.ToTerraformValue(ctx) + + if err != nil { + return tftypes.NewValue(objectType, tftypes.UnknownValue), err + } + + vals["objects_size"] = val + + val, err = v.OwnerId.ToTerraformValue(ctx) + + if err != nil { + return tftypes.NewValue(objectType, tftypes.UnknownValue), err + } + + vals["owner_id"] = val + + val, err = v.Region.ToTerraformValue(ctx) + + if err != nil { + return tftypes.NewValue(objectType, tftypes.UnknownValue), err + } + + vals["region"] = val + + val, err = v.Replication.ToTerraformValue(ctx) + + if err != nil { + return tftypes.NewValue(objectType, tftypes.UnknownValue), err + } + + vals["replication"] = val + + val, err = v.Tags.ToTerraformValue(ctx) + + if err != nil { + return tftypes.NewValue(objectType, tftypes.UnknownValue), err + } + + vals["tags"] = val + + val, err = v.Versioning.ToTerraformValue(ctx) + + if err != nil { + return tftypes.NewValue(objectType, tftypes.UnknownValue), err + } + + vals["versioning"] = val + + val, err = v.VirtualHost.ToTerraformValue(ctx) + + if err != nil { + return tftypes.NewValue(objectType, tftypes.UnknownValue), err + } + + vals["virtual_host"] = 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 CloudProjectStoragesValue) IsNull() bool { + return v.state == attr.ValueStateNull +} + +func (v CloudProjectStoragesValue) IsUnknown() bool { + return v.state == attr.ValueStateUnknown +} + +func (v CloudProjectStoragesValue) String() string { + return "CloudProjectStoragesValue" +} + +func (v CloudProjectStoragesValue) ToObjectValue(ctx context.Context) (basetypes.ObjectValue, diag.Diagnostics) { + var diags diag.Diagnostics + + objVal, diags := types.ObjectValue( + map[string]attr.Type{ + "created_at": ovhtypes.TfStringType{}, + "encryption": EncryptionType{ + basetypes.ObjectType{ + AttrTypes: EncryptionValue{}.AttributeTypes(ctx), + }, + }, + "name": ovhtypes.TfStringType{}, + "objects": ovhtypes.NewTfListNestedType[ObjectsValue](ctx), + "objects_count": ovhtypes.TfInt64Type{}, + "objects_size": ovhtypes.TfInt64Type{}, + "owner_id": ovhtypes.TfInt64Type{}, + "region": ovhtypes.TfStringType{}, + "replication": ReplicationType{ + basetypes.ObjectType{ + AttrTypes: ReplicationValue{}.AttributeTypes(ctx), + }, + }, + "tags": ovhtypes.NewTfMapNestedType[ovhtypes.TfStringValue](ctx), + "versioning": VersioningType{ + basetypes.ObjectType{ + AttrTypes: VersioningValue{}.AttributeTypes(ctx), + }, + }, + "virtual_host": ovhtypes.TfStringType{}, + }, + map[string]attr.Value{ + "created_at": v.CreatedAt, + "encryption": v.Encryption, + "name": v.Name, + "objects": v.Objects, + "objects_count": v.ObjectsCount, + "objects_size": v.ObjectsSize, + "owner_id": v.OwnerId, + "region": v.Region, + "replication": v.Replication, + "tags": v.Tags, + "versioning": v.Versioning, + "virtual_host": v.VirtualHost, + }) + + return objVal, diags +} + +func (v CloudProjectStoragesValue) Equal(o attr.Value) bool { + other, ok := o.(CloudProjectStoragesValue) + + if !ok { + return false + } + + if v.state != other.state { + return false + } + + if v.state != attr.ValueStateKnown { + return true + } + + if !v.CreatedAt.Equal(other.CreatedAt) { + return false + } + + if !v.Encryption.Equal(other.Encryption) { + return false + } + + if !v.Name.Equal(other.Name) { + return false + } + + if !v.Objects.Equal(other.Objects) { + return false + } + + if !v.ObjectsCount.Equal(other.ObjectsCount) { + return false + } + + if !v.ObjectsSize.Equal(other.ObjectsSize) { + return false + } + + if !v.OwnerId.Equal(other.OwnerId) { + return false + } + + if !v.Region.Equal(other.Region) { + return false + } + + if !v.Replication.Equal(other.Replication) { + return false + } + + if !v.Tags.Equal(other.Tags) { + return false + } + + if !v.Versioning.Equal(other.Versioning) { + return false + } + + if !v.VirtualHost.Equal(other.VirtualHost) { + return false + } + + return true +} + +func (v CloudProjectStoragesValue) Type(ctx context.Context) attr.Type { + return CloudProjectStoragesType{ + basetypes.ObjectType{ + AttrTypes: v.AttributeTypes(ctx), + }, + } +} + +func (v CloudProjectStoragesValue) AttributeTypes(ctx context.Context) map[string]attr.Type { + return map[string]attr.Type{ + "created_at": ovhtypes.TfStringType{}, + "encryption": EncryptionValue{}.Type(ctx), + "name": ovhtypes.TfStringType{}, + "objects": ovhtypes.NewTfListNestedType[ObjectsValue](ctx), + "objects_count": ovhtypes.TfInt64Type{}, + "objects_size": ovhtypes.TfInt64Type{}, + "owner_id": ovhtypes.TfInt64Type{}, + "region": ovhtypes.TfStringType{}, + "replication": ReplicationValue{}.Type(ctx), + "tags": ovhtypes.NewTfMapNestedType[ovhtypes.TfStringValue](ctx), + "versioning": VersioningValue{}.Type(ctx), + "virtual_host": ovhtypes.TfStringType{}, + } +} diff --git a/ovh/provider_new.go b/ovh/provider_new.go index aa5ce7e28..bb73e4347 100644 --- a/ovh/provider_new.go +++ b/ovh/provider_new.go @@ -199,6 +199,8 @@ func (p *OvhProvider) DataSources(_ context.Context) []func() datasource.DataSou NewCloudProjectNetworkPrivateDataSource, NewCloudProjectNetworkPrivatesDataSource, NewCloudProjectNetworkPrivateSubnetsDataSource, + NewCloudProjectStorageDataSource, + NewCloudProjectStoragesDataSource, NewCloudProjectVolumesDataSource, NewCloudProjectVolumeDataSource, NewCloudProjectDataSource, diff --git a/website/docs/d/cloud_project_storage.html.markdown b/website/docs/d/cloud_project_storage.html.markdown new file mode 100644 index 000000000..fe9b6a8b0 --- /dev/null +++ b/website/docs/d/cloud_project_storage.html.markdown @@ -0,0 +1,114 @@ +--- +subcategory : "Object Storage" +--- + +# ovh_cloud_project_storage + +Get S3™* compatible storage container. +\* S3 is a trademark filed by Amazon Technologies,Inc. OVHcloud's service is not sponsored by, endorsed by, or otherwise affiliated with Amazon Technologies,Inc. + +## Example Usage + +```hcl +data "ovh_cloud_project_storage" "storage" { + service_name = "" + region_name = "GRA" + name = "my-storage-name" +} +``` + + +## Schema + +### Required + +- `name` (String) Name +- `region_name` (String) Region name +- `service_name` (String) Service name + +### Optional + +- `limit` (Number) Limit the number of objects returned (1000 maximum, defaults to 1000) +- `marker` (String) Key to start with when listing objects +- `prefix` (String) List objects whose key begins with this prefix + +### Read-Only + +- `created_at` (String) The date and timestamp when the resource was created +- `encryption` (Attributes) Encryption configuration (see [below for nested schema](#nestedatt--encryption)) +- `objects` (Attributes List) Container objects (see [below for nested schema](#nestedatt--objects)) +- `objects_count` (Number) Container total objects count +- `objects_size` (Number) Container total objects size (bytes) +- `owner_id` (Number) Container owner user ID +- `region` (String) Container region +- `replication` (Attributes) Replication configuration (see [below for nested schema](#nestedatt--replication)) +- `tags` (Map of String) Container tags +- `versioning` (Attributes) Versioning configuration (see [below for nested schema](#nestedatt--versioning)) +- `virtual_host` (String) Container virtual host + + +### Nested Schema for `encryption` + +Read-Only: + +- `sse_algorithm` (String) Encryption algorithm + + + +### Nested Schema for `objects` + +Read-Only: + +- `etag` (String) ETag +- `is_delete_marker` (Boolean) Whether this object is a delete marker +- `is_latest` (Boolean) Whether this is the latest version of the object +- `key` (String) Key +- `last_modified` (String) Last modification date +- `size` (Number) Size (bytes) +- `storage_class` (String) Storage class +- `version_id` (String) Version ID of the object + + + +### Nested Schema for `replication` + +Read-Only: + +- `rules` (Attributes List) Replication rules (see [below for nested schema](#nestedatt--replication--rules)) + + +### Nested Schema for `replication.rules` + +Read-Only: + +- `delete_marker_replication` (String) Delete marker replication +- `destination` (Attributes) Rule destination configuration (see [below for nested schema](#nestedatt--replication--rules--destination)) +- `filter` (Attributes) Rule filters (see [below for nested schema](#nestedatt--replication--rules--filter)) +- `id` (String) Rule ID +- `priority` (Number) Rule priority +- `status` (String) Rule status + + +### Nested Schema for `replication.rules.destination` + +Read-Only: + +- `name` (String) Destination bucket name +- `region` (String) Destination region, can be null if destination bucket has been deleted +- `storage_class` (String) Destination storage class + + + +### Nested Schema for `replication.rules.filter` + +Read-Only: + +- `prefix` (String) Prefix filter +- `tags` (Map of String) Tags filter + + +### Nested Schema for `versioning` + +Read-Only: + +- `status` (String) Versioning status diff --git a/website/docs/d/cloud_project_storages.html.markdown b/website/docs/d/cloud_project_storages.html.markdown new file mode 100644 index 000000000..4e2dc8b66 --- /dev/null +++ b/website/docs/d/cloud_project_storages.html.markdown @@ -0,0 +1,113 @@ +--- +subcategory : "Object Storage" +--- + +# ovh_cloud_project_storages + +List your S3™* compatible storage container. +\* S3 is a trademark filed by Amazon Technologies,Inc. OVHcloud's service is not sponsored by, endorsed by, or otherwise affiliated with Amazon Technologies,Inc. + +## Example Usage + +```hcl +data "ovh_cloud_project_storage" "storage" { + service_name = "" + region_name = "GRA" +} +``` + +## Schema + +### Required + +- `region_name` (String) Region name +- `service_name` (String) Service name + +### Read-Only + +- `containers` (Attributes Set) (see [below for nested schema](#nestedatt--containers)) + + +### Nested Schema for `containers` + +Read-Only: + +- `created_at` (String) The date and timestamp when the resource was created +- `encryption` (Attributes) Encryption configuration (see [below for nested schema](#nestedatt--containers--encryption)) +- `name` (String) Container name +- `objects` (Attributes List) Container objects (see [below for nested schema](#nestedatt--containers--objects)) +- `objects_count` (Number) Container total objects count +- `objects_size` (Number) Container total objects size (bytes) +- `owner_id` (Number) Container owner user ID +- `region` (String) Container region +- `replication` (Attributes) Replication configuration (see [below for nested schema](#nestedatt--containers--replication)) +- `tags` (Map of String) Container tags +- `versioning` (Attributes) Versioning configuration (see [below for nested schema](#nestedatt--containers--versioning)) +- `virtual_host` (String) Container virtual host + + +### Nested Schema for `containers.encryption` + +Read-Only: + +- `sse_algorithm` (String) Encryption algorithm + + + +### Nested Schema for `containers.objects` + +Read-Only: + +- `etag` (String) ETag +- `is_delete_marker` (Boolean) Whether this object is a delete marker +- `is_latest` (Boolean) Whether this is the latest version of the object +- `key` (String) Key +- `last_modified` (String) Last modification date +- `size` (Number) Size (bytes) +- `storage_class` (String) Storage class +- `version_id` (String) Version ID of the object + + + +### Nested Schema for `containers.replication` + +Read-Only: + +- `rules` (Attributes List) Replication rules (see [below for nested schema](#nestedatt--containers--replication--rules)) + + +### Nested Schema for `containers.replication.rules` + +Read-Only: + +- `delete_marker_replication` (String) Delete marker replication +- `destination` (Attributes) Rule destination configuration (see [below for nested schema](#nestedatt--containers--replication--rules--destination)) +- `filter` (Attributes) Rule filters (see [below for nested schema](#nestedatt--containers--replication--rules--filter)) +- `id` (String) Rule ID +- `priority` (Number) Rule priority +- `status` (String) Rule status + + +### Nested Schema for `containers.replication.rules.destination` + +Read-Only: + +- `name` (String) Destination bucket name +- `region` (String) Destination region, can be null if destination bucket has been deleted +- `storage_class` (String) Destination storage class + + + +### Nested Schema for `containers.replication.rules.filter` + +Read-Only: + +- `prefix` (String) Prefix filter +- `tags` (Map of String) Tags filter + + +### Nested Schema for `containers.versioning` + +Read-Only: + +- `status` (String) Versioning status