Skip to content

Commit

Permalink
No more auto-run build; won't work on TFCloud
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhoo committed Jan 1, 2024
1 parent 641eda3 commit 2050eb7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
14 changes: 4 additions & 10 deletions infra/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,17 @@ resource "aws_iam_role_policy" "dynamodb" {
policy = data.aws_iam_policy_document.dynamodb.json
}

resource "terraform_data" "cargo_lambda" {
triggers_replace = {
cargo_toml = "${base64sha256(file("${path.module}/../server/Cargo.toml"))}"
main_rs = "${base64sha256(file("${path.module}/../server/src/main.rs"))}"
}

provisioner "local-exec" {
command = "cargo lambda build --release --arm64"
working_dir = "../server"
check "lambda-built" {
assert {
condition = fileexists("${path.module}/../server/target/lambda/wewerewondering-api/bootstrap")
error_message = "Run `cargo lambda build --release --arm64` in ../server"
}
}

data "archive_file" "lambda" {
type = "zip"
source_file = "${path.module}/../server/target/lambda/wewerewondering-api/bootstrap"
output_path = "lambda_function_payload.zip"
depends_on = [terraform_data.cargo_lambda]
}

resource "aws_lambda_function" "www" {
Expand Down
16 changes: 5 additions & 11 deletions infra/static.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,15 @@ resource "aws_s3_bucket_policy" "cloudfront" {
policy = data.aws_iam_policy_document.cloudfront_s3.json
}

resource "terraform_data" "npm_build" {
triggers_replace = {
package_json = "${base64sha256(file("${path.module}/../client/package.json"))}"
index_html = "${base64sha256(file("${path.module}/../client/index.html"))}"
}

provisioner "local-exec" {
command = "npm run build"
working_dir = "../client"
check "static-built" {
assert {
condition = fileexists("${path.module}/../client/dist/index.html")
error_message = "Run `npm run build` in ../client"
}
}

resource "aws_s3_object" "dist" {
depends_on = [terraform_data.npm_build]
for_each = fileset("${path.module}/../client/dist", "**")
for_each = fileset("${path.module}/../client/dist", "**")

force_destroy = true
bucket = aws_s3_bucket.static.id
Expand Down

0 comments on commit 2050eb7

Please sign in to comment.