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

Error: Invalid function argument #2

Open
melissajenner22 opened this issue Dec 16, 2020 · 0 comments
Open

Error: Invalid function argument #2

melissajenner22 opened this issue Dec 16, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@melissajenner22
Copy link

I got the errors below. Please help.


Error: Invalid function argument

on .terraform/modules/vpn/main.tf line 8, in resource "aws_acm_certificate" "client":
8: private_key = file("${path.root}/${var.cert_dir}/${module.this.stage}.${var.cert_domain}.key")
|----------------
| module.this.stage is ""
| path.root is "."
| var.cert_dir is "certs"
| var.cert_domain is "clientvpn.com"

Invalid value for "path" parameter: no file exists at
certs/.clientvpn.com.key; this function works only with files that are
distributed as part of the configuration source code, so if this file will be
created by a resource in this configuration you must instead obtain this
result from an attribute of that resource.

Error: Invalid function argument

on .terraform/modules/vpn/main.tf line 9, in resource "aws_acm_certificate" "client":
9: certificate_body = file("${path.root}/${var.cert_dir}/${module.this.stage}.${var.cert_domain}.crt")
|----------------
| module.this.stage is ""
| path.root is "."
| var.cert_dir is "certs"
| var.cert_domain is "clientvpn.com"

Here is my source code:
main.tf:

resource aws_security_group vpn {
  name        = module.this.id
  description = "Security group to apply to VPN target network"

  ingress {
    description = "Allow all ingress"
    from_port   = 0
    to_port     = 0
    protocol    = -1
    cidr_blocks = ["0.0.0.0/0"]
  }

  egress {
    description = "Allow all egress"
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

// VPN
module vpn {
  source = "git::https://github.com/DeployMode/terraform-aws-client-vpn.git?ref=tags/0.8.0"

  context = module.this.context

  vpn_client_cidr               = var.vpn_client_cidr
  cert_dir                      = var.cert_dir
  config_dir                    = var.config_dir
  cert_domain                   = var.cert_domain
  subnet_ids                    = data.terraform_remote_state.vpc.outputs.private_subnets
  security_groups               = [aws_security_group.vpn.id]
  logging_enabled               = var.logging_enabled
  cloudwatch_log_retention_days = var.cloudwatch_log_retention_days
}

terraform.tfvars

name = "clientvpn"
cert_domain = "clientvpn.com"
cert_dir = "certs"
config_dir = "config"
vpn_client_cidr = "60.10.0.0/16"
logging_enabled = true
cloudwatch_log_retention_days = 7

I ran, gen-certs.sh and place crt and key at the folder certs.
$ ls certs/
ca.crt server.crt server.key

@melissajenner22 melissajenner22 added the bug Something isn't working label Dec 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant