1

We want to create a heat templates with servers and volumes attached to these servers. But we also want to be able to destroy all quickly servers without destroying volumes.

So we decided it would be best to make 2 heat templates instead of one : - one for volumes - one for servers and volume attachements

We would like something like that :

stack-for-volume.yml

description: project

heat_template_version: '2015-10-15'

resources:

        volume-choca-01:
                type: OS::Cinder::Volume
                properties:
                        name: volume-choca-01
                        size: 15

stack-for-servers-and-attachments.yml

description: project

heat_template_version: '2015-10-15'

resources:

        vm-choca-01:
                type: OS::Nova::Server
                properties:
                        flavor: CO.2
                        image: Centos 7
                        key_name: choca
                        name: vm-choca-01
                        networks:
                        - {network: net-ext}
                        security_groups: [default]

        volume-attachment-01:
                type: OS::Cinder::VolumeAttachment
                properties:
                        instance_uuid: { get_resource: vm-choca-01 }
                        volume_id: { get_resource: volume-choca-01 }

Of course since all resources are not in the same file: volume_id: { get_resource: volume-choca-01 } can't work.

We tried to get the volume_id with the solution posted here : Openstack Heat - separate templates by adding at the end stack-for-volume.yml :

outputs:
        volume-choca-01-id:
                description: something
                value: { get_attr: [volume-choca-01] }

But the output didn't give us anything looking like the volume id. We´re stuck right now.

Any idea ?

zechocapic
  • 11
  • 2

1 Answers1

0

OpenStack Heat:

When the stack is created with the resources defined in the template/nested templates, all the resources are terminated/deleted when the stack is deleted by user.

So as per your requirement/question, you can try like this:

Step-1: Create the volume using the heat template

Step-2: Get the volume UUID from the dashboard/horizon and assign to volume_id in the OS::Cinder::VolumeAttachment resource like:

         volume-attachment-01:
            type: OS::Cinder::VolumeAttachment
            properties:
                    instance_uuid: { get_resource: vm-choca-01 }
                    volume_id: { get_param: volume-choca-01_UUID }

And in the parameters define the volume-choca-01_UUID param:

 parameters:
   volume-choca-01_UUID:
      type: string
      default: <UUID of volume from dashboard>

With the above process the server is created and volume is attached to it. When you delete the stack the volume is detached instead of getting deleted with server