Use a Heat condition to exclude item from list
Can I use a condition to exclude a part from the list of configs ina MultipartMime resource?
GOAL, If parameter 'playbook_repo' is empty string then: do not create certain resources, and do not include certain SoftwareConfig in MultipartMime user-data.
I'm trying to make my template flexible and reusable, but maybe I'm trying to be too clever.
- Custom resources snippet follows:
resource_registry: Custom::OS::Heat::SoftwareConfig::Playbook-Runner: ../user-data/playbook-runner.yaml Custom::OS::Nova::Keypair::NSA: ssh/group/nsa.yaml Custom::OS::Nova::Server::With-Volume: server/with-volume.yaml
- Heat template test-servers.yaml follows:
heat_template_version: queens parameters: ... resources: servers: type: OS::Heat::ResourceGroup depends_on: - router_internal_interface properties: count: { get_param: instance_count } resource_def: type: Custom::OS::Nova::Server::With-Volume properties: ...
- Custom::OS::Nova::Server::With-Volume: server/with-volume.yaml snippet follows:
heat_template_version: queens parameters: ... playbook_repo: type: string label: Playbook git repo description: Playbook to checkout and run via cloud-init user_data default: '' conditions: playbook_included: not: equals: - get_param: playbook_repo - '' resources: ssh_keys_admins: type: Custom::OS::Nova::Keypair::NSA # GOAL optionally do not create this: playbook_waitcondition_handle: type: OS::Heat::WaitConditionHandle condition: playbook_included # GOAL optionally do not create this: playbook_waitcondition: type: OS::Heat::WaitCondition condition: playbook_included properties: handle: { get_resource: playbook_waitcondition_handle } count: 1 timeout: 600 # GOAL optionally do not create this: playbook_runner: type: Custom::OS::Heat::SoftwareConfig::Playbook-Runner condition: playbook_included properties: playbook_notify_heat: { get_attr: [ playbook_waitcondition_handle, 'curl_cli' ] } server_init: type: OS::Heat::MultipartMime properties: parts: - config: { get_attr: [ssh_keys_admins, resource.cloud_config_ssh] } # GOAL optionally do not include the following part: - config: { get_attr: [playbook_runner, resource.playbook_runner] } instance: type: OS::Nova::Server properties: name: { get_param: instance_name } image: { get_param: image } flavor: { get_param: flavor } key_name: { get_param: key } networks: - port: { get_resource: server_port } user_data_format: RAW user_data: get_resource: server_init