DEV Community

Discussion on: A guide to provisioning AWS ECS Fargate using Terraform

Collapse
 
nz_cub3y profile image
Charles Peach • Edited

Heya, following all the example terraform config, on first terraform plan I get the following errors:

Error: Reference to undeclared resource

  on main.tf line 192, in resource "aws_ecs_service" "staging":
 192:   cluster         = aws_ecs_cluster.staging.id

A managed resource "aws_ecs_cluster" "staging" has not been declared in the
root module.

Error: Reference to undeclared input variable

  on main.tf line 231, in resource "null_resource" "push":
 231:      command     = "${coalesce("push.sh", "${path.module}/push.sh")} ${var.source_path} ${aws_ecr_repository.repo.repository_url} ${var.tag}"

An input variable with the name "source_path" has not been declared. This
variable can be declared with a variable "source_path" {} block.

Error: Reference to undeclared input variable

  on main.tf line 231, in resource "null_resource" "push":
 231:      command     = "${coalesce("push.sh", "${path.module}/push.sh")} ${var.source_path} ${aws_ecr_repository.repo.repository_url} ${var.tag}"

An input variable with the name "tag" has not been declared. This variable can
be declared with a variable "tag" {} block.
Enter fullscreen mode Exit fullscreen mode

The tag one is simple, I can just remove the tag or add a tag variable, but what about the other issues?

Collapse
 
nz_cub3y profile image
Charles Peach

Fixed my issues, was missing these variables:

variable "source_path" {
  description = "source path for project"
  default     = "./"
}

variable "tag" {
  description = "tag to use for our new docker image"
  default     = "latest"
}
Enter fullscreen mode Exit fullscreen mode

And was also missing the ECS cluster definition:

resource "aws_ecs_cluster" "staging" {
  name = "tf-ecs-cluster"
}
Enter fullscreen mode Exit fullscreen mode