Terraform. How to upload own certificates

I’ve generated a certificates for aws acm however I can not upload them.


Main

resource "aws_acm_certificate" "manual" {
   private_key        = var.private_key
   certificate_body   = var.certificate_body
   certificate_chain  = var.certificate_chain
}


Variables

variable "private_key" {
  type    = string
  default = ""
}

variable "certificate_body" {
  type    = string
  default = ""
}

variable "certificate_chain" {
  type    = string
  default = ""
}


Module

module "warrant"   {
   source            = "../Resources/ACM"
   private_key       = ../Local/private.key
   certificate_body  = ../Local/body.crt
   certificate_chain = ../Local/chain.crt
}

And when Terraform planning I’m getting the content of files, not their names, I’m bit confused, how to solve this issue?

Hi,

with this template, you get:

resource "aws_acm_certificate" "manual" {
   private_key        = "../Local/private.key"
   certificate_body   = "../Local/body.crt"
   certificate_chain  = "../Local/chain.crt"
}

I am confused too because this is the file names, not the content. The “aws_acm_certificate” attributes need contents, not file names. You should use the file() function to get the content set as attributes of the resource.

Something like this might work better:

resource "aws_acm_certificate" "manual" {
   private_key        = var.private_key
   certificate_body   = var.certificate_body
   certificate_chain  = var.certificate_chain
}

Module invocation:

module "warrant"   {
   source            = "../Resources/ACM"
   private_key       = file("../Local/private.key")
   certificate_body  = file("../Local/body.crt")
   certificate_chain = file("../Local/chain.crt")
}

It does not requires a content, whenever you pass a content of key(s), the attribute starts to compline that, it requires a string, and I’m not sure that, .key, .pem or .crt is pure string