ACM Certificates
Because the aws_acm_certificate resource supports so many options, (Creating an Amazon issued certificate, Importing an existing certificate, and Creating a private CA issued certificate. See acm_certificate documentation) depending on the various arguments supplied and our module of course supports referencing existing certificates in ACM using a data source, the module needs to be extremely flexible.
To accomplish this, we added a certificate_action attribute to the certificates variable that allows you to specify which action you want to take for each certificate. The options are import_certificate (default), create_amazon_issued_certificate (not yet implemented), create_private_ca_issued_certificate (not yet implemented), and reference_existing_certificate (uses data source). Depending on which action you choose, different attributes will be required or optional. Not all options are currently supported, but this should be flexible enough for us to add any additional options in the future as needed.
Create a Generic, Self-Signed Placeholder Certificate
This would typically be used for testing, development, or as a temporary certificate until a proper one can be obtained. In this example defining certificate_action is optional because it defaults to import_certificate.
Reference an Existing Certificate in ACM
This option uses a data source to look up an existing certificate in ACM that was created outside of Terraform. You can filter by domain, key types, statuses, types, and tags to find the appropriate certificate. See the data source documentation for more details on the available filters. This must only return one certificate or Terraform will output an error. If multiple certificates match the filters, consider using the most_recent attribute to get the latest one.
Import an Existing Certificate
To import an existing certificate, provide the private_key, certificate_body and optionally the certificate_chain attributes. You can define the values using heredoc syntax for better readability as shown below or use file functions to read from external files. This option is not recommended without more thought going into secret management for the private key.