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

Read multiple PEM encoded certificates when using content in a data source #352

Open
1 task done
ropnop opened this issue Apr 21, 2023 · 0 comments
Open
1 task done

Comments

@ropnop
Copy link

ropnop commented Apr 21, 2023

Terraform CLI and Provider Versions

Terraform v1.3.8
on darwin_amd64
+ provider registry.terraform.io/hashicorp/tls v4.0.4

Use Cases or Problem Statement

Allow parsing multiple PEM encoded certificates when using the content attribute in a data block.

I would like to be able to use read and store multiple certificates from a single PEM file that contains a CA chain. Given a file like this (cachain.pem)

-----BEGIN CERTIFICATE-----
MII...
...etc..
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MII...
...etc..
-----END CERTIFICATE-----

I would like to be able to load it via a data resource and reference each cert enclosed within it like so:

data "tls_certificate" "example_content" {
  content = file("cachain.pem")
}

output "num_certs" {
  value = length(data.tls_certificate.example_content.certificates)
}

Currently num_certs is 1 because the data source stops reading after the first PEM certificate in the file.

Proposal

I would like to update the Read function when using the content attribute to loop through the content and append each PEM block, instead of only reading the first valid PEM block in the content.

The resource type already stores certificates as a List type, so no other changes should be necessary. I also think this won't affect any backwards compatibility, since anyone currently using the content attribute is already referencing the data as a list with a 0 index.

How much impact is this issue causing?

Low

Additional Information

Will open a PR for this, but wanted to start an issue for the discussion/thoughts beforehand.

Code of Conduct

  • I agree to follow this project's Code of Conduct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant