Skip to content

Commit 6eace4e

Browse files
authored
feat: new bool variable logdna_add_cluster_name can be used to add the cluster name as a logdna tag + fixed issue where sysdig was using cluster ID instead of name (#99)
1 parent b3d7980 commit 6eace4e

File tree

6 files changed

+28
-12
lines changed

6 files changed

+28
-12
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ No modules.
124124
|------|-------------|------|---------|:--------:|
125125
| <a name="input_cluster_id"></a> [cluster\_id](#input\_cluster\_id) | Cluster id to add to agents to | `string` | n/a | yes |
126126
| <a name="input_cluster_resource_group_id"></a> [cluster\_resource\_group\_id](#input\_cluster\_resource\_group\_id) | Resource group of the cluster | `string` | n/a | yes |
127+
| <a name="input_logdna_add_cluster_name"></a> [logdna\_add\_cluster\_name](#input\_logdna\_add\_cluster\_name) | Add cluster name to the list of tags | `bool` | `true` | no |
127128
| <a name="input_logdna_agent_tags"></a> [logdna\_agent\_tags](#input\_logdna\_agent\_tags) | array of tags to group the host logs pushed by the logdna agent | `list(string)` | `[]` | no |
128129
| <a name="input_logdna_agent_version"></a> [logdna\_agent\_version](#input\_logdna\_agent\_version) | Version of the agent to deploy. To lookup version run: `ibmcloud cr images --restrict ext/logdna-agent`. If null, the default value is used. | `string` | `"3.8.0-20230206.cbc937fa5513f636"` | no |
129130
| <a name="input_logdna_enabled"></a> [logdna\_enabled](#input\_logdna\_enabled) | Deploy IBM Cloud Logging agent | `bool` | `true` | no |

examples/basic/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,5 @@ module "observability_agents" {
105105
sysdig_instance_name = module.observability_instances.sysdig_name
106106
sysdig_access_key = module.observability_instances.sysdig_access_key
107107
logdna_agent_tags = var.logdna_agent_tags
108+
logdna_add_cluster_name = true
108109
}

main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ data "ibm_resource_instance" "sysdig_instance" {
4343

4444
locals {
4545
logdna_secret_name = "logdna-agent" #checkov:skip=CKV_SECRET_6
46-
cluster_name = data.ibm_container_vpc_cluster.cluster.name
46+
cluster_name = data.ibm_container_vpc_cluster.cluster.resource_name
4747
logdna_chart_location = "${path.module}/chart/logdna-agent"
4848
logdna_resource_group_id = var.logdna_resource_group_id != null ? var.logdna_resource_group_id : var.cluster_resource_group_id
4949
logdna_agent_namespace = "ibm-observe"
5050
logdna_agent_registry = "icr.io/ext/logdna-agent"
5151
logdna_key_validate_condition = var.logdna_enabled == true && var.logdna_ingestion_key == null
5252
logdna_key_validate_msg = "Values for 'logdna_ingestion_key' variables must be passed when 'logdna_enabled = true'"
53+
logdna_agent_tags = var.logdna_add_cluster_name ? join("\\,", concat(var.logdna_agent_tags, formatlist(local.cluster_name))) : join("\\,", var.logdna_agent_tags)
5354
# tflint-ignore: terraform_unused_declarations
5455
logdna_key_validate_check = regex("^${local.logdna_key_validate_msg}$", (!local.logdna_key_validate_condition ? local.logdna_key_validate_msg : ""))
5556
sysdig_chart_location = "${path.module}/chart/sysdig-agent"
@@ -103,7 +104,7 @@ resource "helm_release" "logdna_agent" {
103104
set {
104105
name = "agent.tags"
105106
type = "string"
106-
value = join("\\,", var.logdna_agent_tags)
107+
value = local.logdna_agent_tags
107108
}
108109

109110
provisioner "local-exec" {

module-metadata.json

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@
3535
"cloud_data_type": "resource_group",
3636
"computed": true
3737
},
38+
"logdna_add_cluster_name": {
39+
"name": "logdna_add_cluster_name",
40+
"type": "bool",
41+
"description": "Add cluster name to the list of tags",
42+
"default": true,
43+
"pos": {
44+
"filename": "variables.tf",
45+
"line": 55
46+
}
47+
},
3848
"logdna_agent_tags": {
3949
"name": "logdna_agent_tags",
4050
"type": "list(string)",
@@ -114,7 +124,7 @@
114124
],
115125
"pos": {
116126
"filename": "variables.tf",
117-
"line": 81
127+
"line": 87
118128
}
119129
},
120130
"sysdig_agent_version": {
@@ -124,7 +134,7 @@
124134
"default": "12.10.1",
125135
"pos": {
126136
"filename": "variables.tf",
127-
"line": 73
137+
"line": 79
128138
}
129139
},
130140
"sysdig_enabled": {
@@ -138,7 +148,7 @@
138148
],
139149
"pos": {
140150
"filename": "variables.tf",
141-
"line": 55
151+
"line": 61
142152
}
143153
},
144154
"sysdig_instance_name": {
@@ -151,7 +161,7 @@
151161
],
152162
"pos": {
153163
"filename": "variables.tf",
154-
"line": 61
164+
"line": 67
155165
}
156166
},
157167
"sysdig_resource_group_id": {
@@ -160,7 +170,7 @@
160170
"description": "Resource group that the IBM Cloud Monitoring is in. Defaults to Clusters group",
161171
"pos": {
162172
"filename": "variables.tf",
163-
"line": 67
173+
"line": 73
164174
}
165175
}
166176
},
@@ -195,7 +205,7 @@
195205
},
196206
"pos": {
197207
"filename": "main.tf",
198-
"line": 67
208+
"line": 68
199209
}
200210
},
201211
"helm_release.sysdig_agent": {
@@ -210,7 +220,7 @@
210220
},
211221
"pos": {
212222
"filename": "main.tf",
213-
"line": 121
223+
"line": 122
214224
}
215225
}
216226
},

tests/pr_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ func TestRunBasicAgents(t *testing.T) {
6363
func TestRunUpgrade(t *testing.T) {
6464
t.Parallel()
6565

66-
// TODO: Remove this line after the first merge to primary branch is complete to enable upgrade test
67-
t.Skip("Skipping upgrade test until initial code is in primary branch")
68-
6966
options := setupOptions(t, "observ-agents-upg", terraformDirOther)
7067

7168
output, err := options.RunTestUpgrade()

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ variable "logdna_ingestion_key" {
5252
default = null
5353
}
5454

55+
variable "logdna_add_cluster_name" {
56+
type = bool
57+
description = "Add cluster name to the list of tags"
58+
default = true
59+
}
60+
5561
variable "sysdig_enabled" {
5662
type = bool
5763
description = "Deploy IBM Cloud Monitoring agent"

0 commit comments

Comments
 (0)