Skip to content

Conversation

@tembleking
Copy link
Member

Summary

  • Fix provider crash when sysdig_secure_team.zone_ids references IDs from sysdig_secure_zone resources created with for_each
  • Add IsKnown() checks before calling AsValueSlice() and True() on cty values in CustomizeDiff

Problem

When using dynamic zone wiring like this:

resource "sysdig_secure_zone" "zones" {
  for_each = local.teams
  name     = "Zone-${each.key}"
  # ...
}

resource "sysdig_secure_team" "teams" {
  for_each = local.teams
  name     = "Team-${each.key}"
  zone_ids = [sysdig_secure_zone.zones[each.key].id]
}

The provider panics during terraform plan:

panic: value is not known
github.com/hashicorp/go-cty/cty.Value.AsValueSlice(...)
github.com/draios/terraform-provider-sysdig/sysdig/resource_sysdig_secure_team.go:34

Root Cause

In CustomizeDiff, the code calls AsValueSlice() and True() on cty values without checking if they are known first. When zone_ids depends on resources being created in the same plan (via for_each), the value is cty.UnknownVal(cty.List(cty.Number)). Calling AsValueSlice() on an unknown value causes a panic.

Solution

Add IsKnown() checks before accessing cty values:

// Before
if !zoneIDsPlan.IsNull() && len(zoneIDsPlan.AsValueSlice()) > 0 {

// After  
if !zoneIDsPlan.IsNull() && zoneIDsPlan.IsKnown() && len(zoneIDsPlan.AsValueSlice()) > 0 {

When values are unknown during plan, the validation is safely skipped and will execute during apply when values become known.

…ch resources

When using `for_each` to create multiple `sysdig_secure_zone` resources
and referencing their IDs dynamically in `sysdig_secure_team.zone_ids`,
the provider crashes during `terraform plan` with:

    panic: value is not known

This happens because `CustomizeDiff` calls `AsValueSlice()` and `True()`
on cty values without first checking if they are known. When zone_ids
depends on resources being created in the same plan, the entire list is
a cty.UnknownVal, and these methods panic on unknown values.

The fix adds `IsKnown()` checks before accessing the values. When values
are unknown during plan, the validation is skipped and will run during
apply when values become known.
@tembleking tembleking enabled auto-merge (squash) February 2, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants