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

How to get details of current provider (in module) #785

Closed
jgeorgeson opened this issue Jun 25, 2019 · 2 comments
Closed

How to get details of current provider (in module) #785

jgeorgeson opened this issue Jun 25, 2019 · 2 comments

Comments

@jgeorgeson
Copy link

I'm trying to write some modules for OpenStack resources, and the openstack_compute_instance_v2 resource doesn't take a project/tenant argument. Instead it seems to only create the instance in the project authenticated to in the provider configuration.

Within the module, I would like to up at least the project that I'm authenticated against. While I can pass the project name to each module use the data source by name, but I'd prefer if there is a way to do access the provisioner details or use a data source on the current provisioner.

Terraform Version

$ terraform --version
Terraform v0.11.14
+ provider.openstack v1.19.0

Terraform Configuration Files

Caller

provider "openstack" {
  alias       = "project"
  auth_url    = "${var.openstack_auth_url}"
  tenant_name = "myproject"
}

module "instances-rh7-2d" {
  source = "..."

  providers = {
    openstack = "openstack.project"
  }

  network_name       = "tenant-net-rd"
  instances          = 3
  image              = "com.lgc.rhel7.base-0.4"
  flavor             = "2d.large"
  key_name           = "devops_ansible_key"
}

Module

data "openstack_compute_instance_v2" "current" {
    current = true
}

Using the data resource with no arguments appears to return the full list of projects visible to the user I'm authenticating as.

References

hashicorp/terraform#9221

@jtopjian
Copy link
Contributor

the openstack_compute_instance_v2 resource doesn't take a project/tenant argument. Instead it seems to only create the instance in the project authenticated to in the provider configuration.

This is correct. The OpenStack Compute API does not support project scoping per resource like the Networking API does.

The openstack_identity_auth_scope_v3 data source will retrieve information about the current authenticated use (ie: the user configured in the provider). Does this help?

@jgeorgeson
Copy link
Author

Wellllll that's exactly what I was looking for! With the amount of googling I did over the last two days I'm rather annoyed I didn't happen upon that myself. Thanks.

PS - I meant to put data "openstack_identity_project_v3" "current" in the example module code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants