Search code examples
terraformauth0

Accessing a Terraform variable from a map?


I'm trying to reach the aws_partner_event_source variable that sits within sink{} inside the resource.

resource "auth0_log_stream" "aws_logstream" {
  name   = "AWS Eventbridge Auth0 Log Stream"
  type   = "eventbridge"
  status = "active"

  sink {
    aws_account_id = "xxx"
    aws_region     = "eu-west-1"
    aws_partner_event_source = "xxx"
  }
}

resource "aws_cloudwatch_event_bus" "event_bridge_event_bus" {
  event_source_name = auth0_log_stream.aws_logstream.sink[aws_partner_event_source]
}

This however, doesn't work. I get: A reference to a resource type must be followed by at least one attribute access, specifying the resource name.

I also tried:

event_source_name = auth0_log_stream.aws_logstream.sink[2]

Which throws:

auth0_log_stream.aws_logstream.sink is list of object with 1 element │ │ The given key does not identify an element in this collection value.

These are the possible solutions I found when looking through Terraform Variable docs, but I can't seem to get it to work. Any help appreciated, thanks.


Solution

  • Since sink is a list of objects with one element (as per the error output), the correct syntax is:

    event_source_name = auth0_log_stream.aws_logstream.sink[0].aws_partner_event_source