CiscoDevNet / terraform-provider-intersight

Cisco Intersight Terraform
Mozilla Public License 2.0
19 stars 27 forks source link

[ISSUE] Filter argument missing from Data Source: intersight_softwarerepository_catalog #243

Closed sandkum5 closed 1 month ago

sandkum5 commented 1 year ago
Description
data "intersight_softwarerepository_catalog" "repo_catalog" {
  name = "user-catalog"
  # filter = "Organization/Moid eq '${data.intersight_organization_organization.org.results[0].moid}'"
}
Terraform-provider-intersight version

❯ terraform providers -version Terraform v1.4.6 on darwin_arm64

scotttyso commented 9 months ago

@sandkum5

Have you tested using the additional_attributes = jsonencode(filter = "Organization/Moid eq '${data.intersight_organization_organization.org.results[0].moid}')

cwilloughby-bw commented 7 months ago

Bumping this, the filter parameter doesn't seem to be present on any data sources I've spot-checked so far. additional_attributes isn't a supported parameter on any of them either. I've tested with:

scotttyso commented 5 months ago

@cwilloughby-bw & @sandkum5 Although you can't use the filter on the data object you can parse the data when it comes back to do a comparison to figure out the Correct organization.

I have accomplished in two different methods. One like this:

      moid = contains(keys(lookup(local.policies, policy_bucket.value.policy, {})), "${policy_bucket.value.org}/${policy_bucket.value.name}"
        ) == true ? local.policies[policy_bucket.value.policy]["${policy_bucket.value.org}/${policy_bucket.value.name}"
        ] : [for i in data.intersight_search_search_item.policies[policy_bucket.value.policy
          ].results : i.moid if jsondecode(i.additional_properties).Name == policy_bucket.value.name && jsondecode(i.additional_properties
      ).Organization.Moid == var.orgs[policy_bucket.value.org]][0]

The other method that I have recently come back to is compiling the data in locals and making the key of the object to include the organization and look it up that way. i.e.

  policies_data = { for k in keys(data.intersight_search_search_item.policies) : k => {
    for e in lookup(data.intersight_search_search_item.policies[k], "results", []
      ) : "${local.org_names[jsondecode(e.additional_properties).Organization.Moid]}/${jsondecode(e.additional_properties).Name}" => merge({
        additional_properties = jsondecode(e.additional_properties)
        moid                  = e.moid
    })
  } }

Now when I look it up in policy_bucket it is much easier to use.

      moid = contains(keys(lookup(local.policies, policy_bucket.value.policy, {})), policy_bucket.value.name
      ) == true ? local.policies[policy_bucket.value.policy][policy_bucket.value.name] : local.policies_data[policy_bucket.value.policy][policy_bucket.value.name].moid
      object_type = policy_bucket.value.object_type
mohamuni commented 1 month ago

Hi @sandkum5 , We can achieve the operation requested by you in follow example mentioned below, This works with latest terraform version.

For intersight_softwarerepository_catalog

data "intersight_organization_organization" "organization" {
  name = "default"
}

data "intersight_softwarerepository_catalog" "sw_catalog" {
  organization {
    moid = data.intersight_organization_organization.organization.id
  }  
  name = "user-catalog"
}

For intersight_firmware_server_configuration_utility_distributable Organization can be associated with Software repository by selecting a catalog under required organization. In hierarchy of relationship of Software repository with Organization is that Software Repository has relationship with Catalog which in turns has relationship with Organization.

data "intersight_organization_organization" "organization" {
  name = "default"
}

data "intersight_softwarerepository_catalog" "catalog"{
  organization {
    class_id = "organization.Organization"
    moid = data.intersight_organization_organization.organization.id
  }
}

data "intersight_firmware_server_configuration_utility_distributable" "scufilter" {
  name = "SCU-6.0.4c nfs"
  catalog {
    moid        = data.intersight_softwarerepository_catalog.catalog.results[0].moid
    object_type = "softwarerepository.Catalog"
  }
}
the-akhil-nair commented 1 month ago

This issue is fixed in latest release(1.0.56). The association of organization SCU is also mentioned in the comments. Please try and let us know. Closing the issue now. If bug persists please re-open the issue.