More Complete Terraform Data Sources
A
Anthony Clever
Currently, there's only one data source, for searching entities. I would like to request that we get _multiple_ terraform data sources for basically all resources, for use with features like terraform checks/validation.
As a concrete use case, currently, I have a check that uses the
data "http"
resource type to:1) Hit the access token url and get a Bearer token (this could be an ephemeral data source, please)
2) Using that token, hitting the
https://api.port.io/v1/blueprints
api endpoint to get a list of _all blueprints_, including those not managed in terraform.3) Using that response, I create a set of all blueprint identifiers both in the current workspace, as well as in my port environment. Then, assert on the difference. If there are any blueprints present that are not managed in port, the check fails the condition, and I use
setsubtract
to print a list of the blueprints that differ (and thus I need to import into terraform.With some bits removed, this looks like:
check "get_all_blueprints_and_compare_with_terraform" {
data "http" "port_all_blueprints" {
url = "https://api.port.io/v1/blueprints"
method = "GET"
request_headers = {
Accept = "application/json"
Authorization = "Bearer ${jsondecode(data.http.port_bearer_token.response_body).accessToken}"
}
}
assert {
condition = toset([
for bp in jsondecode(data.http.port_all_blueprints.response_body).blueprints : bp.identifier
]) == local.terraform_blueprint_identifiers
error_message = <<-EOT
Blueprint identifiers do not match between Port API and Terraform configuration.
Only in API: ${join(", ", setsubtract(toset([for bp in jsondecode(data.http.port_all_blueprints.response_body).blueprints : bp.identifier]), local.terraform_blueprint_identifiers))}
Only in Terraform: ${join(", ", setsubtract(local.terraform_blueprint_identifiers, toset([for bp in jsondecode(data.http.port_all_blueprints.response_body).blueprints : bp.identifier])))}
EOT
}
}
I think this could be much cleaner with a data source coming from port itself (and could be extended to other types as well, like pages).
Aidan O'Connor
Developers who use the Terraform provider to build their own aspects of Port need the ability to first query identifiers for blueprints, scorecards, and actions