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

Add vcd_catalog_access_control data source #1315

Merged
merged 9 commits into from
Sep 10, 2024

Conversation

adambarreiro
Copy link
Collaborator

Closes #1209

Adds a vcd_catalog_access_control data source to be able to read its properties from an existing Catalog.

abarreiro added 3 commits September 2, 2024 10:23
Signed-off-by: abarreiro <abarreiro@vmware.com>
#
Signed-off-by: abarreiro <abarreiro@vmware.com>
#
Signed-off-by: abarreiro <abarreiro@vmware.com>
@adambarreiro adambarreiro self-assigned this Sep 2, 2024
abarreiro added 4 commits September 2, 2024 11:21
#
Signed-off-by: abarreiro <abarreiro@vmware.com>
Signed-off-by: abarreiro <abarreiro@vmware.com>
#
Signed-off-by: abarreiro <abarreiro@vmware.com>
#
Signed-off-by: abarreiro <abarreiro@vmware.com>
@carmine73
Copy link

I guess I should manage a structure like this:

  shared_with {
    user_id      = data.vcd_org_user.ac-admin1.id
    access_level = "FullControl"
  }
  shared_with {
    user_id      = data.vcd_org_user.ac-vapp-creator2.id
    access_level = "Change"
  }
  shared_with {
    org_id       = data.vcd_org.another-org.id
    access_level = "ReadOnly"
  }

correct?

@adambarreiro
Copy link
Collaborator Author

adambarreiro commented Sep 2, 2024

I guess I should manage a structure like this:
...
correct?

Yes, with this new data source you could then do something like:

output "user_ids" {
  value = tolist(data.vcd_catalog_access_control.ac_ds.shared_with).*.user_id
}

Which could output, for example:

user_ids = tolist([
  "urn:vcloud:user:02a6354f-af65-48e3-bdb4-b863b5c48267",
  "urn:vcloud:user:915586cc-2a17-406d-a384-b895d42f66f7",
  "urn:vcloud:user:a1d7ba06-dce8-4547-aef9-90be200351ab",
])

Then you can use dynamic blocks with them, reference by index or other usages

@adambarreiro adambarreiro marked this pull request as ready for review September 3, 2024 08:36
Signed-off-by: abarreiro <abarreiro@vmware.com>
Signed-off-by: abarreiro <abarreiro@vmware.com>
@adambarreiro adambarreiro merged commit a19450d into vmware:main Sep 10, 2024
3 checks passed
@adambarreiro adambarreiro deleted the access-control-ds branch September 10, 2024 12:21
@carmine73
Copy link

I do something like this, thanks

data "vcd_catalog" "shared_catalog" {
  org   = local.org_name
  name  = local.catalog_name
}

data "vcd_catalog_access_control" "shared_catalog_ac" {
  catalog_id = data.vcd_catalog.shared_catalog.id
}

import {
  to = vcd_catalog_access_control.shared_catalog_ac
  id = "${local.org_name}.${local.catalog_name}"
}

resource "vcd_catalog_access_control" "shared_catalog_ac" {
  org        = local.org_name
  catalog_id = data.vcd_catalog.shared_catalog.id

  shared_with_everyone = false

  # catalog is already shared with these entities
  dynamic "shared_with" {
    for_each = data.vcd_catalog_access_control.shared_catalog_ac.shared_with

    content {
      access_level = shared_with.value.access_level
      group_id     = shared_with.value.group_id
      org_id       = shared_with.value.org_id
      user_id      = shared_with.value.user_id
    }
  }

  # this org added to catalog shared with
  shared_with {
    access_level = "ReadOnly"
    org_id       = vcd_org.org.id
  }
}

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

Successfully merging this pull request may close these issues.

data source vcd_catalog_access_control needed to share a catalog with more orgs
4 participants