0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

local環境でdocker cognitoの環境を作成する

Posted at

local環境でdocker Cognitoの環境を作成する

Motivation

local stackのProを利用すればCognitoの環境は容易に手に入るが、とりあえずサクッと開発環境を手に入れたいなと思いmotoとterraformの環境を作成する。

TL;DR

moto server modeを利用した環境を作成して、terraformのendpoint urlをmoto server向けにする。

Directory Architecture

% tree .
.
├── Makefile
├── README.md
├── local-dev
│   ├── compose.yaml
│   ├── tmp.cognito.dockerfile
│   └── tmp.terraform.dockerfile
└── terraform
    ├── LICENSE.txt
    ├── main.tf
    └── terraform.tfstate

3 directories, 8 files

composeファイルは以下の通りです。
terraformとaws cliもdocker containerで作成しています。
host computer側を利用する場合は、terraform以下は不要です。

local-dev/compose.yaml
services:
  cognito:
    container_name: cognito_container
    build:
      context: .
      dockerfile: tmp.cognito.dockerfile
      args:
        VERSION: "5.0.25"
    ports:
      - 3001:3000
    restart: on-failure
    networks:
      - internal
  terraform:
    container_name: terraform_container
    build:
      context: .
      dockerfile: tmp.terraform.dockerfile
      target: development
      args:
        TERRAFORM_VERSION: "1.10.3"
        AWS_CLI_VERSION: "2.22.27"
    tty: true
    environment:
      AWS_ACCESS_KEY_ID: AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY: AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION: ap-northeast-1
    volumes:
      - ../terraform:/usr/terraform
    networks:
      - internal

networks:
  internal: {}

motoserverは何と言う設定はしてません。

local-dev/tmp.congnito.dockerfile
ARG VERSION

FROM motoserver/moto:${VERSION}

ENV MOTO_PORT=3000

terraformには、endpointsでdockerのnetwork内をみるようにしています。

terraform/main.tf
provider "aws" {
    region                      = "ap-northeast-1"
    skip_credentials_validation = true
    skip_metadata_api_check     = true
    skip_requesting_account_id  = true

    endpoints {
        cognitoidentity = "http://cognito:3000"
        cognitoidp = "http://cognito:3000"
    }
}

resource "aws_cognito_user_pool" "pool" {
  name = "my-user-pool"
}

aws-cli, terraform環境は以下になります。

local-dev/tmp.terraform.dockerfile
ARG AWS_CLI_VERSION

FROM amazon/aws-cli:${AWS_CLI_VERSION} as development

ARG TERRAFORM_VERSION

WORKDIR /usr/terraform

RUN yum install unzip -y

RUN curl https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip -o terraform_${TERRAFORM_VERSION}_linux_amd64.zip &&\
    unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip && rm terraform_${TERRAFORM_VERSION}_linux_amd64.zip &&\
    mv terraform /usr/bin/terraform

ENTRYPOINT [ "/bin/bash" ]

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?