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

Question - is it possible to incorporate a single variable to a list defined in YAML. #150

Open
jorgenspange opened this issue Oct 2, 2024 · 1 comment

Comments

@jorgenspange
Copy link

Good day,

For my backup server I want to define the password in locals to leverage a data object.

module "aci" {
  source  = "netascode/nac-aci/aci"
  version = "0.9.1"
  model   = local.model
  yaml_directories = [
    "data/*",
    "data/**/*",
  ]
  manage_access_policies    = true
  manage_fabric_policies    = true
  manage_pod_policies       = true
  manage_node_policies      = true
  manage_interface_policies = true
  manage_tenants            = true
}

locals {
  model = {
    apic = {
      fabric_policies = {
        remote_locations = [{
          name = "backup_server"
          password = data.key_vault.password
        }]
      }
    }
  }
}

and my yaml file looks like this:

---
apic:
  fabric_policies:
    remote_locations:
      - name: backup_server
        hostname_ip: 192.168.1.20
        protocol: sftp
        path: /
        auth_type: password
        username: backup_user
        mgmt_epg: oob

This will try to create 2x objects that is named backup_server, is it possible to instead merge them?

br
Jørgen

@therealdoug
Copy link
Contributor

I think this has to do with the utils_yaml_merge provider, since it matches on all primitive types.

The following seems to work, but not a great solution for what I think you're trying to accomplish

locals {
  model = {
    apic = {
      fabric_policies = {
        remote_locations = [{
          name = "backup_server"
          hostname_ip = "192.168.1.20"
          protocol = "sftp"
          path = "/"
          auth_type = "password"
          username = "backup_user"
          mgmt_epg = "oob"
          password = "MuHP4ssw0rd"
        }]
      }
    }
  }
}
---
apic:
  fabric_policies:
    remote_locations:
      - name: "backup_server"
        hostname_ip: "192.168.1.20"
        protocol: "sftp"
        path: /
        auth_type: password
        username: backup_user
        mgmt_epg: oob

You could also use an environment variable

So an example would be to export the password to an environment var muh_password

---
apic:
  fabric_policies:
    remote_locations:
      - name: "backup_server"
        hostname_ip: "192.168.1.20"
        protocol: "sftp"
        path: /
        auth_type: password
        username: backup_user
        mgmt_epg: oob
        password: !env muh_password

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