type: user

role: user

content:
You are implementing Task C2 of the "DD Agent Logs via Vector" plan.

## Task Description

Two related edits in the consumer's datadog_agent.tf:
1. Bump the `module.datadog_agent` source ref from `v1.1.2` to `v1.2.0`.
2. Add the `logs_intake_url` argument to the module call, wiring through the new flag.

**File to modify:** `/Users/steve.briggs/projects/IAC/terraform/iac-library/aws/compute/eks-cluster-applications/datadog_agent.tf`

### Edit 1: Bump source ref

Line 14 currently reads:
```hcl
  source = "git@gitlab.infrastructure.immuta.io:infrastructure/terraform/internal-modules/kubernetes/monitoring/datadog-agent?ref=v1.1.2"
```

Change to:
```hcl
  source = "git@gitlab.infrastructure.immuta.io:infrastructure/terraform/internal-modules/kubernetes/monitoring/datadog-agent?ref=v1.2.0"
```

### Edit 2: Add `logs_intake_url` argument to the module call

The current `module "datadog_agent"` block (lines 13-34) ends with:
```hcl
  tags                           = var.tags
  env                            = var.env
}
```

Add a new argument after `env` (preserving a blank line for separation):

```hcl
  tags                           = var.tags
  env                            = var.env

  logs_intake_url = local.vector_dd_agent_logs_enabled ? module.vector[0].service_endpoint_dd_agent : null
}
```

The ternary is correct: when `local.vector_dd_agent_logs_enabled = false`, the right-hand side evaluates to `null` without dereferencing `module.vector[0]`. This safely handles the case where Vector isn't deployed (count=0).

## Verification

```
cd /Users/steve.briggs/projects/IAC/terraform/iac-library/aws/compute/eks-cluster-applications
terraform fmt datadog_agent.tf
```

Expected: no output (or it auto-formats).

## Context

This is the final wire-up that activates the OPW routing path: when `local.vector_dd_agent_logs_enabled` is true, the module receives the URL from the Vector module's new `service_endpoint_dd_agent` output, which renders the OPW env vars in the helm chart. When false, `logs_intake_url = null` and the rendered values are byte-identical to today.

## CRITICAL — No git operations

Do NOT run any git commands. Sir Charles handles git himself.

## Your Job

1. Read datadog_agent.tf to confirm current state.
2. Make Edit 1 (bump version).
3. Make Edit 2 (add logs_intake_url argument).
4. Run `terraform fmt datadog_agent.tf`.
5. Self-review.
6. Report back.

## Report Format

- **Status:** DONE | DONE_WITH_CONCERNS | BLOCKED | NEEDS_CONTEXT
- File modified
- terraform fmt output
- The exact module "datadog_agent" block as it appears after both edits (paste full block from `module "datadog_agent" {` through `}`)
- Any concerns

userType: external

entrypoint: cli

gitBranch: master


type: message

role: assistant

type: text

text: I'll help you implement Task C2. Let me start by reading the current state of the datadog_agent.tf file.

service_tier: standard

attributionAgent: general-purpose

attributionPlugin: superpowers

type: assistant


Read

type: direct


content:
1	# ---------------------------------------------------------------------------------------------------------------------
2	# METRICS SERVER
3	# ---------------------------------------------------------------------------------------------------------------------
4	locals {
5	  datadog_agent_enabled = (
6	    var.datadog_agent_enabled != null
7	    ? var.datadog_agent_enabled
8	    : lookup(var.datadog_agent_enabled_cluster_types, local.cluster_type, true)
9	  )
10	}
11
12	# Datadog Agent
13	module "datadog_agent" {
14	  source = "git@gitlab.infrastructure.immuta.io:infrastructure/terraform/internal-modules/kubernetes/monitoring/datadog-agent?ref=v1.1.2"
15	  count  = local.datadog_agent_enabled ? 1 : 0
16
17	  providers = {
18	    kubernetes = kubernetes.local-cluster
19	    helm       = helm.local-cluster
20	  }
21
22	  chart_version                  = var.datadog_agent_version
23	  image_tag                      = var.datadog_agent_image_tag
24	  create_namespace               = var.datadog_create_namespace
25	  cluster_name                   = var.cluster_name
26	  global_segment                 = var.global_segment
27	  datadog_tags                   = var.datadog_tags
28	  enable_nowrds_monitoring       = var.datadog_enable_nowrds_monitoring
29	  enable_now_obfusicator_options = var.datadog_enable_now_obfusicator_options
30	  enable_mrds_monitoring         = var.datadog_enable_mrds_monitoring
31	  now_obfusicator_options        = var.datadog_now_obfusicator_options
32	  tags                           = var.tags
33	  env                            = var.env
34	}
35
36	# ---------------------------------------------------------------------------------------------------------------------
37	# REQUIRED PARAMETERS
38	# These variables must be set.
39	# ---------------------------------------------------------------------------------------------------------------------
40	variable "datadog_agent_version" {
41	  description = "Version of otel-collector helm chart"
42	  type        = string
43	  default     = ""
44	  validation {
45	    condition     = var.datadog_agent_version == "" && local.datadog_agent_enabled ? false : true
46	    error_message = "datadog_agent_version must be set when datadog_agent is enabled"
47	  }
48	}
49
50	variable "datadog_agent_image_tag" {
51	  description = "Version of otel-collector image tag"
52	  type        = string
53	  default     = ""
54	  validation {
55	    condition     = var.datadog_agent_image_tag == "" && local.datadog_agent_enabled ? false : true
56	    error_message = "datadog_agent_image_tag must be set when datadog_agent is enabled"
57	  }
58	}
59
60	# ---------------------------------------------------------------------------------------------------------------------
61	# OPTIONAL PARAMETERS
62	# These variables are configurable, but have reasonable defaults set.
63	# ---------------------------------------------------------------------------------------------------------------------
64	variable "datadog_agent_enabled_cluster_types" {
65	  description = "Types of clusters datadog_agent should be enabled on by default"
66	  type        = map(string)
67	  default = {
68	    "mgmt"  = true
69	    "cps"   = true
70	    "saas"  = true
71	    "infra" = false
72	    "dev"   = false
73	  }
74	}
75
76	variable "datadog_tags" {
77	  description = "Map of tags to apply to datadog metrics"
78	  type        = list(string)
79	  default     = []
80	}
81
82	variable "datadog_enable_nowrds_monitoring" {
83	  description = "Enable monitoring for NOWRDS."
84	  type        = bool
85	  default     = false
86	}
87
88	variable "datadog_enable_mrds_monitoring" {
89	  description = "Enable multitenant RDS monitoring"
90	  type        = bool
91	  default     = false
92	}
93
94	variable "datadog_enable_now_obfusicator_options" {
95	  description = "Whether to enable the NOWRDS obfuscator options in the Datadog agent configuration."
96	  type        = bool
97	  default     = false
98	}
99
100	variable "datadog_now_obfusicator_options" {
101	  description = "A map of options to configure the NOWRDS obfuscator in the Datadog agent configuration."
102	  type        = map(string)
103	  default = {
104	    replace_digits = "true"
105	  }
106	}
107
108	variable "datadog_create_namespace" {
109	  type    = bool
110	  default = false
111	}
112
113	variable "datadog_agent_enabled" {
114	  description = "Override for explicitly enabling or disabling otel-collector"
115	  type        = bool
116	  default     = null
117	}
118
119	# ---------------------------------------------------------------------------------------------------------------------
120	# DD AGENT → VECTOR LOGS ROUTING (OPW)
121	# ---------------------------------------------------------------------------------------------------------------------
122	locals {
123	  vector_dd_agent_logs_enabled = (
124	    var.vector_dd_agent_logs_enabled != null
125	    ? var.vector_dd_agent_logs_enabled
126	    : local.vector_enabled
127	  )
128	}
129
130	variable "vector_dd_agent_logs_enabled" {
131	  description = "Override for routing DD Agent logs through Vector. When null (default), inherits from local.vector_enabled (i.e., on wherever Vector is on). Set to false to keep DD Agent shipping logs directly to DD SaaS even when Vector is deployed."
132	  type        = bool
133	  default     = null
134	}
135
136	# Plan-time guard: vector_dd_agent_logs_enabled cannot be true if vector itself is off.
137	# Mirrors the existing data "external" "vector_validate" pattern in vector.tf.
138	data "external" "vector_dd_agent_logs_validate" {
139	  count = local.vector_dd_agent_logs_enabled && !local.vector_enabled ? 1 : 0
140
141	  program = ["Error: vector_dd_agent_logs_enabled requires vector_enabled"]
142	}
143


text:
Perfect. I can see the file and the current state. Now I'll make the two edits:

1. **Edit 1**: Bump the version from v1.1.2 to v1.2.0 on line 14
2. **Edit 2**: Add the `logs_intake_url` argument after `env` (after line 33)


speed: standard


content: The file /Users/steve.briggs/projects/IAC/terraform/iac-library/aws/compute/eks-cluster-applications/datadog_agent.tf has been updated successfully. (file state is current in your context — no need to Read it back)


text: Now for Edit 2, I'll add the `logs_intake_url` argument after the `env` line:


Edit

old_string:
  tags                           = var.tags
  env                            = var.env
}

new_string:
  tags                           = var.tags
  env                            = var.env

  logs_intake_url = local.vector_dd_agent_logs_enabled ? module.vector[0].service_endpoint_dd_agent : null
}


text: Now let me run terraform fmt to verify the formatting:


Bash

command: terraform fmt datadog_agent.tf && echo "Format check: OK (no changes needed)"


content: Format check: OK (no changes needed)


text: Excellent! Now let me read back the modified section to confirm both edits are correct:


content:
12	# Datadog Agent
13	module "datadog_agent" {
14	  source = "git@gitlab.infrastructure.immuta.io:infrastructure/terraform/internal-modules/kubernetes/monitoring/datadog-agent?ref=v1.2.0"
15	  count  = local.datadog_agent_enabled ? 1 : 0
16
17	  providers = {
18	    kubernetes = kubernetes.local-cluster
19	    helm       = helm.local-cluster
20	  }
21
22	  chart_version                  = var.datadog_agent_version
23	  image_tag                      = var.datadog_agent_image_tag
24	  create_namespace               = var.datadog_create_namespace
25	  cluster_name                   = var.cluster_name
26	  global_segment                 = var.global_segment
27	  datadog_tags                   = var.datadog_tags
28	  enable_nowrds_monitoring       = var.datadog_enable_nowrds_monitoring
29	  enable_now_obfusicator_options = var.datadog_enable_now_obfusicator_options
30	  enable_mrds_monitoring         = var.datadog_enable_mrds_monitoring
31	  now_obfusicator_options        = var.datadog_now_obfusicator_options
32	  tags                           = var.tags
33	  env                            = var.env
34
35	  logs_intake_url = local.vector_dd_agent_logs_enabled ? module.vector[0].service_endpoint_dd_agent : null
36	}


text:
Perfect! Both edits are complete and properly formatted.

## Report

**Status:** DONE

**File Modified:** `/Users/steve.briggs/projects/IAC/terraform/iac-library/aws/compute/eks-cluster-applications/datadog_agent.tf`

**terraform fmt output:** No output (file was already properly formatted)

**Complete module "datadog_agent" block after edits:**

```hcl
module "datadog_agent" {
  source = "git@gitlab.infrastructure.immuta.io:infrastructure/terraform/internal-modules/kubernetes/monitoring/datadog-agent?ref=v1.2.0"
  count  = local.datadog_agent_enabled ? 1 : 0

  providers = {
    kubernetes = kubernetes.local-cluster
    helm       = helm.local-cluster
  }

  chart_version                  = var.datadog_agent_version
  image_tag                      = var.datadog_agent_image_tag
  create_namespace               = var.datadog_create_namespace
  cluster_name                   = var.cluster_name
  global_segment                 = var.global_segment
  datadog_tags                   = var.datadog_tags
  enable_nowrds_monitoring       = var.datadog_enable_nowrds_monitoring
  enable_now_obfusicator_options = var.datadog_enable_now_obfusicator_options
  enable_mrds_monitoring         = var.datadog_enable_mrds_monitoring
  now_obfusicator_options        = var.datadog_now_obfusicator_options
  tags                           = var.tags
  env                            = var.env

  logs_intake_url = local.vector_dd_agent_logs_enabled ? module.vector[0].service_endpoint_dd_agent : null
}
```

**Concerns:** None. Both edits complete successfully:
- ✓ Version bumped from v1.1.2 to v1.2.0 (line 14)
- ✓ `logs_intake_url` argument added with correct ternary logic (line 35)
- ✓ Blank line preserved between `env` and `logs_intake_url` for readability
- ✓ Formatting validated with terraform fmt

Task C2 is ready for Sir Charles to commit.