Search code examples
amazon-web-servicesterraformlocalstack

Cant get terraform and localstack to run a simple example


I have tried to get terraform and local stack running on a simple example, but all it seems to do it kinda hang.. im on TF 12, and provider "aws" (hashicorp/aws) 3.68.0...

So here is my docker file

version: '3.8'
services:
  localstack:
    image: localstack/localstack:latest
    ports:
      - 8080:8080 # webui
      - 4569:4569 # dynamodb
      - 4574:4574 # lamba
    environment:
      - DATA_DIR=/tmp/localstack/data
      - DEBUG=1
      - DEFAULT_REGION=ap-southeast-2
      - DOCKER_HOST=unix:///var/run/docker.sock
      - LAMBDA_EXECUTOR=docker-reuse
      - PORT_WEB_UI=8080
      - SERVICES=lambda,dynamodb
      - LAMBDA_DOCKER_NETWORK=localstack-tutorial
   volumes:
      - /var/run/docker.sock:/var/run/docker.sock

Here is my localstack tf file

provider "aws" {
  access_key                  = "mock_access_key"
  region                      = "us-east-1"
  s3_force_path_style         = true
  secret_key                  = "mock_secret_key"
  skip_credentials_validation = true
  skip_metadata_api_check     = true
  skip_requesting_account_id  = true

  endpoints {
    dynamodb = "http://localhost:4569"
    lambda   = "http://localhost:4574"
  }
}

resource "aws_dynamodb_table" "table_1" {
  name           = "table_1"
  read_capacity  = "20"
  write_capacity = "20"
  hash_key       = "id"

  attribute {
    name = "id"
    type = "S"
  }
}

When i run this using terraform plan its runs fine, but when i run apply --auto-approve..

$ terraform apply --auto-approve
aws_dynamodb_table.table_1: Creating...
aws_dynamodb_table.table_1: Still creating... [10s elapsed]
aws_dynamodb_table.table_1: Still creating... [20s elapsed]
aws_dynamodb_table.table_1: Still creating... [30s elapsed]
aws_dynamodb_table.table_1: Still creating... [40s elapsed]
aws_dynamodb_table.table_1: Still creating... [50s elapsed]
aws_dynamodb_table.table_1: Still creating... [1m0s elapsed]
aws_dynamodb_table.table_1: Still creating... [1m10s elapsed]
aws_dynamodb_table.table_1: Still creating... [1m20s elapsed]
aws_dynamodb_table.table_1: Still creating... [1m30s elapsed]
aws_dynamodb_table.table_1: Still creating... [1m40s elapsed]
aws_dynamodb_table.table_1: Still creating... [1m50s elapsed]
aws_dynamodb_table.table_1: Still creating... [2m0s elapsed]
aws_dynamodb_table.table_1: Still creating... [2m10s elapsed]
aws_dynamodb_table.table_1: Still creating... [2m20s elapsed]
aws_dynamodb_table.table_1: Still creating... [2m30s elapsed]
aws_dynamodb_table.table_1: Still creating... [2m40s elapsed]
aws_dynamodb_table.table_1: Still creating... [2m50s elapsed]
aws_dynamodb_table.table_1: Still creating... [3m0s elapsed]

Solution

  • I think your ports are incorrect. From docs:

    A major (breaking) change has been merged in PR #2905 - starting with releases after v0.11.5, all services are now exposed via the edge service (port 4566) only! Please update your client configurations to use this new endpoint.