milliHQ / terraform-aws-next-js

Terraform module for building and deploying Next.js apps to AWS. Supports SSR (Lambda), Static (S3) and API (Lambda) pages.
https://registry.terraform.io/modules/milliHQ/next-js/aws
Apache License 2.0
1.47k stars 151 forks source link

[Quesstion] Getting deployment-id or url after deploy as an output #354

Open MastalerzKamil opened 2 years ago

MastalerzKamil commented 2 years ago

I'm going to use tf-next into Github Action CI/CD and based on README in order to switch alias I need to have daployment-id or url to deployed app. Is there any way to get it as an output from command tf-next deploy?

khuezy commented 2 years ago

Doesn't it already output the preview url? https://github.com/milliHQ/terraform-aws-next-js/blob/main/packages/tf-next/src/commands/deploy/deploy.ts#L110

MastalerzKamil commented 2 years ago

Yes it is but I would like to take it and save into secrets in my CI/CD. I know that I could copy it manually but I need make deployment wit changing alias automatically. Based on documentation https://registry.terraform.io/modules/milliHQ/next-js/aws/1.0.0-canary.5. There isn't an output as url or deployment Id

eprokofev commented 1 year ago

It seems the project is stale...it's a pity...not usable in the real world without getting a deployment id. Only for manual deployments.

khuezy commented 1 year ago

Yeah Vercel poached our dear boy. I'd recommend using sst.dev for your infra and NextjsSite v2 for your nextjs app. It supports latest Nextjs features. https://discord.gg/sst

eprokofev commented 1 year ago

I made this construction:

resource "null_resource" "tf-next-deploy-and-promote" {
  provisioner "local-exec" {
    command = "tf-next deploy --endpoint=${module.tf_next.api_endpoint} | grep -oP '(?<=\\/\\/)(.*?)(?=undefined)' | xargs -I {} tf-next alias set ${aws_route53_record.main.fqdn} {} --force"
    working_dir = "../." #because next.js in parent folder
  }
}

In my case, tf-next deploy throws "HTTP://1234141124(some_id)123141234undefined" instead of URL. That's why I used regex '(?<=\/\/)(.*?)(?=undefined)'