diff --git a/.github/workflows/ecr_deployment.yaml b/.github/workflows/ecr_deployment.yaml index 60e77aa7..37974f87 100644 --- a/.github/workflows/ecr_deployment.yaml +++ b/.github/workflows/ecr_deployment.yaml @@ -17,20 +17,45 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - with: - region: us-east-1 + # - name: Login to Amazon ECR + # id: login-ecr + # uses: aws-actions/amazon-ecr-login@v1 + # with: + # region: us-east-1 # - name: Authenticate Docker Registry for ECR # run: aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 339712971032.dkr.ecr.us-east-1.amazonaws.com - - name: Build Docker fhir-converter image - run: docker build -t fhir-converter . - - - name: Tag Docker image - run: docker tag fhir-converter:latest 339712971032.dkr.ecr.us-east-1.amazonaws.com/fhir-converter:latest - - - name: Push Docker image - run: docker push 339712971032.dkr.ecr.us-east-1.amazonaws.com/fhir-converter:latest \ No newline at end of file + - uses: hashicorp/setup-terraform@v2.0.3 + with: + terraform_version: 1.3.3 + - name: Init Terraform + working-directory: ./terraform/implementation/ecs + env: + ENVIRONMENT: dev + BUCKET: infra-tfstate-alis-default-aizwjxuh + DYNAMODB_TABLE: infra-tfstate-lock-alis-default-aizwjxuh + REGION: us-east-1 + OWNER: alis + PROJECT: infra + shell: bash + run: | + touch $ENVIRONMENT.tfvars + echo "owner = \"$OWNER\"" + echo "project = \"$PROJECT\"" + echo "region = \"$REGION\"" + terraform init \ + -migrate-state \ + -var-file="$ENVIRONMENT.tfvars" \ + -backend-config "bucket=$BUCKET" \ + -backend-config "dynamodb_table=$DYNAMODB_TABLE" \ + -backend-config "region=$REGION" + terraform apply -var-file="$ENVIRONMENT.tfvars" + + # - name: Apply Terraform + # working-directory: ./terraform/implementation/ecs + # env: + # ENVIRONMENT: value + # shell: bash + # run: | + # terraform apply -var-file="$ENVIRONMENT.tfvars" diff --git a/terraform/implementation/ecs/apply.sh b/terraform/implementation/ecs/ecs.sh similarity index 87% rename from terraform/implementation/ecs/apply.sh rename to terraform/implementation/ecs/ecs.sh index 9a5b21cd..66dc1513 100755 --- a/terraform/implementation/ecs/apply.sh +++ b/terraform/implementation/ecs/ecs.sh @@ -71,28 +71,30 @@ if [ ! -f "$ENVIRONMENT.tfvars" ]; then fi if ! grep -q "owner" "$ENVIRONMENT.tfvars"; then - read -p "Who is the owner of this infrastructure? default=skylight" owner_choice + read -p "Who is the owner of this infrastructure? ( default=skylight ): " owner_choice owner_choice=${owner_choice:-skylight} echo "owner = \"$owner_choice\"" >> "$ENVIRONMENT.tfvars" fi if ! grep -q "project" "$ENVIRONMENT.tfvars"; then - read -p "What is this project called? default=dibbs" project_choice + read -p "What is this project called? ( default=dibbs ): " project_choice project_choice=${project_choice:-dibbs} echo "project = \"$project_choice\"" >> "$ENVIRONMENT.tfvars" fi if ! grep -q "region" "$ENVIRONMENT.tfvars"; then - read -p "What aws region are you setting up in? default=us-east-1" region_choice + read -p "What aws region are you setting up in? ( default=us-east-1 ): " region_choice region_choice=${region_choice:-us-east-1} echo "region = \"$region_choice\"" >> "$ENVIRONMENT.tfvars" fi -echo "Running Terraform with the following configuration:" +echo "Running Terraform with the following variables:" echo "Environment: $ENVIRONMENT" +echo "Terraform Workspace: $ENVIRONMENT" echo "Bucket: $BUCKET" echo "DynamoDB Table: $DYNAMODB_TABLE" echo "Region: $REGION" +cat "$ENVIRONMENT.tfvars" terraform init \ -migrate-state \ @@ -117,5 +119,4 @@ else fi fi -terraform destroy \ - -var-file="$ENVIRONMENT.tfvars" +terraform apply -var-file="$ENVIRONMENT.tfvars" diff --git a/terraform/implementation/setup/setup.sh b/terraform/implementation/setup/setup.sh index d8767d23..552a85b1 100755 --- a/terraform/implementation/setup/setup.sh +++ b/terraform/implementation/setup/setup.sh @@ -1,12 +1,7 @@ #!/bin/bash -# Load environment variables from .env file -if [ -f ../.env ]; then - export $(cat ../.env | xargs) -fi - # set default values -ENVIRONMENT="${ENVIRONMENT:-}" +ENVIRONMENT="${ENVIRONMENT:-default}" while [[ $# -gt 0 ]] do @@ -49,22 +44,25 @@ if [ ! -f "$ENVIRONMENT.tfvars" ]; then fi if ! grep -q "owner" "$ENVIRONMENT.tfvars"; then - read -p "Who is the owner of this infrastructure? default=skylight" owner_choice + read -p "Who is the owner of this infrastructure? ( default=skylight ): " owner_choice owner_choice=${owner_choice:-skylight} echo "owner = \"$owner_choice\"" >> "$ENVIRONMENT.tfvars" fi if ! grep -q "project" "$ENVIRONMENT.tfvars"; then - read -p "What is this project called? default=dibbs" project_choice + read -p "What is this project called? ( default=dibbs ): " project_choice project_choice=${project_choice:-dibbs} echo "project = \"$project_choice\"" >> "$ENVIRONMENT.tfvars" fi if ! grep -q "region" "$ENVIRONMENT.tfvars"; then - read -p "What aws region are you setting up in? default=us-east-1" region_choice + read -p "What aws region are you setting up in? ( default=us-east-1 ): " region_choice region_choice=${region_choice:-us-east-1} echo "region = \"$region_choice\"" >> "$ENVIRONMENT.tfvars" fi +echo "Running Terraform with the following variables:" +cat "$ENVIRONMENT.tfvars" + terraform init -var-file="$ENVIRONMENT.tfvars" terraform apply -var-file="$ENVIRONMENT.tfvars"