How to use condition for resource creation via heat template

1k views Asked by At
heat_template_version: 2017-02-24
......
......
......
conditions:
    port_security_enabled:
        equals:
            - { get_param: port_security_enabled }
            - "true"

resources:
    port:
        type: OS::Neutron::Port
        properties:
            admin_state_up: true
            network_id: { get_param: internal_net }
            port_security_enabled: { get_param: port_security_enabled }
            security_groups: { get_param: security_group }

I want to create a condition , so if I set "port_security_enabled = false" security group will not apply in port.properties . If I set "port_security_enabled = true" then security group will applied.

Please help me

2

There are 2 answers

1
xgr On

This may work fine:

security_groups: {if: [port_security_enabled, [{get_resource: security_group}], []]}
0
Munna On

I have found a solution.

I have created two port 1 is with Security Group and another one is without security group.


conditions:

    port_security_disable: {equals : [{get_param: port_security_enabled}, "disabled"]}

resources:
    port1:
        type: OS::Neutron::Port
        properties:
            admin_state_up: true
            network_id: { get_param: internal_net }
            security_groups:
                - { get_param: security_group }
    port2:
        type: OS::Neutron::Port
        properties:
            admin_state_up: true
            network_id: { get_param: internal_net }
            port_security_enabled: false

    instance_floatingip:
        type: OS::Neutron::FloatingIP
        properties:
            floating_network_id: { get_param: public_network_id }
            port_id: {if: ["port_security_disable", { get_resource: port2 }, { get_resource: port1 } ]}

    instance:
        properties:
            networks:
                - port: {if: ["port_security_disable", { get_resource: port2 }, { get_resource: port1 } ]}

I know its getting complex. but I did not found any easiest solution.