Terraform: Resource not found during plan

Created on 26 Apr 2018  ยท  4Comments  ยท  Source: hashicorp/terraform

Terraform Version

Terraform v0.11.7

Terraform Configuration Files

...

# ------------------------------------------------------------------------------
# CREATE APPLICATION LOAD BALANCER
# ------------------------------------------------------------------------------
resource "aws_lb" "lb" {
  name               = "${local.env_id}-alb"
  load_balancer_type = "application"
  subnets            = ["${var.subnet_ids}"]
  security_groups    = ["${aws_security_group.application_alb.id}"]

  access_logs {
    bucket = "${var.lb_log_bucket}"
  }

  enable_cross_zone_load_balancing = true
  idle_timeout                     = 400

  tags {
    Name      = "${local.env_id}-alb"
    Terraform = "true"
  }
}

resource "aws_lb_target_group" "http" {
  name                 = "${local.env_id}-alb-http"
  port                 = 80
  protocol             = "HTTP"
  vpc_id               = "${var.vpc_id}"
  deregistration_delay = 400

  health_check {
    healthy_threshold   = 2
    unhealthy_threshold = 2
    timeout             = 3
    interval            = 30
    protocol            = "HTTP"
    port                = "8081"
    path                = "/ping"
    matcher             = 200
  }

}

resource "aws_lb_listener" "http" {
  load_balancer_arn = "${aws_lb.lb.arn}"
  port              = 80
  protocol          = "HTTP"

  default_action {
    target_group_arn = "${aws_lb_target_group.http.arn}"
    type             = "forward"
  }
}

resource "aws_lb_target_group" "https" {
  name                 = "${local.env_id}-alb-https"
  port                 = 443
  protocol             = "HTTPS"
  vpc_id               = "${var.vpc_id}"
  deregistration_delay = 400

  health_check {
    healthy_threshold   = 2
    unhealthy_threshold = 2
    timeout             = 3
    interval            = 30
    protocol            = "HTTP"
    port                = "8081"
    path                = "/ping"
    matcher             = 200
  }
}

resource "aws_lb_listener" "https" {
  load_balancer_arn = "${aws_lb.lb.arn}"
  port              = "443"
  protocol          = "HTTPS"

  default_action {
    target_group_arn = "${aws_lb_target_group.https.arn}"
    type             = "forward"
  }
}

# ------------------------------------------------------------------------------
# CONFIGURE LB STICKINESS
# ------------------------------------------------------------------------------
resource "aws_lb_cookie_stickiness_policy" "http" {
  name          = "http-policy"
  load_balancer = "${aws_lb.lb.id}"
  lb_port       = 80
}

resource "aws_lb_cookie_stickiness_policy" "https" {
  name          = "https-policy"
  load_balancer = "${aws_lb.lb.id}"
  lb_port       = 443
}

Expected Behavior

A plan with no errors about not being able to find a resource that's been defined.

Actual Behavior

I get the following errors:

Error: Error running plan: 16 error(s) occurred:

* module.application.module.application_cluster_east.module.networking.aws_lb_cookie_stickiness_policy.http: 1 error(s) occurred:

* module.application.module.application_cluster_east.module.networking.aws_lb_cookie_stickiness_policy.http: Resource 'aws_lb.lb' not found for variable 'aws_lb.lb.id'
* module.application.module.application_cluster_west.module.networking.aws_lb_listener.http: 1 error(s) occurred:

* module.application.module.application_cluster_west.module.networking.aws_lb_listener.http: Resource 'aws_lb.lb' not found for variable 'aws_lb.lb.arn'
* module.manager.module.networking.output.lb_zone_id: Resource 'aws_lb.lb' not found for variable 'aws_lb.lb.zone_id'
* module.application.module.application_cluster_east.module.networking.output.lb_zone_id: Resource 'aws_lb.lb' not found for variable 'aws_lb.lb.zone_id'
* module.application.module.application_cluster_east.module.networking.aws_lb_listener.https: 1 error(s) occurred:

* module.application.module.application_cluster_east.module.networking.aws_lb_listener.https: Resource 'aws_lb.lb' not found for variable 'aws_lb.lb.arn'
* module.application.module.application_cluster_east.module.networking.aws_lb_listener.http: 1 error(s) occurred:

* module.application.module.application_cluster_east.module.networking.aws_lb_listener.http: Resource 'aws_lb.lb' not found for variable 'aws_lb.lb.arn'
* module.application.module.application_cluster_west.module.networking.output.lb_dns_name: Resource 'aws_lb.lb' not found for variable 'aws_lb.lb.dns_name'
* module.manager.module.networking.aws_lb_listener.https: 1 error(s) occurred:

* module.manager.module.networking.aws_lb_listener.https: Resource 'aws_lb.lb' not found for variable 'aws_lb.lb.arn'
* module.application.module.application_cluster_west.module.networking.aws_lb_listener.https: 1 error(s) occurred:

* module.application.module.application_cluster_west.module.networking.aws_lb_listener.https: Resource 'aws_lb.lb' not found for variable 'aws_lb.lb.arn'
* module.application.module.application_cluster_west.module.networking.aws_lb_cookie_stickiness_policy.https: 1 error(s) occurred:

* module.application.module.application_cluster_west.module.networking.aws_lb_cookie_stickiness_policy.https: Resource 'aws_lb.lb' not found for variable 'aws_lb.lb.id'
* module.application.module.application_cluster_east.module.networking.aws_lb_cookie_stickiness_policy.https: 1 error(s) occurred:

* module.application.module.application_cluster_east.module.networking.aws_lb_cookie_stickiness_policy.https: Resource 'aws_lb.lb' not found for variable 'aws_lb.lb.id'
* module.application.module.application_cluster_east.module.networking.output.lb_dns_name: Resource 'aws_lb.lb' not found for variable 'aws_lb.lb.dns_name'
* module.manager.module.networking.output.lb_dns_name: Resource 'aws_lb.lb' not found for variable 'aws_lb.lb.dns_name'
* module.manager.module.networking.aws_lb_listener.http: 1 error(s) occurred:

* module.manager.module.networking.aws_lb_listener.http: Resource 'aws_lb.lb' not found for variable 'aws_lb.lb.arn'
* module.application.module.application_cluster_west.module.networking.output.lb_zone_id: Resource 'aws_lb.lb' not found for variable 'aws_lb.lb.zone_id'
* module.application.module.application_cluster_west.module.networking.aws_lb_cookie_stickiness_policy.http: 1 error(s) occurred:

* module.application.module.application_cluster_west.module.networking.aws_lb_cookie_stickiness_policy.http: Resource 'aws_lb.lb' not found for variable 'aws_lb.lb.id'

Most helpful comment

I'm having a similar issue. There is no indication that the resource is invalid and not being included. In my case I have a aws_ecs_task_definition with an invalid container_definitions but nothing indicates the container_definitions is invalid during terraform plan. It just fails on the first resource that tries to get the ARN of the aws_ecs_task_definition resource.

I'm looking into invalid definitions seperately. I'm only mentioning this as another example of how the issue manifests itself.

All 4 comments

I'm closing this. It turned out to be an issue with my configuration that was causing the aws_lb to be invalid and not make it into the plan for other things to reference. The invalid error of the resource configuration isn't being exposed in anyway currently.

The issue with with the name property that was referencing local.env_id. That local looks like this:

locals {
  env_id = "${element(split(".", var.fqdn), 0)}"
}

If I hardcode a value for env_id rather than use nested functions to parse a value out of a variable, then everything works fine.

I'm having a similar issue. There is no indication that the resource is invalid and not being included. In my case I have a aws_ecs_task_definition with an invalid container_definitions but nothing indicates the container_definitions is invalid during terraform plan. It just fails on the first resource that tries to get the ARN of the aws_ecs_task_definition resource.

I'm looking into invalid definitions seperately. I'm only mentioning this as another example of how the issue manifests itself.

@ifnull I'm facing the same problem. Also with a faulty container_definition(s).
This issue is still open imo, might be better located in the aws provider repo.

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ketzacoatl picture ketzacoatl  ยท  3Comments

thebenwaters picture thebenwaters  ยท  3Comments

rjinski picture rjinski  ยท  3Comments

larstobi picture larstobi  ยท  3Comments

sprokopiak picture sprokopiak  ยท  3Comments