VMware Cloud Community
bdamian
Expert
Expert

vRA 8.6 Template - Custom Property as a variable for constraint

I'm trying to use custom properties in a template as a strategy for a use case but isn't working. 

resources:
  Cloud_Machine_1:
    type: Cloud.Machine
    properties:
      image: Ubuntu
      flavor: small
      resourcePool: global
      constraints:
        - tag: 'project:${self.resourcePool}'

The Template fail because is trying to find a resource with the tag "project:null:hard".

What I am missing? If this doesn't work, what can I do to get the same result?

Thanks a lot.

---
Damián Bacalov
vExpert 2017-2023 (7 years)
https://www.linkedin.com/in/damianbacalov/
https://tecnologiaimasd.blogspot.com/
twitter @bdamian
Reply
0 Kudos
15 Replies
paul_xtravirt
Expert
Expert

Hey,

Try the following:

resources:
  Cloud_Machine_1:
    type: Cloud.Machine
    properties:
      image: Ubuntu
      flavor: small
      resourcePool: global
      constraints:
        - tag: ${"project:" + self.resourcePool}

 

If you found this helpful, please consider awarding some points
Reply
0 Kudos
bdamian
Expert
Expert

Same result as before...

bdamian_0-1649420553884.png

 

---
Damián Bacalov
vExpert 2017-2023 (7 years)
https://www.linkedin.com/in/damianbacalov/
https://tecnologiaimasd.blogspot.com/
twitter @bdamian
Reply
0 Kudos
paul_xtravirt
Expert
Expert

Very odd. Can you post the complete YAML on here? And which version of vRA are you running?

If you found this helpful, please consider awarding some points
Reply
0 Kudos
bdamian
Expert
Expert

The version is 8.6.2. This is the complete template:

formatVersion: 1
inputs: {}
resources:
  Cloud_Machine_1:
    type: Cloud.Machine
    properties:
      image: Ubuntu
      flavor: small
      resourcePool: global
      constraints:
        - tag: 'project:${self.resourcePool}'
      networks:
        - network: '${resource.Cloud_Network_1.id}'
          assignment: static
  Cloud_Network_1:
    type: Cloud.Network
    properties:
      networkType: existing
      constraints:
        - tag: net:dmz
---
Damián Bacalov
vExpert 2017-2023 (7 years)
https://www.linkedin.com/in/damianbacalov/
https://tecnologiaimasd.blogspot.com/
twitter @bdamian
Reply
0 Kudos
paul_xtravirt
Expert
Expert

 

 

- tag: 'project:${self.resourcePool}'

 

Try changing the property name to something that doesn't relate to an API object. For example change it to myResourcePool and see what happens

If you found this helpful, please consider awarding some points
Reply
0 Kudos
bdamian
Expert
Expert

I've used the same approach to pass data for the Cloud-Init block. But I guess that the placement evaluation is done before the replacement.

Yes, the idea is to use the value of the custom property defined in the same Template.

---
Damián Bacalov
vExpert 2017-2023 (7 years)
https://www.linkedin.com/in/damianbacalov/
https://tecnologiaimasd.blogspot.com/
twitter @bdamian
Reply
0 Kudos
paul_xtravirt
Expert
Expert

In my YAML I have this section under the virtual machine resource which is working, albeit from an input. Sorry, I cannot post the complete YAML but you should get the drift.

      constraints:
        - tag: ${"cloud.zone.environment:" + input.environment}
        - tag: '${input.environment == "non-prod" ? "cloud.account:nonprodWindows" : "cloud.account:prodWindows"}'
        - tag: cloud.zone.type:windows

 

If you found this helpful, please consider awarding some points
Reply
0 Kudos
bdamian
Expert
Expert

I've tried this and got the same result:

      myUniqueName: global
      constraints:
        - tag: 'project:${self.myUniqueName}'

For me, this is a bug.

---
Damián Bacalov
vExpert 2017-2023 (7 years)
https://www.linkedin.com/in/damianbacalov/
https://tecnologiaimasd.blogspot.com/
twitter @bdamian
Reply
0 Kudos
bdamian
Expert
Expert

The replacement work fine when you use Input variables, but not with custom properties. That is my point.

---
Damián Bacalov
vExpert 2017-2023 (7 years)
https://www.linkedin.com/in/damianbacalov/
https://tecnologiaimasd.blogspot.com/
twitter @bdamian
Tags (1)
Reply
0 Kudos
paul_xtravirt
Expert
Expert

And this?

      myUniqueName: global
      constraints:
        - tag: ${"project:" + self.myUniqueName}

This is working for me in the latest version 

If you found this helpful, please consider awarding some points
Reply
0 Kudos
paul_xtravirt
Expert
Expert

Ah, ok. Understood. I will try and test

If you found this helpful, please consider awarding some points
Reply
0 Kudos
xian_
Expert
Expert

Then use a read-only input variable with default value 'global'

Map this input to resourcePool and constraint tag

Reply
0 Kudos
bdamian
Expert
Expert

That doesn't solve my problem. And it will be visible to the user.

The idea is that I can override the Custom Property in the template for a similar custom property in the Project. It works if I use it in the Cloud-Init block, but it seams that the placement evaluation is done before the replacement.

---
Damián Bacalov
vExpert 2017-2023 (7 years)
https://www.linkedin.com/in/damianbacalov/
https://tecnologiaimasd.blogspot.com/
twitter @bdamian
Reply
0 Kudos
xian_
Expert
Expert

You can always hide an input with Custom Forms.

Also, if this is project-specific, you can use secrets to use custom values.

Reply
0 Kudos
Ankush11s
VMware Employee
VMware Employee

Resource self variables are allowed only for resources supporting the allocation phase. Resource self variables are only available (or only have a value set) after the allocation phase is complete.
Check the doc for same



I would suggest you to use input with custom form ,use the visibility option to hide it 

Reply
0 Kudos