Skip to content

Commit ea679dd

Browse files
authored
feat: added support to the module to attach access tags using new input access_tags (#404)
1 parent 4d397d3 commit ea679dd

File tree

11 files changed

+71
-0
lines changed

11 files changed

+71
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ To create service credentials, access the Event Notifications service, and acces
8888
| [ibm_iam_authorization_policy.kms_policy](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
8989
| [ibm_resource_instance.en_instance](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/resource_instance) | resource |
9090
| [ibm_resource_key.service_credentials](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/resource_key) | resource |
91+
| [ibm_resource_tag.en_tag](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/resource_tag) | resource |
9192
| [time_sleep.wait_for_cos_authorization_policy](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
9293
| [time_sleep.wait_for_kms_authorization_policy](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
9394
| [ibm_en_integrations.en_integrations](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/en_integrations) | data source |
@@ -96,6 +97,7 @@ To create service credentials, access the Event Notifications service, and acces
9697

9798
| Name | Description | Type | Default | Required |
9899
|------|-------------|------|---------|:--------:|
100+
| <a name="input_access_tags"></a> [access\_tags](#input\_access\_tags) | A list of access tags to apply to the Event Notifications instance created by the module. For more information, see https://cloud.ibm.com/docs/account?topic=account-access-tags-tutorial. | `list(string)` | `[]` | no |
99101
| <a name="input_cbr_rules"></a> [cbr\_rules](#input\_cbr\_rules) | The list of context-based restrictions rules to create. | <pre>list(object({<br/> description = string<br/> account_id = string<br/> rule_contexts = list(object({<br/> attributes = optional(list(object({<br/> name = string<br/> value = string<br/> }))) }))<br/> enforcement_mode = string<br/> operations = optional(list(object({<br/> api_types = list(object({<br/> api_type_id = string<br/> }))<br/> })))<br/> }))</pre> | `[]` | no |
100102
| <a name="input_cos_bucket_name"></a> [cos\_bucket\_name](#input\_cos\_bucket\_name) | The name of an existing IBM Cloud Object Storage bucket which will be used for storage of failed delivery events. Required if `cos_integration_enabled` is set to true. | `string` | `null` | no |
101103
| <a name="input_cos_endpoint"></a> [cos\_endpoint](#input\_cos\_endpoint) | The endpoint URL for your bucket region. For more information, see https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-endpoints. Required if `cos_integration_enabled` is set to true. | `string` | `null` | no |

examples/complete/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ module "event_notification" {
6868
root_key_id = module.key_protect_all_inclusive.keys["${local.key_ring_name}.${local.key_name}"].key_id
6969
kms_endpoint_url = module.key_protect_all_inclusive.kms_public_endpoint
7070
tags = var.resource_tags
71+
access_tags = var.access_tags
7172
service_endpoints = "public"
7273
service_credential_names = var.service_credential_names
7374
region = var.region

examples/complete/variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ variable "resource_tags" {
2626
default = []
2727
}
2828

29+
variable "access_tags" {
30+
type = list(string)
31+
description = "A list of access tags to apply to the Event Notifications instance created by the module. For more information, see https://cloud.ibm.com/docs/account?topic=account-access-tags-tutorial."
32+
default = []
33+
34+
validation {
35+
condition = alltrue([
36+
for tag in var.access_tags : can(regex("[\\w\\-_\\.]+:[\\w\\-_\\.]+", tag)) && length(tag) <= 128
37+
])
38+
error_message = "Tags must match the regular expression \"[\\w\\-_\\.]+:[\\w\\-_\\.]+\", see https://cloud.ibm.com/docs/account?topic=account-tag&interface=ui#limits for more details"
39+
}
40+
}
41+
2942
variable "region" {
3043
type = string
3144
description = "IBM Cloud region where event notification will be created, supported regions are: us-south (Dallas), eu-gb (London), eu-de (Frankfurt), au-syd (Sydney), eu-es (Madrid)"

examples/fscloud/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ module "event_notification" {
109109
root_key_id = local.root_key_id
110110
kms_endpoint_url = var.kms_endpoint_url
111111
tags = var.resource_tags
112+
access_tags = var.access_tags
112113

113114
# Map of name, role for service credentials that you want to create for the event notification
114115
service_credential_names = {

examples/fscloud/variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ variable "resource_tags" {
2525
default = []
2626
}
2727

28+
variable "access_tags" {
29+
type = list(string)
30+
description = "A list of access tags to apply to the Event Notifications instance created by the module. For more information, see https://cloud.ibm.com/docs/account?topic=account-access-tags-tutorial."
31+
default = []
32+
33+
validation {
34+
condition = alltrue([
35+
for tag in var.access_tags : can(regex("[\\w\\-_\\.]+:[\\w\\-_\\.]+", tag)) && length(tag) <= 128
36+
])
37+
error_message = "Tags must match the regular expression \"[\\w\\-_\\.]+:[\\w\\-_\\.]+\", see https://cloud.ibm.com/docs/account?topic=account-tag&interface=ui#limits for more details"
38+
}
39+
}
40+
2841
variable "region" {
2942
type = string
3043
description = "Region to provision all resources created by this example, Event Notifications supported regions are: us-south (Dallas), eu-gb (London), eu-de (Frankfurt), au-syd (Sydney), eu-es (Madrid)"

main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ resource "ibm_resource_instance" "en_instance" {
3737
}
3838
}
3939

40+
##############################################################################
41+
# Attach Access Tags
42+
##############################################################################
43+
44+
resource "ibm_resource_tag" "en_tag" {
45+
count = length(var.access_tags) == 0 ? 0 : 1
46+
resource_id = ibm_resource_instance.en_instance.crn
47+
tags = var.access_tags
48+
tag_type = "access"
49+
}
50+
4051
#############################################################################
4152
# Event Notification COS integration to Collect Failed Events
4253
#############################################################################

modules/fscloud/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ No resources.
8080

8181
| Name | Description | Type | Default | Required |
8282
|------|-------------|------|---------|:--------:|
83+
| <a name="input_access_tags"></a> [access\_tags](#input\_access\_tags) | A list of access tags to apply to the Event Notifications instance created by the module. For more information, see https://cloud.ibm.com/docs/account?topic=account-access-tags-tutorial. | `list(string)` | `[]` | no |
8384
| <a name="input_cbr_rules"></a> [cbr\_rules](#input\_cbr\_rules) | The list of context-based restrictions rules to create. | <pre>list(object({<br/> description = string<br/> account_id = string<br/> rule_contexts = list(object({<br/> attributes = optional(list(object({<br/> name = string<br/> value = string<br/> }))) }))<br/> enforcement_mode = string<br/> operations = optional(list(object({<br/> api_types = list(object({<br/> api_type_id = string<br/> }))<br/> })))<br/> }))</pre> | `[]` | no |
8485
| <a name="input_cos_bucket_name"></a> [cos\_bucket\_name](#input\_cos\_bucket\_name) | The name of an existing Object Storage bucket to use for the storage of failed delivery events. | `string` | `null` | no |
8586
| <a name="input_cos_endpoint"></a> [cos\_endpoint](#input\_cos\_endpoint) | The endpoint URL for your bucket region. Required if `cos_integration_enabled` is set to `true`. [Learn more](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-endpoints). | `string` | `null` | no |

modules/fscloud/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ module "event_notification" {
1919
cos_bucket_name = var.cos_bucket_name
2020
cos_instance_id = var.cos_instance_id
2121
skip_en_cos_auth_policy = var.skip_en_cos_auth_policy
22+
access_tags = var.access_tags
2223
}

modules/fscloud/variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ variable "tags" {
1818
default = []
1919
}
2020

21+
variable "access_tags" {
22+
type = list(string)
23+
description = "A list of access tags to apply to the Event Notifications instance created by the module. For more information, see https://cloud.ibm.com/docs/account?topic=account-access-tags-tutorial."
24+
default = []
25+
26+
validation {
27+
condition = alltrue([
28+
for tag in var.access_tags : can(regex("[\\w\\-_\\.]+:[\\w\\-_\\.]+", tag)) && length(tag) <= 128
29+
])
30+
error_message = "Tags must match the regular expression \"[\\w\\-_\\.]+:[\\w\\-_\\.]+\", see https://cloud.ibm.com/docs/account?topic=account-tag&interface=ui#limits for more details"
31+
}
32+
}
33+
2134
variable "region" {
2235
type = string
2336
description = "The IBM Cloud region where the Event Notifications resource is created. Possible values: `us-south` (Dallas), `eu-gb` (London), `eu-de` (Frankfurt), `au-syd` (Sydney), `eu-es` (Madrid)"

tests/pr_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func TestCompleteExampleInSchematics(t *testing.T) {
9494
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
9595
{Name: "prefix", Value: options.Prefix, DataType: "string"},
9696
{Name: "region", Value: region, DataType: "string"},
97+
{Name: "access_tags", Value: permanentResources["accessTags"], DataType: "list"},
9798
}
9899

99100
err := options.RunSchematicTest()
@@ -192,6 +193,7 @@ func TestFSCloudInSchematics(t *testing.T) {
192193
{Name: "existing_kms_instance_crn", Value: permanentResources["hpcs_south_crn"], DataType: "string"},
193194
{Name: "kms_endpoint_url", Value: permanentResources["hpcs_south_private_endpoint"], DataType: "string"},
194195
{Name: "root_key_crn", Value: permanentResources["hpcs_south_root_key_crn"], DataType: "string"},
196+
{Name: "access_tags", Value: permanentResources["accessTags"], DataType: "list"},
195197
}
196198

197199
err := options.RunSchematicTest()

0 commit comments

Comments
 (0)