Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fresh install and setup, terraform plan error #310

Open
jeremyrajan opened this issue May 2, 2022 · 11 comments
Open

Fresh install and setup, terraform plan error #310

jeremyrajan opened this issue May 2, 2022 · 11 comments
Labels
question Question about usage of the library

Comments

@jeremyrajan
Copy link

jeremyrajan commented May 2, 2022

Hello @ofhouse ,

I have been trying to implement it as per readme, but constantly getting this error:

 Error: invalid value for name (must match [\w+=,.@-])
│
│   with module.tf_next.aws_iam_role.lambda["app/__NEXT_PAGE_LAMBDA_0"],
│   on .terraform/modules/tf_next/iam.tf line 20, in resource "aws_iam_role" "lambda":
│   20:   name        = "${var.deployment_name}_${each.key}"
│
╵
╷
│ Error: invalid value for name (must match [\w+=,.@-])
│
│   with module.tf_next.aws_iam_role.lambda["app/__NEXT_API_LAMBDA_0"],
│   on .terraform/modules/tf_next/iam.tf line 20, in resource "aws_iam_role" "lambda":
│   20:   name        = "${var.deployment_name}_${each.key}"
│
╵
╷
│ Error: invalid value for function_name (must be valid function name or function ARN)
│
│   with module.tf_next.aws_lambda_permission.current_version_triggers["app/__NEXT_API_LAMBDA_0"],
│   on .terraform/modules/tf_next/main.tf line 94, in resource "aws_lambda_permission" "current_version_triggers":
│   94:   function_name = "${var.deployment_name}_${each.key}"
│
╵
╷
│ Error: invalid value for function_name (must be valid function name or function ARN)
│
│   with module.tf_next.aws_lambda_permission.current_version_triggers["app/__NEXT_PAGE_LAMBDA_0"],
│   on .terraform/modules/tf_next/main.tf line 94, in resource "aws_lambda_permission" "current_version_triggers":
│   94:   function_name = "${var.deployment_name}_${each.key}"

any idea?

Thank you! :)

@jeremyrajan
Copy link
Author

Terraform:

Terraform v1.1.9
on darwin_arm64
+ provider registry.terraform.io/hashicorp/aws v4.12.1
+ provider registry.terraform.io/hashicorp/external v2.2.2
+ provider registry.terraform.io/hashicorp/local v2.2.2
+ provider registry.terraform.io/hashicorp/null v3.1.1

@ofhouse
Copy link
Member

ofhouse commented May 2, 2022

Hi, looks like your deployment_name input variable contains a character that cannot be used as function name for AWS Lambda.

module "tf_next" {
  source = "milliHQ/next-js/aws"
  ...
  deployment_name = "xxx" # <-- This here
}

@ofhouse ofhouse added the question Question about usage of the library label May 2, 2022
@jeremyrajan
Copy link
Author

Hello, I tried without it because i saw it was falling back to a value in the TF file. I also tried putting just demo. But still failed :(

@jeremyrajan
Copy link
Author

jeremyrajan commented May 2, 2022

I then updated my local code and removed _${each.key} from function_name = "${var.deployment_name}_${each.key}". And did the same in iam.tf and now its happy :/

#iam.tf
resource "aws_iam_role" "lambda" {
  for_each = local.lambdas

  name        = "${var.deployment_name}"
  description = "Managed by Terraform Next.js"

  permissions_boundary = var.lambda_role_permissions_boundary

  assume_role_policy = data.aws_iam_policy_document.assume_role.json

  tags = var.tags
}

Above is my newer version

@ofhouse
Copy link
Member

ofhouse commented May 2, 2022

Ah I see, it's because you are using the basePath setting.
This adds the basePath in the form of <basePath>/<LambdaName>, but the / character is not allowed in function names.

Same issue as #288

@jeremyrajan
Copy link
Author

Ahh okok! Any way to bypass without having a local copy of the lib? :)

@ofhouse
Copy link
Member

ofhouse commented May 2, 2022

Not without an update to the module unfortunately.
Would probably enough to insert a method that replaces / with _ for the value in each.key.

@jeremyrajan
Copy link
Author

No worries! That helps :)

@jeremyrajan
Copy link
Author

I removed the basePath temporarily for now and it did work, till it got stuck on a quote for concurrent requests. Waiting for that now :).

In the meantime, can I ask if there is a way to sponsor the project? :)

@ofhouse
Copy link
Member

ofhouse commented May 2, 2022

There is no way to sponsor the project, but I am working to establish a sustainable business model for it.
Currently working towards the v1.0.0 release that will include support for unlimited parallel deployments.

While the module itself will stay free, I plan to offer a plugin on top of it that provides a better integration for GitHub/GitLab and the Hashicorp stack.
Basically something like the preview deployments that Netlify & Vercel offer, but self-hosted 😬

Yeah, the problem with concurrent requests is also something that will be resolved with v1.0.0 release, because we don't have to ensure that only one deployment is running at a time.

@jeremyrajan
Copy link
Author

Sounds good! Let me know, where we can help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question about usage of the library
Projects
None yet
Development

No branches or pull requests

2 participants