Rename s3 bucket (#206)

* make EFS bucket per node

* Rename S3 bucket to td-devnet-bucket
This commit is contained in:
Jerome 2022-11-12 12:29:23 +11:00 committed by GitHub
parent 1ac3e9c8d9
commit fb7234c93f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 23 deletions

View file

@ -23,7 +23,9 @@ Each PR merged into `dev-upgrade` will trigger below actions:
"xdc{{NUMBER}}: {...} "xdc{{NUMBER}}: {...}
} }
``` ```
2. Access to aws console, create a bucket with name `terraform-devnet-bucket` 2. Access to aws console, create a bucket with name `tf-devnet-bucket`:
- You can choose any name, just make sure update the name in the s3 bucket name variable in `variables.tf`
- And update the name of the terraform.backend.s3.bucket from `s3.tf`
3. Upload the file from step 1 into the above bucket with name `node-config.json` 3. Upload the file from step 1 into the above bucket with name `node-config.json`
4. In order to allow pipeline able to push and deploy via ECR and ECS, we require below environment variables to be injected into the CI pipeline: 4. In order to allow pipeline able to push and deploy via ECR and ECS, we require below environment variables to be injected into the CI pipeline:
1. DOCKER_USERNAME 1. DOCKER_USERNAME

View file

@ -24,14 +24,16 @@ resource "aws_ecs_task_definition" "devnet_task_definition_group" {
# New nodes will consume a lot more CPU usage than existing nodes. # New nodes will consume a lot more CPU usage than existing nodes.
# This is due to sync is resource heavy. Recommending set to below if doing sync: # This is due to sync is resource heavy. Recommending set to below if doing sync:
# CPU = 2048, Memory = 4096 # CPU = 2048, Memory = 4096
# Please set it back to cpu 512 and memory of 2048 after sync is done to save the cost # Please set it back to cpu 256 and memory of 2048 after sync is done to save the cost
cpu = 256 # cpu = 256
memory = 2048 # memory = 2048
cpu = 2048
memory = 4096
volume { volume {
name = "efs" name = "efs"
efs_volume_configuration { efs_volume_configuration {
file_system_id = aws_efs_file_system.devnet_efs.id file_system_id = aws_efs_file_system.devnet_efs[each.key].id
root_directory = "/" root_directory = "/"
transit_encryption = "ENABLED" transit_encryption = "ENABLED"
authorization_config { authorization_config {

View file

@ -24,24 +24,29 @@ resource "aws_security_group" "devnet_efs_security_group" {
} }
resource "aws_efs_file_system" "devnet_efs" { resource "aws_efs_file_system" "devnet_efs" {
creation_token = "efs" for_each = local.devnetNodeKyes
performance_mode = "generalPurpose" creation_token = "efs-${each.key}"
throughput_mode = "bursting" performance_mode = "generalPurpose"
encrypted = "true" throughput_mode = "bursting"
tags = { encrypted = "true"
Name = "TfDevnetEfs" lifecycle_policy {
} transition_to_ia = "AFTER_30_DAYS"
}
tags = {
Name = "TfDevnetEfs${each.key}"
}
} }
resource "aws_efs_mount_target" "devnet_efs_efs_mount_target" { resource "aws_efs_mount_target" "devnet_efs_efs_mount_target" {
file_system_id = aws_efs_file_system.devnet_efs.id for_each = local.devnetNodeKyes
file_system_id = aws_efs_file_system.devnet_efs[each.key].id
subnet_id = aws_subnet.devnet_subnet.id subnet_id = aws_subnet.devnet_subnet.id
security_groups = [aws_security_group.devnet_efs_security_group.id] security_groups = [aws_security_group.devnet_efs_security_group.id]
} }
resource "aws_efs_access_point" "devnet_efs_access_point" { resource "aws_efs_access_point" "devnet_efs_access_point" {
for_each = local.devnetNodeKyes for_each = local.devnetNodeKyes
file_system_id = aws_efs_file_system.devnet_efs.id file_system_id = aws_efs_file_system.devnet_efs[each.key].id
root_directory { root_directory {
path = "/${each.key}/database" path = "/${each.key}/database"
creation_info { creation_info {

View file

@ -1,17 +1,10 @@
# This bucket had to be created before you can run the terraform init
resource "aws_s3_bucket" "terraform_s3_bucket" {
bucket = "terraform-devnet-bucket"
versioning {
enabled = true
}
}
# Bucket need to be created first. If first time run terraform init, need to comment out the below section # Bucket need to be created first. If first time run terraform init, need to comment out the below section
terraform { terraform {
backend "s3" { backend "s3" {
bucket = "terraform-devnet-bucket" bucket = "tf-devnet-bucket" // This name need to be updated to be the same as local.s3BucketName. We can't use variable here.
key = "tf/terraform.tfstate" key = "tf/terraform.tfstate"
region = "us-east-1" region = "us-east-1"
encrypt = true encrypt = true
@ -19,6 +12,6 @@ terraform {
} }
data "aws_s3_bucket_object" "devnet_xdc_node_config" { data "aws_s3_bucket_object" "devnet_xdc_node_config" {
bucket = "terraform-devnet-bucket" bucket = local.s3BucketName
key = "node-config.json" key = "node-config.json"
} }

View file

@ -15,4 +15,5 @@ locals {
devnetNodeKyes = { devnetNodeKyes = {
for i in local.keyNames: i => local.predefinedNodesConfig[i] for i in local.keyNames: i => local.predefinedNodesConfig[i]
} }
s3BucketName = "tf-devnet-bucket"
} }