Skip to content

feat(o11y): add o11y terraform module for VM - #5341

Open
hassaansaleem28 wants to merge 15 commits into
OWASP:feature/o11yfrom
hassaansaleem28:feat/o11y-vm-infra
Open

feat(o11y): add o11y terraform module for VM #5341
hassaansaleem28 wants to merge 15 commits into
OWASP:feature/o11yfrom
hassaansaleem28:feat/o11y-vm-infra

Conversation

@hassaansaleem28

@hassaansaleem28 hassaansaleem28 commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Proposed change

Resolves #5327

Add terraform module for observability.

  • Runs VM on ECS Fargate with an EFS-backed, KMS-encrypted /data volume so metrics survive task restarts
  • Runs non-root through an EFS access point, on-demand Fargate only, single task
  • Registered in live/ behind enable_observability -- terraform plan shows no changes until turned on
  • VM image single-sourced from docker/victoriametrics/Dockerfile so dependabot tracks it and local/prod stay in sync
  • Native terraform test suite -- 16 unit tests (mocked) + an integration test applied against LocalStack

Checklist

  • Required: I followed the contributing workflow
  • Required: I verified that my code works as intended and resolves the issue as described
  • Required: I ran all required checks and tests locally; all warnings addressed and failures resolved
  • I used AI for code, documentation, tests, or communication related to this PR

Signed-off-by: hassaansaleem28 <iamhassaans@gmail.com>
@hassaansaleem28 hassaansaleem28 changed the title add o11y terraform module feat(o11y): add o11y terraform module for VM Jul 31, 2026
@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Summary by CodeRabbit

  • New Features
    • Added an optional VictoriaMetrics observability stack for collecting and retaining application metrics.
    • Added encrypted persistent storage, centralized logging, health monitoring, and secure application connectivity.
    • Added configuration options for enabling observability, container image, resource sizing, retention, networking, and log settings.
    • Added outputs for metrics storage, cluster, and security group details.
  • Documentation
    • Documented observability setup, configuration options, and available outputs.
  • Tests
    • Added validation for encryption, networking, deployment, logging, and runtime configuration.

Walkthrough

Adds an optional VictoriaMetrics module for ECS Fargate. The module provisions encrypted EFS storage, security groups, CloudWatch logging, IAM permissions, an ARM64 task definition, and a single ECS service. Live infrastructure supplies configuration and exposes selected resource identifiers.

Changes

VictoriaMetrics observability

Layer / File(s) Summary
Observability module contract
infrastructure/modules/observability/variables.tf, infrastructure/modules/observability/main.tf, infrastructure/live/variables.tf, infrastructure/live/README.md, infrastructure/modules/observability/README.md
Defines module inputs, Terraform requirements, container settings, retention, health checks, outputs, and the pinned VictoriaMetrics image.
Storage and network security
infrastructure/modules/observability/main.tf
Creates security groups, encrypted EFS storage with mount targets, and an encrypted CloudWatch log group.
ECS runtime and permissions
infrastructure/modules/observability/main.tf
Creates ECS execution permissions, an ARM64 Fargate task definition, an encrypted EFS volume mount, and a single-task service.
Infrastructure validation
infrastructure/modules/observability/tests/unit.tftest.hcl
Validates storage encryption, network rules, deployment settings, ARM64 execution, EFS transit encryption, logging, cluster naming, and common tags.
Live deployment integration
infrastructure/live/main.tf, infrastructure/modules/observability/outputs.tf
Conditionally deploys the module with live networking and shared settings, and outputs the EFS ID, cluster name, and security group ID.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Suggested reviewers: kasya, arkid15r

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes satisfy issue #5327 by adding the module, running VM on ECS Fargate, and using EFS for persistent storage.
Out of Scope Changes check ✅ Passed The module, live integration, documentation, variables, outputs, and tests directly support the linked issue objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly identifies the addition of an observability Terraform module for VictoriaMetrics.
Description check ✅ Passed The description accurately explains the observability module, ECS Fargate deployment, persistent EFS storage, enablement flag, and tests.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

4 similar comments
@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@infrastructure/live/main.tf`:
- Around line 253-271: The observability toggle currently owns retained EFS
storage through the conditional observability module, allowing Terraform to
delete it when disabled. In infrastructure/live/main.tf lines 253-271, keep the
module toggle limited to ECS runtime resources and move EFS ownership into
persistent storage configuration; in
infrastructure/modules/observability/main.tf lines 117-123, stop declaring or
managing the retained metrics EFS there, and add an explicit decommission path
for intentional removal.

In `@infrastructure/modules/observability/main.tf`:
- Around line 248-270: Update the aws_ecs_service.vm resource to register tasks
through Cloud Map using service_registries, configure the required private DNS
namespace/service resources, and output the resulting stable VictoriaMetrics DNS
name for clients. Preserve the existing Fargate networking and service settings;
use an internal NLB only if the current client requirements cannot use Cloud
Map.
- Around line 117-119: In infrastructure/modules/kms/main.tf, add a KMS policy
statement that grants EFS the necessary encrypt and decrypt permissions scoped
to the EFS service using a kms:ViaService condition for
elasticfilesystem.<region>.amazonaws.com. This will allow the
aws_efs_file_system resource in infrastructure/modules/observability/main.tf to
successfully use var.kms_key_arn without AccessDenied errors. Update any KMS
policy test coverage to include verification of the new EFS scoped condition
alongside the existing CloudWatch Logs condition.
- Around line 78-86: Update aws_security_group_rule.vm_egress_https to remove
the unrestricted 0.0.0.0/0 HTTPS egress; restrict outbound access to approved
AWS service endpoint ranges required by the task, or remove this rule and use
the approved egress proxy configuration.
- Around line 238-245: Update the ECS volume’s EFS configuration in the
observability module to require IAM authorization by setting
authorization_config.iam to ENABLED. Add an EFS access point, a task role
limited to elasticfilesystem:ClientMount and elasticfilesystem:ClientWrite, and
a file-system policy requiring TLS, the access point, and that task role; wire
these resources into the existing vm-data efs_volume_configuration.

In `@infrastructure/modules/observability/variables.tf`:
- Around line 55-58: Update the vm_image variable definition to validate that
the value references a SHA-256 image digest and document that the image must be
a linux/arm64 artifact, matching the ECS task’s ARM64 runtime contract. Keep the
existing string type and description scope while adding validation that rejects
non-digest image references.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: affcc8dd-bca3-4410-a58b-0dd543129005

📥 Commits

Reviewing files that changed from the base of the PR and between e9fec46 and 9640d24.

📒 Files selected for processing (5)
  • infrastructure/live/main.tf
  • infrastructure/live/variables.tf
  • infrastructure/modules/observability/main.tf
  • infrastructure/modules/observability/outputs.tf
  • infrastructure/modules/observability/variables.tf

Comment thread infrastructure/live/main.tf Outdated
Comment thread infrastructure/modules/observability/main.tf
Comment thread infrastructure/modules/observability/main.tf
Comment thread infrastructure/modules/observability/main.tf
Comment thread infrastructure/modules/observability/main.tf
Comment thread infrastructure/modules/observability/variables.tf

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread infrastructure/modules/observability/main.tf
Comment thread infrastructure/live/main.tf Outdated
Comment thread infrastructure/modules/observability/main.tf
Comment thread infrastructure/modules/observability/main.tf Outdated
Comment thread infrastructure/live/main.tf Outdated
Comment thread infrastructure/modules/observability/main.tf Outdated
Comment thread infrastructure/live/main.tf Outdated
Comment thread infrastructure/modules/observability/main.tf
Comment thread infrastructure/modules/observability/main.tf
Comment thread infrastructure/modules/observability/variables.tf
Signed-off-by: hassaansaleem28 <iamhassaans@gmail.com>
@github-actions github-actions Bot added the docs Improvements or additions to documentation label Jul 31, 2026
@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 2 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval blocked by 15 unresolved issues from previous reviews.

Re-trigger cubic

Signed-off-by: hassaansaleem28 <iamhassaans@gmail.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@infrastructure/modules/observability/README.md`:
- Line 67: Add the missing trailing newline after the END_TF_DOCS marker in the
README, then rerun the pre-commit end-of-file-fixer to verify the file remains
unchanged.
- Line 52: Update the subnet_ids variable description in the source Terraform
variable definition to document both private and public subnet usage when NAT
gateways are disabled, then regenerate
infrastructure/modules/observability/README.md so its input table matches the
updated description.

In `@infrastructure/modules/observability/tests/unit.tftest.hcl`:
- Around line 111-118: Update the test_task_mounts_encrypted_efs_volume
assertion to also verify that the vm-data volume’s EFS file system ID is
aws_efs_file_system.vm.id. Target the volume identified by its vm-data name,
while preserving the existing transit_encryption == "ENABLED" validation.
- Around line 66-72: Update the test_efs_ingress_from_vm_only assertion to
require source_security_group_id == aws_security_group.vm.id and to_port ==
2049, while preserving the existing from_port and ingress checks. Keep the
assertion focused on the aws_security_group_rule.efs_from_vm production rule.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1238403e-527b-4431-878a-321bdb97dc76

📥 Commits

Reviewing files that changed from the base of the PR and between 9640d24 and ff31b6e.

📒 Files selected for processing (3)
  • infrastructure/live/README.md
  • infrastructure/modules/observability/README.md
  • infrastructure/modules/observability/tests/unit.tftest.hcl

Comment thread infrastructure/modules/observability/README.md
Comment thread infrastructure/modules/observability/README.md Outdated
Comment thread infrastructure/modules/observability/tests/unit.tftest.hcl
Comment thread infrastructure/modules/observability/tests/unit.tftest.hcl

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 1 file (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread infrastructure/modules/observability/tests/unit.tftest.hcl
Comment thread infrastructure/modules/observability/tests/unit.tftest.hcl Outdated
Comment thread infrastructure/modules/observability/tests/unit.tftest.hcl
Signed-off-by: hassaansaleem28 <iamhassaans@gmail.com>
@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.84%. Comparing base (7f92666) to head (3d5fbdd).
⚠️ Report is 3 commits behind head on feature/o11y.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##           feature/o11y    #5341   +/-   ##
=============================================
  Coverage         98.84%   98.84%           
=============================================
  Files               541      543    +2     
  Lines             17165    17235   +70     
  Branches           2464     2472    +8     
=============================================
+ Hits              16966    17036   +70     
  Misses               99       99           
  Partials            100      100           
Flag Coverage Δ
backend 99.38% <ø> (+<0.01%) ⬆️
frontend 97.32% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e9fec46...3d5fbdd. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread infrastructure/modules/observability/variables.tf Outdated
Comment thread infrastructure/modules/observability/variables.tf Outdated
Signed-off-by: hassaansaleem28 <iamhassaans@gmail.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval blocked by 9 unresolved issues from previous reviews.

Re-trigger cubic

coderabbitai[bot]
coderabbitai Bot previously approved these changes Aug 3, 2026
@hassaansaleem28
hassaansaleem28 marked this pull request as ready for review August 3, 2026 10:54
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Aug 7, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 7 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread infrastructure/modules/observability/tests/integration.tftest.hcl
Comment thread infrastructure/modules/observability/README.md
Comment thread infrastructure/modules/observability/tests/setup/main.tf
Signed-off-by: hassaansaleem28 <iamhassaans@gmail.com>
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 4 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval blocked by 3 unresolved issues from previous reviews.

Re-trigger cubic

coderabbitai[bot]
coderabbitai Bot previously approved these changes Aug 7, 2026
Signed-off-by: hassaansaleem28 <iamhassaans@gmail.com>
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

cubic-dev-ai[bot]
cubic-dev-ai Bot previously approved these changes Aug 7, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

coderabbitai[bot]
coderabbitai Bot previously approved these changes Aug 7, 2026
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

@hassaansaleem28
hassaansaleem28 marked this pull request as ready for review August 7, 2026 05:24
@rudransh-shrivastava

Copy link
Copy Markdown
Collaborator

please use "re-request review" button to notify users
image

@hassaansaleem28

Copy link
Copy Markdown
Collaborator Author

please use "re-request review" button to notify users image

ah, my bad.

@rudransh-shrivastava

Copy link
Copy Markdown
Collaborator

no issues!

@rudransh-shrivastava rudransh-shrivastava left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work, LGTM! I tested it in LocalStack, and it works.

I only have one blocking request, rest can be addressed when you want.

Also, I think you need to address the false positive semgrep findings.

Comment thread infrastructure/live/main.tf Outdated
Comment on lines +25 to +28
observability_vm_image = trimspace(trimprefix(
one([for line in split("\n", file("${path.root}/../../docker/victoriametrics/Dockerfile")) : line if startswith(line, "FROM ")]),
"FROM "
))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it be something like this?

observability_vm_image = regex("(?m)^FROM (victoriametrics/victoria-metrics:\\S+)", file("${path.root}/../../docker/victoriametrics/Dockerfile"))[0]

@@ -0,0 +1 @@
.terraform.lock.hcl

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should commit this lockfile in this setup well.

Comment thread infrastructure/live/main.tf Outdated
environment = var.environment
kms_key_arn = module.kms.key_arn
project_name = var.project_name
subnet_ids = var.enable_nat_gateway ? module.networking.private_subnet_ids : module.networking.public_subnet_ids

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think VictoriaMetrics container should run in public subnet. This is risky. Why do we need to do this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I understand now, this is required for staging as it has no NAT.

I originally disabled NAT for staging to reduce costs. But since we have AWS's support for credits and all, I think we can afford a NAT for staging.

If @arkid15r agrees, can you remove enable_nat_gateway and enable it for both staging and production? It'll require some minor refactor in networking module, but it should be straightforward. Just use private subnet where there's currently a conditional expression based on this variable.

Not only this, it reduces backend and frontend task/container attack surface as they no longer get a public IP.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine if you want to do it later in a different PR, but please add a TODO comment for now if you do so.

common_tags = { Environment = "test", Project = "nest" }
environment = "test"
project_name = "nest"
vm_image = "victoriametrics/victoria-metrics:v1.145.0@sha256:c014fb5a711d38cb24fd0673197592cd1394bb903dbb16aea565620c9c8a3d70"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use the same pattern here?

image: victoriametrics/victoria-metrics:v1.145.0@sha256:c014fb5a711d38cb24fd0673197592cd1394bb903dbb16aea565620c9c8a3d70
build:
context: ../../docker/victoriametrics
dockerfile: Dockerfile

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pointing out that it runs as root but ECS task runs as non-root. Maybe something to keep in mind, no action required for this PR.

Comment on lines +103 to +107
variable "vm_retention_period" {
description = "The VictoriaMetrics data retention period (e.g., 12, 5y)."
type = string
default = "12"
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

12? please update to make it more explicit that it's 12 months. Both description and default.

}

resource "aws_security_group_rule" "vm_ingest_from_apps" {
for_each = toset(var.app_security_group_ids)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this breaks on an empty state apply. This is localstack logs but same will happen in prod/staging:

Plan: 21 to add, 0 to change, 0 to destroy.
╷
│ Error: Invalid for_each argument
│
│   on ../../modules/observability/main.tf line 67, in resource "aws_security_group_rule" "vm_ingest_from_apps":
│   67:   for_each = toset(var.app_security_group_ids)
│     ├────────────────
│     │ var.app_security_group_ids is list of string with 3 elements
│
│ The "for_each" set includes values derived from resource attributes that cannot be determined until apply, and so Terraform cannot determine the full set of keys that will identify the
│ instances of this resource.
│
│ When working with unknown values in for_each, it's better to use a map value where the keys are defined statically in your configuration and where only the values contain apply-time
│ results.
│
│ Alternatively, you could use the -target planning option to first apply only the resources that the for_each value depends on, and then apply a second time to fully converge.
╵
╷
│ Error: Invalid for_each argument
│
│   on ../../modules/observability/main.tf line 130, in resource "aws_efs_mount_target" "vm":
│  130:   for_each = toset(var.subnet_ids)
│     ├────────────────
│     │ var.subnet_ids is list of string with 2 elements
│
│ The "for_each" set includes values derived from resource attributes that cannot be determined until apply, and so Terraform cannot determine the full set of keys that will identify the
│ instances of this resource.
│
│ When working with unknown values in for_each, it's better to use a map value where the keys are defined statically in your configuration and where only the values contain apply-time
│ results.
│
│ Alternatively, you could use the -target planning option to first apply only the resources that the for_each value depends on, and then apply a second time to fully converge.
╵
make: *** [infrastructure-apply-observability] Error 1

It is because for_each needs to know its keys at plan time. But since we're passing the values from resources that haven't been created yet, those values are "known after apply". Since length of list is known at plan time, you should use count = length(var.app_security_group_ids) instead.

Example:

count = length(var.private_subnet_ids)

Signed-off-by: hassaansaleem28 <iamhassaans@gmail.com>
@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

2 similar comments
@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

@sonarqubecloud

Copy link
Copy Markdown

❌ The last analysis has failed.

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants