Skip to content

Commit

Permalink
[terraform][blob] Use different S3 bucket for staging
Browse files Browse the repository at this point in the history
Summary:
Modified the blob service ECS task to:
- Use the "latest" tag for staging Docker image
- Add `BLOB_S3_BUCKET_NAME` environment variable to the task definition that uses the bucket name suffix introduced in D8714

Depends on D8742, D8714

Test Plan:
Ran `terraform plan` in staging:
```
 # aws_ecs_task_definition.blob_service must be replaced
-/+ resource "aws_ecs_task_definition" "blob_service" {
      ~ container_definitions    = jsonencode(
          ~ [
              ~ {
                  - cpu              = 0
                  ~ environment      = [
                      + {
                          + name  = "BLOB_S3_BUCKET_NAME"
                          + value = "commapp-blob-staging"
                        },
                        {
                            name  = "RUST_LOG"
                            value = "info"
                        },
                    ]
                  ~ image            = "commapp/blob-server:0.2.0" -> "commapp/blob-server:latest"
                    name             = "blob-service-server"
                    # (2 unchanged attributes hidden)
                },
            ] # forces replacement
        )
      ~ id                       = "blob-service-task-def" -> (known after apply)
      ~ revision                 = 1 -> (known after apply)
        # (9 unchanged attributes hidden)
    }
```

To be done after other terraform diffs in this stack are applied:
- Build docker image for staging (with "latest" tag), with D8742 applied
- Apply this TF change to redeploy blob service
- Look at ECS task logs - there should be a note: `INFO blob::config: Using custom S3 bucket: commapp-blob-staging`

Reviewers: jon, varun

Reviewed By: jon

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D8743
  • Loading branch information
barthap committed Aug 8, 2023
1 parent b683fcc commit 0e55529
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion services/terraform/remote/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ provider "aws" {
}
}

locals {
# S3 bucket names are globally unique so we add a suffix to staging buckets
s3_bucket_name_suffix = local.is_staging ? "-staging" : ""
}

# Shared resources between local dev environment and remote AWS
module "shared" {
source = "../modules/shared"
bucket_name_suffix = local.is_staging ? "-staging" : ""
bucket_name_suffix = local.s3_bucket_name_suffix
}

7 changes: 6 additions & 1 deletion services/terraform/remote/service_blob.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
locals {
blob_service_image_tag = "0.2.0"
blob_service_image_tag = local.is_staging ? "latest" : "0.2.0"
blob_service_container_name = "blob-service-server"
blob_service_server_image = "commapp/blob-server:${local.blob_service_image_tag}"
blob_service_container_http_port = 51001
blob_service_container_grpc_port = 50051
blob_service_grpc_public_port = 50053
blob_service_domain_name = "blob.${local.root_domain}"
blob_service_s3_bucket = "commapp-blob${local.s3_bucket_name_suffix}"
}

resource "aws_ecs_task_definition" "blob_service" {
Expand Down Expand Up @@ -33,6 +34,10 @@ resource "aws_ecs_task_definition" "blob_service" {
{
name = "RUST_LOG"
value = "info"
},
{
name = "BLOB_S3_BUCKET_NAME",
value = local.blob_service_s3_bucket
}
]
logConfiguration = {
Expand Down

0 comments on commit 0e55529

Please sign in to comment.