Rajesh
Rajesh

Reputation: 49

Terraform 0.12 issue . This object does not have an attribute named "xyz"

i have a project that i created in terraform 0.12 and its modularized.

its something like:

<project_name>
----sg
    --main.tf
    --variables.tf
    --outputs.tf
----ecs
    --main.tf
    --variables.tf
    --outputs.tf
----efs
    --main.tf
    --variables.tf
    --outputs.tf
----alb
    --main.tf
    --variables.tf
    --outputs.tf

i will be calling the outputs values in sg[security group] using remote state.

i was able to call the outputs values form sg to ecs and other modules successfully but while doing same in alb i get following error. "This object does not have an attribute named "alb_sg"".

the outputs.tf file for sg is

output "alb_sg" {
value = [module.alb_sg.this_security_group_id]}

...
...
...

Security group Output from terraform apply:

alb_sg = [
    "sg-somevalue"
]

ecs_sg = [
    "sg-somevalue"
]

efs_sg = [
    "sg-somevalue"
]

alb resource code from alb module :

resource "aws_lb" this
{
name = somename
subnets = flatten(module.vpc_presets.subnet_ids)
security_groups = [data.terraform_remote_state.remote_state_sg.outputs.alb_sg]


internal = "true"
loab_balancer_type = "application"
tags = var.tags
}

the error after i do terraform apply from inside alb module

Error: Unsupported attribute. 

on main.tf line 12, in resource "aws_lb" "this"

12: security_groups = [data.terraform_remote_state.remote_state_sg.outputs.alb_sg]

data.terraform_remote_state.remote_state_sg.outputs is object with 3 attributes

This object does not have an attribute named “alb_sg”

Upvotes: 0

Views: 5789

Answers (2)

Rajesh
Rajesh

Reputation: 49

The issue was with wrong reference to the remote state. i was referring to different remote state and that was not having alb_sg attribute. after going through the code again i realized that it was coding issue.

Upvotes: 1

Ked Mardemootoo
Ked Mardemootoo

Reputation: 1605

So there's a mistake in your resource declaration:

It should be "this" instead of this. See below:

resource "aws_lb" "this"
{
   name = somename
   subnets = flatten(module.vpc_presets.subnet_ids)
   security_groups = [data.terraform_remote_state.remote_state_sg.outputs.alb_sg]


   internal = "true"
   loab_balancer_type = "application"
   tags = var.tags
}

You can refer to the terraform documentation for aws_lb resource type.

Upvotes: 0

Related Questions