rlabinot
Enthusiast
Enthusiast

Customize Blueprint to add a network with a ternary condition

Jump to solution

Hello,

I want my blueprint to add a second network only if the value is "linux".

Here is an example :

  resources:

  Cloud_vSphere_Machine_1:

    type: Cloud.vSphere.Machine

    properties:

      image: '${input.image}'

      networks:

        - network: '${resource.Cloud_vSphere_Network_1.id}'

        - network: '${resource.Cloud_vSphere_Network_2.id}'

  Cloud_vSphere_Network_1:

    type: Cloud.vSphere.Network

    properties:

      networkType: existing

  Cloud_vSphere_Network_2:

    type: Cloud.vSphere.Network

    properties:

      networkType: existing

      count: '${input.image == "linux" ? 1 : 0 }

vRA8 indicates an error on the second network line saying that it can't create a network on the existing condition. Is there a way to do that ?

1 Solution

Accepted Solutions
dbis7575
Enthusiast
Enthusiast

If you have more than one network resource and one or more have a count property the interface will give an error when trying to link them to your machine resource.

You can manually add the following:

networks: '${map_to_object(resource.Cloud_vSphere_Network_1[*].id + resource.Cloud_vSphere_Network_2[*].id, "network")}'

or if you have to add additional properties (i.e. static ip assignment):

networks: '${map_by(resource.Cloud_vSphere_Network_1[*].id + resource.Cloud_vSphere_Network_2[*].id, id => {"network":id, "assignment":"static"})}'

View solution in original post

7 Replies
dbis7575
Enthusiast
Enthusiast

If you have more than one network resource and one or more have a count property the interface will give an error when trying to link them to your machine resource.

You can manually add the following:

networks: '${map_to_object(resource.Cloud_vSphere_Network_1[*].id + resource.Cloud_vSphere_Network_2[*].id, "network")}'

or if you have to add additional properties (i.e. static ip assignment):

networks: '${map_by(resource.Cloud_vSphere_Network_1[*].id + resource.Cloud_vSphere_Network_2[*].id, id => {"network":id, "assignment":"static"})}'

View solution in original post

rlabinot
Enthusiast
Enthusiast

Tanks for your reply, here is many tests that I have done to have two networks if linux machine is selected :

- One machine and one network with count property --> not possible to have "2" as a value for count, so not solving the problem

- One machine and two networks (one mandatory network without count property, the other optional network with count property) --> Works but with many specificity

resources:

  Cloud_vSphere_Machine_1:

    type: Cloud.vSphere.Machine

    properties:

      image: '${input.image}'

      networks: '${map_to_object(resource.Cloud_vSphere_Network_1[*].id + resource.Cloud_vSphere_Network_2[*].id, "network")}'

  Cloud_vSphere_Network_1:

    type: Cloud.vSphere.Network

    properties:

      networkType: existing

  Cloud_vSphere_Network_2:

    type: Cloud.vSphere.Network

    properties:

      networkType: existing

      count: '${input.image == "linux" ? 1:0}'

The [*] at the networks resources name is mandatory because the "networks" property asks string array. So even "Network_1" hasn't the "count" property, you must indicate the [*].

Where did you find these function as "map_to_object" ? And this particular syntax ? Do you have any documentation about these for blueprints ?

0 Kudos
xian_
Hot Shot
Hot Shot

Just did a quick search, it's in the vRealize Automation 8.1 Release Notes

0 Kudos
rlabinot
Enthusiast
Enthusiast

I am not yet in 8.1 but will do the upgrade asap.

Thanks for your help

0 Kudos
xian_
Hot Shot
Hot Shot

Looks like this was already documented in vRealize Automation 8.0 Release Notes as well, so should work for you without upgrading.

0 Kudos
rlabinot
Enthusiast
Enthusiast

Don't worry, I need this upgrade for the other features.

0 Kudos
dbis7575
Enthusiast
Enthusiast

map_to_object is referenced in the release notes for the disk object and it works the same for the network objects. As far as adding the other maps (i.e. static assignment) I had problems with that and was able to resolve that with tech support.