Search code examples
yamlopenstack

How to use the security group existing in horizon in heat template


I'm newbies on heat yaml template loaded by OpenStack I've got this command which works fine :

openstack server create --image RHEL-7.4   --flavor std.cpu1ram1 --nic net-id=network-name.admin-network --security-group security-name.group-sec-default   value instance-name

I tried to write this heat file with the command above :

heat_template_version: 2014-10-16

description: Simple template to deploy a single compute instance with an attached volume

resources:
  my_instance:
    type: OS::Nova::Server
    properties:
      name: instance-name
      image: RHEL-7.4
      flavor: std.cpu1ram1
      networks:
        - network: network-name.admin-network
      security_group: 
        - security_group: security-name.group-sec-default

security-group: 
  type: OS::Neutron::SecurityGroup
properties:
  rules: security-name.group-sec-default

  my_volume:
    type: OS::Cinder::Volume
    properties:
      size: 10

  my_attachment:
      type: OS::Cinder::VolumeAttachment
      properties:
        instance_uuid:  { get_resource: my_instance }
        volume_id: { get_resource: my_volume }
        mountpoint: /dev/vdb

The stack creation failed with the following message error :

 openstack stack create -t my_first.yaml First_stack
 openstack stack show First_stack
.../...
   | stack_status_reason   | Resource CREATE failed: BadRequest: resources.my_instance: Unable to find security_group with name or id 'sec_group1' (HTTP 400) (Request-ID: req-1c5d041c-2254-4e43-8785-c421319060d0) 
.../...

Thanks for helping,


Solution

  • After digging, I finally found what was wrong in my heat file. I had to declare my instance like this :

    my_instance:
        type: OS::Nova::Server
        properties:
          name: instance-name
          image: RHEL-7.4
          flavor: std.cpu1ram1
          networks:
            - network: network-name.admin-network
          security_groups: [security-name.group-sec-default]
    

    Thanks for your support