[Docs]: Add support for package version overrides on aws_amplify_app resource
#27,768 opened on Nov 11, 2022
Repository metrics
- Stars
- (11,045 stars)
- PR merge metrics
- (PR metrics pending)
Description
Documentation Link
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/amplify_app
Description
As stated on the AWS official Amplify Build Settings docs the Node version used is the latest one unless something else is specified on the package.json. While having on Amplify a different version than the package.json file could be not the best practice, there might be a need for overriding this for some builds. The steps for doing this are very well explained on the official AWS next (with Next.js instead of Node but still the same) Updating the Next.js version for an existing app.
While looking at the aws_amplify_app docs there are no indications about how to do that, so we usually ended up adding this manually and getting the changes from the plan. What essentially is needed, is to add the following code block
environment_variables = {
"_LIVE_UPDATES" = jsonencode([
{
pkg = "<package-name>"
type = "<package-type>"
version = "<package-version>"
},
])})
Used as the following example:
environment_variables = {
"_LIVE_UPDATES" = jsonencode([
{
pkg = "node"
type = "nvm"
version = "9"
},
])})
Note 1: Please note that this might not only apply for Node.js versions but for other package version overrides as the ones that are allowed on Amplify
Note 2: If you think about it, the _LIVE_UPDATES env-var could also be an independent map outside the environment_variables and moreover could be a standalone resource to override package versions.
resource "aws_amplify_app" "main" {
name = "myapp"
....
}
resource "aws_amplify_app_build_settings" "main" {
app_id = aws_amplify_app.main.id
build_settings = {
custom_image = ${_CUSTOM_IMAGE}
live_setting = ${_LIVE_UPDATES}
....
}
References
Build Settings Updating the Next.js version for an existing app Relates to https://github.com/hashicorp/terraform-provider-aws/issues/27319
Would you like to implement a fix?
No