Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
TF_VAR_chat_model__type: ${{ vars.CHAT_MODEL__TYPE }}
TF_VAR_chat_model__size: ${{ vars.CHAT_MODEL__SIZE }}
TF_VAR_chat_model__api_key: ${{ secrets.CHAT_MODEL__API_KEY }}
TF_VAR_dns_account_role_arn: ${{ vars.DNS_ACCOUNT_ROLE_ARN }}
defaults:
run:
working-directory: terraform/aws
Expand Down
28 changes: 25 additions & 3 deletions terraform/aws/acm.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
data "aws_route53_zone" "ecs_domain" {
provider = aws.dns
name = var.domain_name
private_zone = false
}

module "acm" {
source = "terraform-aws-modules/acm/aws"
source = "terraform-aws-modules/acm/aws"
version = "~> 6.2.0"

domain_name = var.domain_name
zone_id = data.aws_route53_zone.ecs_domain.zone_id
Expand All @@ -13,5 +15,25 @@ module "acm" {
"*.${var.domain_name}",
]

validation_method = "DNS"
}
validation_method = "DNS"
create_route53_records = false
validation_record_fqdns = module.route53_validation.validation_route53_record_fqdns
}

module "route53_validation" {
source = "terraform-aws-modules/acm/aws"
version = "~> 6.2.0"

providers = {
aws = aws.dns
}

create_certificate = false
create_route53_records_only = true
validation_method = "DNS"

zone_id = data.aws_route53_zone.ecs_domain.zone_id
distinct_domain_names = module.acm.distinct_domain_names

acm_certificate_domain_validation_options = module.acm.acm_certificate_domain_validation_options
}
Comment on lines +18 to +39

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to #218 (comment), the certificate manager module automatically handles DNS validation, but assumes the certificate is being issued in the DNS authority account.

Using same module and pointing to separate accounts to propagate DNS validation to correct place.

23 changes: 14 additions & 9 deletions terraform/aws/alb.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module "alb" {
source = "terraform-aws-modules/alb/aws"
source = "terraform-aws-modules/alb/aws"
version = "~> 10.3.0"

name = "atlas-lb"

Expand Down Expand Up @@ -67,13 +68,17 @@ module "alb" {
}
}

route53_records = {
A = {
name = "api"
type = "A"
zone_id = data.aws_route53_zone.ecs_domain.id
}
}

tags = var.tags
}

resource "aws_route53_record" "atlas_assistant_api" {
provider = aws.dns
zone_id = data.aws_route53_zone.ecs_domain.zone_id
name = var.api_subdomain
type = "A"
alias {
name = module.alb.dns_name
zone_id = module.alb.zone_id
evaluate_target_health = true
}
Comment on lines -70 to +83

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, the api portion of api.atlas-assistant.ds.io was automatically created by the load balancer module, which assumes DNS lives in the same account.

Provisioning separately allows explicit reference to another provider (account).

}
5 changes: 4 additions & 1 deletion terraform/aws/cognito.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ resource "aws_cognito_user_pool" "atlas_pool" {
resource "aws_cognito_user_pool_client" "atlas_pool_client" {
name = "atlas-backend-client"
user_pool_id = aws_cognito_user_pool.atlas_pool.id
callback_urls = jsondecode(var.cognito_redirect_urls)
callback_urls = concat(
["https://${var.api_subdomain}.${var.domain_name}/docs/oauth2-redirect"],
jsondecode(var.cognito_redirect_urls),
)
allowed_oauth_flows_user_pool_client = true
allowed_oauth_flows = ["code"]
allowed_oauth_scopes = ["openid", "email", "phone", "profile"]
Expand Down
9 changes: 5 additions & 4 deletions terraform/aws/ecr.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module "ecr" {
source = "terraform-aws-modules/ecr/aws"
source = "terraform-aws-modules/ecr/aws"
version = "~> 3.1.0"

repository_name = "atlas"

Expand Down Expand Up @@ -29,10 +30,10 @@ module "ecr" {
rulePriority = 2,
description = "Keep last 5 tagged images",
selection = {
tagStatus = "tagged",
tagStatus = "tagged",
tagPrefixList = ["sha-"],
countType = "imageCountMoreThan",
countNumber = 5
countType = "imageCountMoreThan",
countNumber = 5
},
action = {
type = "expire"
Expand Down
3 changes: 2 additions & 1 deletion terraform/aws/ecs.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module "ecs" {
source = "terraform-aws-modules/ecs/aws"
source = "terraform-aws-modules/ecs/aws"
version = "~> 6.10.0"

cluster_name = "atlas-cluster"

Expand Down
8 changes: 8 additions & 0 deletions terraform/aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ provider "aws" {
default_tags { tags = var.tags }
}

provider "aws" {
# Provider reference for account that owns Route 53 records
alias = "dns"
assume_role {
role_arn = var.dns_account_role_arn
}
}

data "aws_caller_identity" "current" {}
data "aws_region" "current" {}
data "aws_availability_zones" "available" {}
Expand Down
2 changes: 1 addition & 1 deletion terraform/aws/secretsmanager.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ resource "aws_secretsmanager_secret" "backend_secrets" {
resource "aws_secretsmanager_secret_version" "backend_secrets" {
secret_id = aws_secretsmanager_secret.backend_secrets.id
secret_string_wo = jsonencode(local.application_env)
secret_string_wo_version = 7
secret_string_wo_version = 8
}
15 changes: 7 additions & 8 deletions terraform/aws/tfvars/dev.tfvars
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
environment = "dev"
region = "us-east-1"
state_bucket = "tfstate-atlas"
domain_name = "atlas-assistant.ds.io"
environment = "dev"
region = "us-east-1"
state_bucket = "tfstate-atlas"
domain_name = "adaptationatlas.cgiar.org"
api_subdomain = "atlas-assistant-api"
cors_origins = "[\"https://adaptationatlas.github.io\"]"
cognito_redirect_urls = "[\"https://api.atlas-assistant.ds.io/docs/oauth2-redirect\",\"https://adaptationatlas.github.io/adaptation-atlas-assistant/\", \"http://localhost:5173\"]"
embeddings_directory = "/app/data/embeddings"
cognito_redirect_urls = "[\"https://adaptationatlas.github.io/adaptation-atlas-assistant/\", \"http://localhost:5173\"]"
embeddings_directory = "/app/data/embeddings"
tags = {
project = "atlas-assistant"
owner = "orbaco"
client = "cgiar"
}
16 changes: 16 additions & 0 deletions terraform/aws/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ variable "domain_name" {
EOT
}

variable "api_subdomain" {
type = string
default = ""
description = <<-EOT
Load balancer target for API backend
EOT
}

variable "dns_account_role_arn" {
type = string
default = ""
description = <<-EOT
Role to assume in DNS account to add certificate validation and load balancer reference on `domain_name` hosted zone.
EOT
}

variable "chat_model__type" {
type = string
default = ""
Expand Down
2 changes: 1 addition & 1 deletion terraform/aws/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 6.0"
version = "~> 6.0"
}
}
}
3 changes: 2 additions & 1 deletion terraform/aws/vpc.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
source = "terraform-aws-modules/vpc/aws"
version = "~> 6.5.0"

name = "atlas-vpc"
cidr = local.vpc_cidr
Expand Down
Loading