data source for region to return the current region
Hi all,
There are multiple usecases where, inside a module, one will need to query the current region. We'll need something similar to what AWS provides - provider datasources: https://www.terraform.io/docs/providers/aws/d/region.html
Thanks
@cosmindev thanks for the request! could you please add an example of the usecase you are trying to address with the enhancement?
As for now I think there are two possible ways to get the region value for the existing provider:
- provider configuration contains the region value
- oci_identity_region_subscriptions datasource can be used to get the list of the regions per tenancy and the home region value, you can find an example here: https://github.com/terraform-providers/terraform-provider-oci/blob/master/examples/identity/region.tf
@afedorch - thanks for the reply. The use case will be to access the provider details from inside a tf module. The module can take as a parameter the provider(a custom provider) and it will be redundant to duplicate the provider parameters as standalone parameters to a module.
@afedorch - Here's a nearly complete example of my particular use case (which is a more specific form of @cosmindev 's explanation)
The data source would allow me to stop (redundantly) passing in the region and home region as input variables. (Note: I realize I could pass in the tenancy id and lookup the home_region via the tenancy data source, but passing in the home region name itself just eliminated that extra step.)
In a perfect world, I wish we could attach some sort of metadata to the provider blocks in Terraform (in general ... not just for OCI) and the reference them in modules. But it doesn't look Hashicorp is interested in that (according to some closed issues I found.) So this would fit my specific use case.
provider "oci" {
region = "me-jeddah-1"
}
provider "oci" {
alias = "home"
region = "eu-frankfurt-1"
}
data "oci_region" "default" {}
data "oci_region" "home" {
provider = oci.home
}
resource "null_resource" "bootoci_secret" {
name = "test"
region = data.oci_region.default.name
compartment_id = var.compartment_id
vault_id = var.vault_id
key_id = var.key_id
secret = "not really a secret"
provisioner "local-exec" {
command = <<-EOF
oci --region ${self.triggers.region} vault secret create-base64 \
--compartment-id ${self.triggers.compartment_id} \
--vault-id ${self.triggers.vault_id} \
--secret-name ${self.triggers.name} \
--secret-content-content ${base64encode(self.triggers.secret)} \
--key-id ${self.triggers.key_id} \
--wait-for-state ACTIVE \
--wait-for-state FAILED
EOF
}
}
resource "null_resource" "key_upload" {
triggers = {
region = data.oci_region.home.name
user = var.user_id
key = var.public_key_pem
}
depends_on = [
oci_identity_user.bootoci,
tls_private_key.bootoci
]
provisioner "local-exec" {
command = <<-EOF
oci --region ${self.triggers.region} iam user api-key upload \
--user-id ${self.triggers.user} \
--key "${self.triggers.key}"
EOF
}
}
This would be possible if oci_identity_regions had a return value that was actually useful and parseable by Terraform. There's no way to retrieve a map item from a list in Terraform based on a key/value of one of those map elements.
We are very sorry that we couldn't respond to each and every issue reported on GitHub. Although we have refined the process to prioritize customer issues on GitHub, since this issue was reported a while ago, there is a good chance it may have been fixed in the latest version of Terraform Provider OCI. If you are still experiencing this issue, please create a new issue and label it as Bug.