type: user

role: user

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

## Task Description

Add the `vector_dd_agent_logs_enabled` flag (variable + local + plan-time guard) to the consumer's `datadog_agent.tf`.

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

The current file ends with the `variable "datadog_agent_enabled"` block at around line 117 (full file is 118 lines). At the bottom of the file, append:

```hcl

# ---------------------------------------------------------------------------------------------------------------------
# DD AGENT → VECTOR LOGS ROUTING (OPW)
# ---------------------------------------------------------------------------------------------------------------------
locals {
  vector_dd_agent_logs_enabled = (
    var.vector_dd_agent_logs_enabled != null
    ? var.vector_dd_agent_logs_enabled
    : local.vector_enabled
  )
}

variable "vector_dd_agent_logs_enabled" {
  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."
  type        = bool
  default     = null
}

# Plan-time guard: vector_dd_agent_logs_enabled cannot be true if vector itself is off.
# Mirrors the existing data "external" "vector_validate" pattern in vector.tf.
data "external" "vector_dd_agent_logs_validate" {
  count = local.vector_dd_agent_logs_enabled && !local.vector_enabled ? 1 : 0

  program = ["Error: vector_dd_agent_logs_enabled requires vector_enabled"]
}
```

(Leading blank line to separate from the previous block.)

The `local.vector_enabled` reference is defined in `vector.tf` (already exists in the consumer); this new block can reference it because all `.tf` files in the same directory share locals.

## Verification

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

Expected: no output, exit 0.

## Context

This implements the consumer-side flag for the OPW routing feature. The variable defaults to null; when null, the local inherits from `local.vector_enabled` (so the routing is on wherever Vector is on). When the variable is set explicitly to true/false, it overrides. The guard prevents the user from enabling DD-Agent-logs routing without Vector being deployed first (which would cause connection refused at runtime).

## CRITICAL — No git operations

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

## Your Job

1. Read the current `datadog_agent.tf` to confirm the existing structure.
2. Append the new block at the end.
3. Run `terraform fmt datadog_agent.tf`.
4. Self-review.
5. Report back.

## Report Format

- **Status:** DONE | DONE_WITH_CONCERNS | BLOCKED | NEEDS_CONTEXT
- File modified
- terraform fmt output
- The exact added block as it appears in the file (paste the whole block)
- Any concerns

userType: external

entrypoint: cli

gitBranch: master


type: message

role: assistant

type: text

text: I'll help you implement Task C1. 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

speed: standard


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


text: Good. The file currently ends at line 118 with the `variable "datadog_agent_enabled"` block. Now I'll append the new block as specified in the task.


Edit

old_string:
variable "datadog_agent_enabled" {
  description = "Override for explicitly enabling or disabling otel-collector"
  type        = bool
  default     = null
}

new_string:
variable "datadog_agent_enabled" {
  description = "Override for explicitly enabling or disabling otel-collector"
  type        = bool
  default     = null
}

# ---------------------------------------------------------------------------------------------------------------------
# DD AGENT → VECTOR LOGS ROUTING (OPW)
# ---------------------------------------------------------------------------------------------------------------------
locals {
  vector_dd_agent_logs_enabled = (
    var.vector_dd_agent_logs_enabled != null
    ? var.vector_dd_agent_logs_enabled
    : local.vector_enabled
  )
}

variable "vector_dd_agent_logs_enabled" {
  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."
  type        = bool
  default     = null
}

# Plan-time guard: vector_dd_agent_logs_enabled cannot be true if vector itself is off.
# Mirrors the existing data "external" "vector_validate" pattern in vector.tf.
data "external" "vector_dd_agent_logs_validate" {
  count = local.vector_dd_agent_logs_enabled && !local.vector_enabled ? 1 : 0

  program = ["Error: vector_dd_agent_logs_enabled requires vector_enabled"]
}


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 I'll run terraform fmt to verify the formatting is correct.


Bash

command: terraform fmt datadog_agent.tf && echo "Format check passed"


content: Format check passed


text: Let me verify the final state of the file by reading the appended section.


content:
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. Here's the report:

---

**Status:** DONE

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

**terraform fmt output:**
```
Format check passed (exit code 0, no output)
```

**Exact added block (lines 119-142):**
```hcl
# ---------------------------------------------------------------------------------------------------------------------
# DD AGENT → VECTOR LOGS ROUTING (OPW)
# ---------------------------------------------------------------------------------------------------------------------
locals {
  vector_dd_agent_logs_enabled = (
    var.vector_dd_agent_logs_enabled != null
    ? var.vector_dd_agent_logs_enabled
    : local.vector_enabled
  )
}

variable "vector_dd_agent_logs_enabled" {
  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."
  type        = bool
  default     = null
}

# Plan-time guard: vector_dd_agent_logs_enabled cannot be true if vector itself is off.
# Mirrors the existing data "external" "vector_validate" pattern in vector.tf.
data "external" "vector_dd_agent_logs_validate" {
  count = local.vector_dd_agent_logs_enabled && !local.vector_enabled ? 1 : 0

  program = ["Error: vector_dd_agent_logs_enabled requires vector_enabled"]
}
```

**Concerns:** None. The block was appended correctly with proper spacing, the local correctly references `local.vector_enabled` (which exists in vector.tf), the variable defaults to null as expected, and the validation guard correctly prevents the impossible state. All formatting is correct and consistent with the existing file style.