heat_template_version: 2015-04-30

description: >
  OpenStack compute node post deployment for Puppet.

parameters:
  ConfigDebug:
    default: false
    description: Whether to run config management (e.g. Puppet) in debug mode.
    type: boolean
  servers:
    type: json
  RoleData:
    type: json
    default: {}
  DeployIdentifier:
     type: string
     description: Value which changes if the node configuration may need to be re-applied

resources:

  ComputeArtifactsConfig:
    type: deploy-artifacts.yaml

  ComputeArtifactsDeploy:
    type: OS::Heat::StructuredDeployments
    properties:
      servers:  {get_param: servers}
      config: {get_resource: ComputeArtifactsConfig}
      input_values:
        update_identifier: {get_param: DeployIdentifier}

  ComputePuppetConfig:
    type: OS::Heat::SoftwareConfig
    properties:
      group: puppet
      options:
        enable_debug: {get_param: ConfigDebug}
        enable_hiera: True
        enable_facter: False
      inputs:
      - name: step
      outputs:
      - name: result
      config:
        list_join:
        - ''
        - - get_file: manifests/overcloud_compute.pp
          - {get_param: [RoleData, step_config]}

  ComputeServicesBaseDeployment_Step2:
    type: OS::Heat::StructuredDeployments
    depends_on: [ComputeArtifactsDeploy]
    properties:
      name: ComputeServicesBaseDeployment_Step2
      servers:  {get_param: servers}
      config: {get_resource: ComputePuppetConfig}
      input_values:
        step: 2
        update_identifier: {get_param: DeployIdentifier}

  ComputeOvercloudServicesDeployment_Step3:
    type: OS::Heat::StructuredDeployments
    depends_on: ComputeServicesBaseDeployment_Step2
    properties:
      name: ComputeOvercloudServicesDeployment_Step3
      servers:  {get_param: servers}
      config: {get_resource: ComputePuppetConfig}
      input_values:
        step: 3
        update_identifier: {get_param: DeployIdentifier}

  ComputeOvercloudServicesDeployment_Step4:
    type: OS::Heat::StructuredDeployments
    depends_on: ComputeOvercloudServicesDeployment_Step3
    properties:
      name: ComputeOvercloudServicesDeployment_Step4
      servers:  {get_param: servers}
      config: {get_resource: ComputePuppetConfig}
      input_values:
        step: 4
        update_identifier: {get_param: DeployIdentifier}

  # Note, this should come last, so use depends_on to ensure
  # this is created after any other resources.
  ExtraConfig:
    depends_on: ComputeOvercloudServicesDeployment_Step4
    type: OS::TripleO::NodeExtraConfigPost
    properties:
        servers: {get_param: servers}