Skip to content

Commit

Permalink
Added COS quota support
Browse files Browse the repository at this point in the history
updated based on comment

Revert "Added COS quota support"

This reverts commit e119f2973fea78f7ec498ccfd6ee69c9418c6055.

Added COS quota support

updated based on comment

updated docs
  • Loading branch information
testpod-source-p authored and hkantare committed Jun 23, 2021
1 parent 27606be commit 6d20c3e
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 1 deletion.
3 changes: 3 additions & 0 deletions examples/ibm-cos-bucket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ resource "ibm_cos_bucket" "retention_cos" {
region_location = "jp-tok"
storage_class = standard
force_delete = true
hard_quota = 11
retention_rule {
default = 1
maximum = 1
Expand All @@ -116,6 +117,7 @@ resource "ibm_cos_bucket" "objectversioning" {
resource_instance_id = ibm_resource_instance.cos_instance.id
region_location = "us-east"
storage_class = var.storage
hard_quota = 1024
object_versioning {
enable = true
}
Expand Down Expand Up @@ -181,3 +183,4 @@ data "ibm_cos_bucket" "standard-ams03" {
| minimum | Specifies minimum duration of time an object must be kept unmodified in the bucket. | `int` | yes
| permanent | Specifies a permanent retention status either enable or disable for a bucket. | `bool` | no
| enable | Specifies Versioning status either enable or Suspended for the objects in the bucket. | `bool` | no
| hard_quota | sets a maximum amount of storage (in bytes) available for a bucket. | `int` | no
3 changes: 3 additions & 0 deletions examples/ibm-cos-bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ resource "ibm_cos_bucket" "standard-ams03" {
resource_instance_id = ibm_resource_instance.cos_instance.id
single_site_location = var.single_site_loc
storage_class = var.storage
hard_quota = var.quota
activity_tracking {
read_data_events = true
write_data_events = true
Expand All @@ -48,6 +49,7 @@ resource "ibm_cos_bucket" "lifecycle_rule_cos" {
resource_instance_id = ibm_resource_instance.cos_instance.id
region_location = var.regional_loc
storage_class = var.storage
hard_quota = var.quota
archive_rule {
rule_id = var.archive_ruleid
enable = true
Expand All @@ -73,6 +75,7 @@ resource "ibm_cos_bucket" "cos_bucket" {
resource_instance_id = ibm_resource_instance.cos_instance.id
region_location = var.regional_loc
storage_class = var.storage
hard_quota = var.quota
object_versioning {
enable = true
}
Expand Down
4 changes: 4 additions & 0 deletions examples/ibm-cos-bucket/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ variable "minimum_retention" {

variable "maximum_retention" {
default = "1"
}

variable "quota" {
default = "1"
}
8 changes: 8 additions & 0 deletions ibm/data_source_ibm_cos_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ func dataSourceIBMCosBucket() *schema.Resource {
},
},
},
"hard_quota": {
Type: schema.TypeInt,
Computed: true,
Description: "sets a maximum amount of storage (in bytes) available for a bucket",
},
},
}
}
Expand Down Expand Up @@ -367,6 +372,9 @@ func dataSourceIBMCosBucketRead(d *schema.ResourceData, meta interface{}) error
if bucketPtr.MetricsMonitoring != nil {
d.Set("metrics_monitoring", flattenMetricsMonitor(bucketPtr.MetricsMonitoring))
}
if bucketPtr.HardQuota != nil {
d.Set("hard_quota", bucketPtr.HardQuota)
}

}

Expand Down
13 changes: 13 additions & 0 deletions ibm/resource_ibm_cos_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ func resourceIBMCOSBucket() *schema.Resource {
},
},
},
"hard_quota": {
Type: schema.TypeInt,
Optional: true,
Description: "sets a maximum amount of storage (in bytes) available for a bucket",
},
"force_delete": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -596,6 +601,11 @@ func resourceIBMCOSBucketUpdate(d *schema.ResourceData, meta interface{}) error
bucketName = d.Get("bucket_name").(string)
updateBucketConfigOptions.Bucket = &bucketName

if d.HasChange("hard_quota") {
hasChanged = true
updateBucketConfigOptions.HardQuota = aws.Int64(int64(d.Get("hard_quota").(int)))
}

if d.HasChange("allowed_ip") {
firewall := &resourceconfigurationv1.Firewall{}
var ips = make([]string, 0)
Expand Down Expand Up @@ -799,6 +809,9 @@ func resourceIBMCOSBucketRead(d *schema.ResourceData, meta interface{}) error {
if bucketPtr.MetricsMonitoring != nil {
d.Set("metrics_monitoring", flattenMetricsMonitor(bucketPtr.MetricsMonitoring))
}
if bucketPtr.HardQuota != nil {
d.Set("hard_quota", bucketPtr.HardQuota)
}
}
// Read the lifecycle configuration (archive & expiration)

Expand Down
52 changes: 52 additions & 0 deletions ibm/resource_ibm_cos_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,34 @@ func TestAccIBMCosBucket_Object_Versioning(t *testing.T) {
})
}

func TestAccIBMCosBucket_Hard_Quota(t *testing.T) {

cosServiceName := fmt.Sprintf("cos_instance_%d", acctest.RandIntRange(10, 100))
bucketName := fmt.Sprintf("terraform%d", acctest.RandIntRange(10, 100))
bucketRegion := "us-south"
bucketClass := "standard"
bucketRegionType := "region_location"
hardQuota := 1024

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckIBMCosBucketDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckIBMCosBucket_hard_quota(cosServiceName, bucketName, bucketRegionType, bucketRegion, bucketClass, hardQuota),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckIBMCosBucketExists("ibm_resource_instance.instance", "ibm_cos_bucket.bucket", bucketRegionType, bucketRegion, bucketName),
resource.TestCheckResourceAttr("ibm_cos_bucket.bucket", "bucket_name", bucketName),
resource.TestCheckResourceAttr("ibm_cos_bucket.bucket", "storage_class", bucketClass),
resource.TestCheckResourceAttr("ibm_cos_bucket.bucket", "region_location", bucketRegion),
resource.TestCheckResourceAttr("ibm_cos_bucket.bucket", "hard_quota", fmt.Sprintf("%d", hardQuota)),
),
},
},
})
}

func TestAccIBMCosBucket_Smart_Type(t *testing.T) {
serviceName := fmt.Sprintf("terraform_%d", acctest.RandIntRange(10, 100))
bucketName := fmt.Sprintf("terraform%d", acctest.RandIntRange(10, 100))
Expand Down Expand Up @@ -961,3 +989,27 @@ func testAccCheckIBMCosBucket_object_versioning(cosServiceName string, bucketNam
}
`, cosServiceName, bucketName, region, storageClass)
}

func testAccCheckIBMCosBucket_hard_quota(cosServiceName string, bucketName string, regiontype string, region string, storageClass string, hardQuota int) string {

return fmt.Sprintf(`
data "ibm_resource_group" "cos_group" {
name = "Default"
}
resource "ibm_resource_instance" "instance" {
name = "%s"
service = "cloud-object-storage"
plan = "standard"
location = "global"
resource_group_id = data.ibm_resource_group.cos_group.id
}
resource "ibm_cos_bucket" "bucket" {
bucket_name = "%s"
resource_instance_id = ibm_resource_instance.instance.id
region_location = "%s"
storage_class = "%s"
hard_quota = %d
}
`, cosServiceName, bucketName, region, storageClass, hardQuota)
}
1 change: 1 addition & 0 deletions website/docs/d/cos_bucket.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,6 @@ In addition to all argument reference list, you can access the following attribu
- `maximum` - (String) Specifies maximum duration of time an object can be kept unmodified in the bucket.
- `minimum` - (String) Specifies minimum duration of time an object must be kept unmodified in the bucket.
- `permanent` - (String) Specifies a permanent retention status either enable or disable for a bucket.
- `hard_quota` - (String) Maximum bytes for the bucket.
- `single_site_location` - (String) The location to create a single site bucket.
- `storage_class` - (String) The storage class of the bucket.
5 changes: 4 additions & 1 deletion website/docs/r/cos_bucket.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ resource "ibm_cos_bucket" "retention_cos" {
resource_instance_id = ibm_resource_instance.cos_instance.id
region_location = "jp-tok"
storage_class = standard
hard_quota = 1024
force_delete = true
retention_rule {
default = 1
Expand All @@ -181,6 +182,7 @@ resource "ibm_cos_bucket" "objectversioning" {
resource_instance_id = ibm_resource_instance.cos_instance.id
region_location = "us-east"
storage_class = var.storage
hard_quota = 11
object_versioning {
enable = true
}
Expand Down Expand Up @@ -223,7 +225,7 @@ Review the argument references that you can specify for your resource.
Both `archive_rule` and `expire_rule` must be managed by Terraform as they use the same lifecycle configuration. If user creates any of the rule outside of Terraform by using command line or console, you can see unexpected difference like removal of any of the rule or one rule overrides another. The policy cannot match as expected due to API limitations, as the lifecycle is a single API request for both archive and expire.
- `force_delete`- (Optional, Bool) As the default value set to **true**, it will delete all the objects in the COS Bucket and then delete the bucket. **Note:** `force_delete` will timeout on buckets with a large amount of objects. 24 hours before you delete the bucket you can set an expire rule to remove all the files over a day old. * **Note** Both `archive_rule` and `expire_rule` must be managed by Terraform as they use the same lifecycle configuration. If user creates any of the rule outside of Terraform by using command line, or console, you can see unexpected difference such as removal of any of the rule, or one rule overrides another, the policy may not match as expected due to API limitation because the lifecycle is a single API request for both archive and expire.
- `key_protect` - (Optional, String) The CRN of the IBM Key Protect root key that you want to use to encrypt data that is sent and stored in IBM Cloud Object Storage. Before you can enable IBM Key Protect encryption, you must provision an instance of IBM Key Protect and authorize the service to access IBM Cloud Object Storage. For more information, see [Server-Side Encryption with IBM Key Protect or Hyper Protect Crypto Services (SSE-KP)](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-encryption).
- `metrics_monitoring_crn` - (Required, string) Required the first time `metrics_monitoring` is configured. The instance of IBM Cloud Monitoring receives the bucket metrics. **Note** Request metrics are supported in all regions and console has the support. For more details check the [cloud documentiona](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-mm-cos-integration) **Note** One of the location option must be present.
- `metrics_monitoring_crn` - (Required, string) Required the first time `metrics_monitoring` is configured. The instance of IBM Cloud Monitoring receives the bucket metrics. **Note** Request metrics are supported in all regions and console has the support. For more details check the [cloud documention](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-mm-cos-integration) **Note** One of the location option must be present.
- `metrics_monitoring`- (Object) to enable metrics tracking with IBM Cloud Monitoring - Optional- Set up your IBM Cloud Monitoring service instance to receive metrics for your IBM Cloud Object Storage bucket.

Nested scheme for `metrics_monitoring`:
Expand Down Expand Up @@ -259,6 +261,7 @@ Both `archive_rule` and `expire_rule` must be managed by Terraform as they use
- The minimum retention period must be less than or equal to the default retention period, that in turn must be less than or equal to the maximum retention period.
- Permanent retention can only be enabled at a IBM Cloud Object Storage bucket level with retention policy enabled and users are able to select the permanent retention period option during object uploads. Once enabled, this process can't be reversed and objects uploaded that use a permanent retention period cannot be deleted. It's the responsibility of the users to validate at their end if there's a legitimate need to permanently store objects by using Object Storage buckets with a retention policy.
- force deleting the bucket will not work if any object is still under retention. As objects cannot be deleted or overwritten until the retention period has expired and all the legal holds have been removed.
- `hard_quota` - (Optional, Integer) sets a maximum amount of storage (in bytes) available for a bucket. For more details check the [cloud documention](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-quota)
- `single_site_location` - (Optional, String) The location for a single site bucket. Supported values are: `ams03`, `che01`, `hkg02`, `mel01`, `mex01`, `mil01`, `mon01`, `osl01`, `par01`, `sjc04`, `sao01`, `seo01`, `sng01`, and `tor01`. If you set this parameter, do not set `region_location` or `cross_region_location` at the same time.
- `storage_class` - (Required, String) The storage class that you want to use for the bucket. Supported values are `standard`, `vault`, `cold`, `flex`, and `smart`. For more information, about storage classes, see [Use storage classes](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-classes).

Expand Down

0 comments on commit 6d20c3e

Please sign in to comment.