-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from NASA-IMPACT/fix/tf-env-variables
Tf env variables, remove dns
- Loading branch information
Showing
16 changed files
with
229 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#! /bin/bash | ||
# Check .env file | ||
|
||
|
||
DOT_ENV=$1 | ||
|
||
if [ -f $DOT_ENV ] | ||
then | ||
set -a; source $DOT_ENV; set +a | ||
else | ||
echo "Run: ./scripts/deploy.sh <.env_file>" | ||
echo "Please create $DOT_ENV file first and try again" | ||
exit 1 | ||
fi | ||
|
||
function create_state_bucket { | ||
# $1 region | ||
# $2 bucket_name | ||
|
||
aws s3 mb s3://$2 --region $1 | ||
aws s3api put-bucket-versioning \ | ||
--bucket $2 \ | ||
--versioning-configuration Status=Enabled | ||
} | ||
|
||
function generate_terraform_variables { | ||
tf_vars=(tf tfvars) | ||
for tf_var in "${tf_vars[@]}"; do | ||
( | ||
echo "cat <<EOF" | ||
cat terraform.${tf_var}.tmpl | ||
echo EOF | ||
) | sh > terraform.${tf_var} | ||
done | ||
|
||
} | ||
|
||
function check_create_remote_state { | ||
# $1 aws_region | ||
# $2 bucket name | ||
# $3 dynamotable_name | ||
AWS_REGION=$1 | ||
STATE_BUCKET_NAME=$2 | ||
|
||
bucketstatus=$(aws s3api head-bucket --bucket $STATE_BUCKET_NAME 2>&1) | ||
|
||
if echo "${bucketstatus}" | grep 'Not Found'; | ||
then | ||
echo "Creating TF remote state" | ||
create_state_bucket $AWS_REGION $STATE_BUCKET_NAME | ||
elif echo "${bucketstatus}" | grep 'Forbidden'; | ||
then | ||
echo "Bucket $STATE_BUCKET_NAME exists but not owned" | ||
exit 1 | ||
elif echo "${bucketstatus}" | grep 'Bad Request'; | ||
then | ||
echo "Bucket $STATE_BUCKET_NAME specified is less than 3 or greater than 63 characters" | ||
exit 1 | ||
else | ||
echo "State Bucket $STATE_BUCKET_NAME owned and exists. Continue..."; | ||
fi | ||
} | ||
|
||
|
||
cd ./terraform/features-api | ||
generate_terraform_variables | ||
check_create_remote_state $AWS_REGION $STATE_BUCKET_NAME | ||
|
||
read -rp 'action [init|plan|deploy]: ' ACTION | ||
case $ACTION in | ||
init) | ||
terraform init | ||
;; | ||
plan) | ||
terraform plan | ||
;; | ||
|
||
deploy) | ||
terraform apply --auto-approve | ||
;; | ||
*) | ||
echo "Choose from 'init', 'plan' or 'deploy'" | ||
exit 1 | ||
;; | ||
esac | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
data "aws_route53_zone" "zone" { | ||
provider = aws.west2 | ||
name = var.dns_zone_name | ||
} | ||
# data "aws_route53_zone" "zone" { | ||
# provider = aws.west2 | ||
# name = var.dns_zone_name | ||
# } | ||
|
||
resource "aws_acm_certificate" "cert" { | ||
provider = aws.west2 | ||
domain_name = "*.${data.aws_route53_zone.zone.name}" | ||
validation_method = "DNS" | ||
tags = var.tags | ||
# resource "aws_acm_certificate" "cert" { | ||
# provider = aws.west2 | ||
# domain_name = "*.${data.aws_route53_zone.zone.name}" | ||
# validation_method = "DNS" | ||
# tags = var.tags | ||
|
||
lifecycle { | ||
create_before_destroy = true | ||
} | ||
} | ||
# lifecycle { | ||
# create_before_destroy = true | ||
# } | ||
# } | ||
|
||
resource "aws_route53_record" "subdomain_record" { | ||
provider = aws.west2 | ||
name = "${var.dns_subdomain}.${data.aws_route53_zone.zone.name}" | ||
zone_id = data.aws_route53_zone.zone.id | ||
type = "A" | ||
# resource "aws_route53_record" "subdomain_record" { | ||
# provider = aws.west2 | ||
# name = "${var.dns_subdomain}.${data.aws_route53_zone.zone.name}" | ||
# zone_id = data.aws_route53_zone.zone.id | ||
# type = "A" | ||
|
||
alias { | ||
name = aws_alb.alb_ecs.dns_name | ||
zone_id = aws_alb.alb_ecs.zone_id | ||
evaluate_target_health = true | ||
} | ||
} | ||
# alias { | ||
# name = aws_alb.alb_ecs.dns_name | ||
# zone_id = aws_alb.alb_ecs.zone_id | ||
# evaluate_target_health = true | ||
# } | ||
# } | ||
|
||
resource "aws_lb_listener_certificate" "cert" { | ||
provider = aws.west2 | ||
listener_arn = aws_alb_listener.alb_listener_ecs.arn | ||
certificate_arn = aws_acm_certificate.cert.arn | ||
} | ||
# resource "aws_lb_listener_certificate" "cert" { | ||
# provider = aws.west2 | ||
# listener_arn = aws_alb_listener.alb_listener_ecs.arn | ||
# certificate_arn = aws_acm_certificate.cert.arn | ||
# } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
provider "aws" { | ||
alias = "west1" | ||
region = "us-west-1" | ||
} | ||
|
||
provider "aws" { | ||
alias = "west2" | ||
region = "us-west-2" | ||
} | ||
|
||
terraform { | ||
required_version = "1.3.9" | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 5.0" | ||
} | ||
} | ||
backend "s3" { | ||
bucket = "${STATE_BUCKET_NAME}" | ||
key = "root" | ||
region = "${AWS_REGION}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
region = "us-west-2" | ||
registry_name = "ghgc-features-api-registry" | ||
env = "dev" | ||
project_name = "ghgc-features-api" | ||
availability_zones = ["us-west-2a", "us-west-2b"] | ||
service_port = "8080" | ||
dns_zone_name = "dev.ghg.center" | ||
tags = {"project": "ghgc", "service": "ghgc-features-api-dev"} | ||
vpc_id = "vpc-0a20167ff1004d0f2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
region = "${AWS_REGION}" | ||
registry_name = "${REGISTRY_NAME}" | ||
env = "${ENV}" | ||
project_name = "${PROJECT_NAME}" | ||
availability_zones = ${AZ} | ||
service_port = "${SERVICE_PORT}" | ||
dns_zone_name = "${DNS_ZONE_NAME}" | ||
tags = ${TAGS} | ||
vpc_id = "${VPC_ID}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
region = "us-west-2" | ||
registry_name = "features-api-registry" | ||
registry_name = "ghgc-features-api-registry" | ||
env = "dev" | ||
project_name = "veda-features-api" | ||
project_name = "ghgc-features-api" | ||
db_public_subnet = false | ||
availability_zones = ["us-west-2a", "us-west-2b"] | ||
service_port = 8080 | ||
dns_zone_name = "delta-backend.com" | ||
dns_subdomain = "ghg-dev" | ||
tags = {"project": "veda", "service": "veda-features-api-dev"} | ||
vpc_id = "vpc-0512162c42da5e645" | ||
dns_zone_name = "dev.ghg.center" | ||
dns_subdomain = "features-api" | ||
tags = {"project": "ghgc", "service": "ghgc-features-api-dev"} | ||
vpc_id = "vpc-0a20167ff1004d0f2" | ||
alb_protocol = "HTTP" |
Oops, something went wrong.