Skip to content

Commit

Permalink
added support for cos sysdig v2(request metrics)
Browse files Browse the repository at this point in the history
update docs

updated based on comment
  • Loading branch information
testpod-source-p authored and hkantare committed Apr 27, 2021
1 parent 8a366fa commit f47bf16
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 60 deletions.
17 changes: 14 additions & 3 deletions examples/ibm-cos-bucket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,26 @@ resource "ibm_resource_instance" "metrics_monitor" {
name = "metrics_monitor"
resource_group_id = data.ibm_resource_group.cos_group.id
service = "sysdig-monitor"
plan = "lite"
plan = "graduated-tier"
location = "us-south"
parameters = {
default_receiver = true
}
}
resource "ibm_cos_bucket" "standard-ams03" {
bucket_name = var.bucket_name
resource_instance_id = ibm_resource_instance.cos_instance.id
cross_region_location = var.region
single_site_location = "sjc04"
#cross_region_location = var.region
storage_class = var.storage
activity_tracking {
activity_tracking {
read_data_events = true
write_data_events = true
activity_tracker_crn = ibm_resource_instance.activity_tracker.id
}
metrics_monitoring {
usage_metrics_enabled = true
request_metrics_enabled = true
metrics_monitoring_crn = ibm_resource_instance.metrics_monitor.id
}
allowed_ip = ["223.196.168.27","223.196.161.38","192.168.0.1"]
Expand Down Expand Up @@ -114,6 +119,12 @@ data "ibm_cos_bucket" "standard-ams03" {
| resource\_group\_name | Name of the resource group. | `string` | yes |
| storage | The storage class that you want to use for the bucket. Supported values are standard, vault, cold, flex, and smart.| `string` | no |
| region | The location for a cross-regional bucket. Supported values are us, eu, and ap. | `string` | no |
| read_data_events | Enables sending log data to Activity Tracker and LogDNA to provide visibility into object read and write events.. | `array` | no
| write_data_events | all object write events (i.e. uploads) will be sent to Activity Tracker. | `bool` | no
| activity_tracker_crn | Required the first time activity_tracking is configured. | `string` | yes
| usage_metrics_enabled | Specify true or false to set usage metrics (i.e. bytes_used). | `bool` | no
| request_metrics_enabled | Specify true or false to set cos request metrics (i.e. get,put,post request). | `bool` | no
| metrics_monitoring_crn | Required the first time metrics_monitoring is configured. The instance of IBM Cloud Monitoring that will receive the bucket metrics. | `string` | yes
| archive_ruleid | Unique identifier for the rule. | `string` | no
| regional_loc | The location for a regional bucket. Supported values are au-syd, eu-de, eu-gb, jp-tok,,us-east,us-south. | `string` | no
| archive_days | Specifies the number of days when the specific archive rule action takes effect. | `int` | yes
Expand Down
8 changes: 6 additions & 2 deletions examples/ibm-cos-bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ resource "ibm_resource_instance" "metrics_monitor" {
name = "metrics_monitor"
resource_group_id = data.ibm_resource_group.cos_group.id
service = "sysdig-monitor"
plan = "lite"
plan = "graduated-tier"
location = "us-south"
parameters = {
default_receiver = true
}
}
resource "ibm_cos_bucket" "standard-ams03" {
bucket_name = var.bucket_name
resource_instance_id = ibm_resource_instance.cos_instance.id
cross_region_location = var.region
single_site_location = var.single_site_loc
storage_class = var.storage
activity_tracking {
read_data_events = true
Expand All @@ -34,6 +37,7 @@ resource "ibm_cos_bucket" "standard-ams03" {
}
metrics_monitoring {
usage_metrics_enabled = true
request_metrics_enabled = true
metrics_monitoring_crn = ibm_resource_instance.metrics_monitor.id
}
allowed_ip = ["223.196.168.27", "223.196.161.38", "192.168.0.1"]
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 @@ -14,6 +14,10 @@ variable "region" {
default = "us"
}

variable "single_site_loc" {
default = "sjc04"
}

variable "archive_ruleid" {
default = ""
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ require (
github.com/IBM/go-sdk-core/v3 v3.3.1
github.com/IBM/go-sdk-core/v4 v4.10.0
github.com/IBM/go-sdk-core/v5 v5.3.0
github.com/IBM/ibm-cos-sdk-go v1.3.1
github.com/IBM/ibm-cos-sdk-go-config v1.0.1
github.com/IBM/ibm-cos-sdk-go v1.6.1
github.com/IBM/ibm-cos-sdk-go-config v1.1.0
github.com/IBM/keyprotect-go-client v0.7.0
github.com/IBM/networking-go-sdk v0.13.0
github.com/IBM/platform-services-go-sdk v0.18.7
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,12 @@ github.com/IBM/go-sdk-core/v5 v5.3.0 h1:ZDqawFURQ1nlNhy4SE9Q+0AOlpa/TrsbVC7TnoSi
github.com/IBM/go-sdk-core/v5 v5.3.0/go.mod h1:+MNa5Jbqb9FO7KEevo982Pb/YXr4adkyEffJlPs2TGc=
github.com/IBM/ibm-cos-sdk-go v1.3.1 h1:6SHueqFpznp7S/9b39/WiJ9mt3TgD322j2pArzyd/c8=
github.com/IBM/ibm-cos-sdk-go v1.3.1/go.mod h1:YLBAYobEA8bD27P7xpMwSQeNQu6W3DNBtBComXrRzRY=
github.com/IBM/ibm-cos-sdk-go v1.6.1 h1:2XG/fsXno8228gBEwxf0u2AFI/Nii3wpk17lkpF0IvA=
github.com/IBM/ibm-cos-sdk-go v1.6.1/go.mod h1:BOqDAOxuJTamCSdAKx2XStknDaeB99nXWaf1PtvW0iY=
github.com/IBM/ibm-cos-sdk-go-config v1.0.1 h1:Nld42UysaZ16hPl4XMnkCgbuwW+s4OVctqEf2QbE5ec=
github.com/IBM/ibm-cos-sdk-go-config v1.0.1/go.mod h1:BAbdv1Zf8mRP6rj40Cem7KgBp+UQn9Fe2EWxIBrp5sM=
github.com/IBM/ibm-cos-sdk-go-config v1.1.0 h1:udFHLvw1o1mtLdX3t1hTaPSdLAUPnkc2qCngNhubR1o=
github.com/IBM/ibm-cos-sdk-go-config v1.1.0/go.mod h1:BAbdv1Zf8mRP6rj40Cem7KgBp+UQn9Fe2EWxIBrp5sM=
github.com/IBM/keyprotect-go-client v0.7.0 h1:JstSHD14Lp6ihwQseyPuGcs1AjOBjAmcisP0dTBA6A0=
github.com/IBM/keyprotect-go-client v0.7.0/go.mod h1:SVr2ylV/fhSQPDiUjWirN9fsyWFCNNbt8GIT8hPJVjE=
github.com/IBM/networking-go-sdk v0.12.1 h1:GmzrRjvAyqKMfUPM8Y/R5dce0x5AXTqmseVZ3n7eZks=
Expand Down Expand Up @@ -1010,6 +1014,8 @@ golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb h1:eBmm0M9fYhWpKZLjQUUKka/Lt
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew=
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down
5 changes: 5 additions & 0 deletions ibm/data_source_ibm_cos_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ func dataSourceIBMCosBucket() *schema.Resource {
Computed: true,
Description: "Usage metrics will be sent to the monitoring service.",
},
"request_metrics_enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "Request metrics will be sent to the monitoring service.",
},
"metrics_monitoring_crn": {
Type: schema.TypeString,
Computed: true,
Expand Down
12 changes: 11 additions & 1 deletion ibm/resource_ibm_cos_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ func resourceIBMCOS() *schema.Resource {
Default: false,
Description: "Usage metrics will be sent to the monitoring service.",
},
"request_metrics_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Request metrics will be sent to the monitoring service.",
},
"metrics_monitoring_crn": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -596,7 +602,11 @@ func resourceIBMCOSUpdate(d *schema.ResourceData, meta interface{}) error {
metrics := metricsSet.(bool)
metricsMonitor.UsageMetricsEnabled = &metrics
}

// request metrics enabled - as its optional check for existence
if metricsSet := metricsMap["request_metrics_enabled"]; metricsSet != nil {
metrics := metricsSet.(bool)
metricsMonitor.RequestMetricsEnabled = &metrics
}
//crn - Required field
crn := metricsMap["metrics_monitoring_crn"].(string)
metricsMonitor.MetricsMonitoringCrn = &crn
Expand Down
25 changes: 16 additions & 9 deletions ibm/resource_ibm_cos_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ func TestAccIBMCosBucket_ActivityTracker_Monitor(t *testing.T) {
activityServiceName := fmt.Sprintf("activity_tracker_%d", acctest.RandIntRange(10, 100))
monitorServiceName := fmt.Sprintf("metrics_monitor_%d", acctest.RandIntRange(10, 100))
bucketName := fmt.Sprintf("tf-bucket%d", acctest.RandIntRange(10, 100))
bucketRegion := "us"
bucketRegion := "sjc04"
bucketClass := "standard"
bucketRegionType := "cross_region_location"
bucketRegionType := "single_site_location"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -75,7 +75,7 @@ func TestAccIBMCosBucket_ActivityTracker_Monitor(t *testing.T) {
testAccCheckIBMCosBucketExists("ibm_resource_instance.instance2", "ibm_cos_bucket.bucket2", bucketRegionType, bucketRegion, bucketName),
resource.TestCheckResourceAttr("ibm_cos_bucket.bucket2", "bucket_name", bucketName),
resource.TestCheckResourceAttr("ibm_cos_bucket.bucket2", "storage_class", bucketClass),
resource.TestCheckResourceAttr("ibm_cos_bucket.bucket2", "cross_region_location", bucketRegion),
resource.TestCheckResourceAttr("ibm_cos_bucket.bucket2", "single_site_location", bucketRegion),
resource.TestCheckResourceAttr("ibm_cos_bucket.bucket2", "activity_tracking.#", "1"),
resource.TestCheckResourceAttr("ibm_cos_bucket.bucket2", "metrics_monitoring.#", "1"),
),
Expand All @@ -86,7 +86,7 @@ func TestAccIBMCosBucket_ActivityTracker_Monitor(t *testing.T) {
testAccCheckIBMCosBucketExists("ibm_resource_instance.instance2", "ibm_cos_bucket.bucket2", bucketRegionType, bucketRegion, bucketName),
resource.TestCheckResourceAttr("ibm_cos_bucket.bucket2", "bucket_name", bucketName),
resource.TestCheckResourceAttr("ibm_cos_bucket.bucket2", "storage_class", bucketClass),
resource.TestCheckResourceAttr("ibm_cos_bucket.bucket2", "cross_region_location", bucketRegion),
resource.TestCheckResourceAttr("ibm_cos_bucket.bucket2", "single_site_location", bucketRegion),
resource.TestCheckResourceAttr("ibm_cos_bucket.bucket2", "activity_tracking.#", "0"),
resource.TestCheckResourceAttr("ibm_cos_bucket.bucket2", "metrics_monitoring.#", "0"),
),
Expand Down Expand Up @@ -542,7 +542,7 @@ func testAccCheckIBMCosBucket_activityTracker_monitor(cosServiceName, activitySe
name = "%s"
resource_group_id = data.ibm_resource_group.cos_group.id
service = "logdnaat"
plan = "7-day "
plan = "7-day"
location = "us-south"
}
resource "ibm_resource_instance" "metrics_monitor2" {
Expand All @@ -551,11 +551,14 @@ func testAccCheckIBMCosBucket_activityTracker_monitor(cosServiceName, activitySe
service = "sysdig-monitor"
plan = "graduated-tier"
location = "us-south"
parameters = {
default_receiver = true
}
}
resource "ibm_cos_bucket" "bucket2" {
bucket_name = "%s"
resource_instance_id = ibm_resource_instance.instance2.id
cross_region_location = "%s"
single_site_location = "%s"
storage_class = "%s"
activity_tracking {
read_data_events = true
Expand All @@ -564,6 +567,7 @@ func testAccCheckIBMCosBucket_activityTracker_monitor(cosServiceName, activitySe
}
metrics_monitoring {
usage_metrics_enabled = true
request_metrics_enabled = true
metrics_monitoring_crn = ibm_resource_instance.metrics_monitor2.id
}
}
Expand All @@ -589,21 +593,24 @@ func testAccCheckIBMCosBucket_update_activityTracker_monitor(cosServiceName, act
name = "%s"
resource_group_id = data.ibm_resource_group.cos_group.id
service = "logdnaat"
plan = "standard"
plan = "7-day"
location = "us-south"
}
resource "ibm_resource_instance" "metrics_monitor2" {
name = "%s"
resource_group_id = data.ibm_resource_group.cos_group.id
service = "sysdig-monitor"
plan = "standard"
plan = "graduated-tier"
location = "us-south"
parameters = {
default_receiver = true
}
}
resource "ibm_cos_bucket" "bucket2" {
bucket_name = "%s"
resource_instance_id = ibm_resource_instance.instance2.id
cross_region_location = "%s"
single_site_location = "%s"
storage_class = "%s"
}
`, cosServiceName, activityServiceName, monitorServiceName, bucketName, region, storageClass)
Expand Down
3 changes: 3 additions & 0 deletions ibm/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,9 @@ func flattenMetricsMonitor(in *resourceconfigurationv1.MetricsMonitoring) []inte
if in.MetricsMonitoringCrn != nil {
att["metrics_monitoring_crn"] = *in.MetricsMonitoringCrn
}
if in.RequestMetricsEnabled != nil {
att["request_metrics_enabled"] = *in.RequestMetricsEnabled
}
}
return []interface{}{att}
}
Expand Down
37 changes: 19 additions & 18 deletions website/docs/d/cos_bucket.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: |-

# ibm\_cos_bucket

Get information about already existing buckets.
Creates an IBM Cloud Object Storage bucket. It also allows object storage buckets to be updated and deleted. The ibmcloud_api_key used by Terraform must have been granted sufficient IAM rights to create and modify IBM Cloud Object Storage buckets and have access to the Resource Group the Cloud Object Storage bucket will be associated with. See https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-iam for more details on setting IAM and Access Group rights to manage COS buckets.

## Example Usage

Expand Down Expand Up @@ -61,25 +61,26 @@ In addition to all arguments above, the following attributes are exported:
* `storage_class` - Storage class of the bucket.
* `allowed_ip` - List of IPv4 or IPv6 addresses in CIDR notation to be affected by firewall.
* Nested `activity_tracking` block have the following structure:
* `activity_tracking.read_data_events` : (Optional, array) Enables sending log data to Activity Tracker and LogDNA to provide visibility into object read and write events.
* `activity_tracking.write_data_events` : (Optional,bool) If set to true, all object write events (i.e. uploads) will be sent to Activity Tracker.
* `activity_tracking.activity_tracker_crn` : (Required, string) Required the first time activity_tracking is configured.
* `read_data_events` : (Optional, array) Enables sending log data to Activity Tracker and LogDNA to provide visibility into object read and write events.
* `write_data_events` : (Optional,bool) If set to true, all object write events (i.e. uploads) will be sent to Activity Tracker.
* `activity_tracker_crn` : (Required, string) Required the first time activity_tracking is configured.
* Nested `metrics_monitoring` block have the following structure:
* `metrics_monitoring.usage_metrics_enabled` : (Optional,bool) If set to true, all usage metrics (i.e. bytes_used) will be sent to the monitoring service.
* `metrics_monitoring.metrics_monitoring_crn` : (Required, string) Required the first time metrics_monitoring is configured. The instance of IBM Cloud Monitoring that will receive the bucket metrics.
* `usage_metrics_enabled` : (Optional,bool) If set to true, all usage metrics (i.e. bytes_used) will be sent to the monitoring service.
* `request_metrics_enabled` : (Optional,bool) If set to true, all request metrics (i.e. ibm_cos_bucket_all_request) will be sent to the monitoring service @1mins granulatiy.
* `metrics_monitoring_crn` : (Required, string) Required the first time metrics_monitoring is configured. The instance of IBM Cloud Monitoring that will receive the bucket metrics.
* Nested `archive_rule` block have the following structure:
* `archive_rule.rule_id` : (Optional, Computed, string) Unique identifier for the rule. Archive rules allow you to set a specific time frame after which objects transition to the archive.
* `archive_rule.enable` :* (Required, bool) (Required) Specifies archive rule status either enable or disable for a bucket.
* `archive_rule.days` :* (Required, string) Specifies the number of days when the specific rule action takes effect.
* `archive_rule.type` :* (Required, string) Specifies the storage class/archive type to which you want the object to transition. It can be Glacier or Accelerated.
* `rule_id` : (Optional, Computed, string) Unique identifier for the rule. Archive rules allow you to set a specific time frame after which objects transition to the archive.
* `enable` :* (Required, bool) (Required) Specifies archive rule status either enable or disable for a bucket.
* `days` :* (Required, string) Specifies the number of days when the specific rule action takes effect.
* `type` :* (Required, string) Specifies the storage class/archive type to which you want the object to transition. It can be Glacier or Accelerated.
* Nested `expire_rule` block have the following structure:
* `expire_rule.rule_id` : (Optional, Computed, string) Unique identifier for the rule. Expire rules allow you to set a specific time frame after which objects are deleted.
* `expire_rule.enable` :* (Required, bool) (Required) Specifies expire rule status either enable or disable for a bucket.
* `expire_rule.days` :* (Required, string) Specifies the number of days when the specific rule action takes effect.
* `expire_rule.prefix` :* (Optional, string) Specifies a prefix filter to apply to only a subset of objects with names that match the prefix.
* `rule_id` : (Optional, Computed, string) Unique identifier for the rule. Expire rules allow you to set a specific time frame after which objects are deleted.
* `enable` :* (Required, bool) (Required) Specifies expire rule status either enable or disable for a bucket.
* `days` :* (Required, string) Specifies the number of days when the specific rule action takes effect.
* `prefix` :* (Optional, string) Specifies a prefix filter to apply to only a subset of objects with names that match the prefix.

* Nested `retention_rule` block have the following structure:
* `retention_rule.default` : (Required, int) default retention period are defined by this policy and apply to all objects in the bucket.
* `retention_rule.maximum` : (Required, int) Specifies maximum duration of time an object can be kept unmodified in the bucket.
* `retention_rule.minimum` : (Required, int) Specifies minimum duration of time an object must be kept unmodified in the bucket.
* `retention_rule.permanent` : (Optional, bool) Specifies a permanent retention status either enable or disable for a bucket.
* `default` : (Required, int) default retention period are defined by this policy and apply to all objects in the bucket.
* `maximum` : (Required, int) Specifies maximum duration of time an object can be kept unmodified in the bucket.
* `minimum` : (Required, int) Specifies minimum duration of time an object must be kept unmodified in the bucket.
* `permanent` : (Optional, bool) Specifies a permanent retention status either enable or disable for a bucket.
Loading

0 comments on commit f47bf16

Please sign in to comment.