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

Get Subnets from Bridge Domain DN #727

Closed
mingjliu9 opened this issue Nov 5, 2021 · 3 comments
Closed

Get Subnets from Bridge Domain DN #727

mingjliu9 opened this issue Nov 5, 2021 · 3 comments
Assignees

Comments

@mingjliu9
Copy link

Description

I want to get subnets with bridge domain/EPG dn as input parameter, so that my terraform module could work well to pass subnets as input parameter to other terraform resources.

New or Affected Resource(s) + ACI Class(es):

New data source expected:
aci_egp_subnets
or
aci_bd_subnets

APIC version and APIC Platform

  • V 4.2(7I) and on-prem/cloud-aws/cloud-azure/all.

Potential Terraform Configuration

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key.
data aci_bd_subnets "my_subnets" {
  parent_dn         = "${aci_bridge_domain.example.id}"
}

resource myprovider_myresource example {
  subnets = data.aci_bd_subnets.my_subnets
}
@akinross akinross self-assigned this Aug 30, 2023
@akinross
Copy link
Collaborator

HI @mingjliu9,

We currently do not support class querying in the data sources or expose the fvSubnet as part of the parent resource/datasource. You could leverage aci_rest datasource for your described scenario. See example below where you would need to set "parent_dn_bd" and "parent_dn_epg" to respective parent DNs that you would like to query.

locals {
  parent_dn_bd = "uni/tn-abr_tenant/BD-abr_bd.json"
  parent_dn_epg = "uni/tn-abr_tenant/ap-abr_ap/epg-abr_epg.json"
}

data "aci_rest" "bd_subnets" {
  path       = "api/mo/${local.parent_dn_bd}?rsp-subtree=children&rsp-subtree-class=fvSubnet"
}

data "aci_rest" "epg_subnets" {
  path       = "api/mo/${local.parent_dn_epg}?rsp-subtree=children&rsp-subtree-class=fvSubnet"
}

locals {
  bd_subnets = [for child in tolist(data.aci_rest.bd_subnets.children) : child.child_content.ip]
  epg_subnets = [for child in tolist(data.aci_rest.epg_subnets.children) : child.child_content.ip]
}

output "bd_subnets" {
  value = local.bd_subnets
}

output "epg_subnets" {
  value = local.epg_subnets
}

The output would look like example below.

bd_subnets = [
  "1.1.1.1/24",
  "1.1.2.1/24",
  "1.1.3.1/24",
]
epg_subnets = [
  "2.1.1.1/32",
  "2.1.2.1/32",
]

@lhercot
Copy link
Member

lhercot commented Sep 14, 2023

@mingjliu9 does Akini's answer fixed your issue?

@akinross
Copy link
Collaborator

Hi @mingjliu9,

I have added a new issue as seen above to create more generic HCL examples for our resources. Will proceed with closure. In case you have additional questions please let us know. Also if you have other use-cases that you feel should be part of the generic guides feel free to comment on the raised issue.

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

3 participants