Solved

How to use Variable Types from the library?

  • 12 January 2024
  • 9 replies
  • 126 views

I would like to create variables that are reusable in blueprints - things like package store URI, proxy URL, etc. I don’t think it makes sense to define these in every blueprint, as they’re identical; we want to keep that kind of thing DRY.

The docs state that Variable Types defined in the Library are reusable across blueprints. But if I define MY_VAR as a new Variable Type with a value, it has no value when expanded in a blueprint script as @@{MY_VAR}@@

What is the trick to defining these vars at the Library level and using them in Blueprints?

 

Thanks!

icon

Best answer by Avico 14 January 2024, 16:56

View original

This topic has been closed for comments

9 replies

 

Hi mcascone


I am using a variable type saved in the library with a value.

Then in a BP named test I’m adding a new variable named test with the type selected as my library var type.

In a BP’s task I reference it as “@@{test}@@” and it does contain the value configured in the library.

 

Ah, that makes sense. It’s like an env var but you still have to declare it if you want to use it. And the default value is inherited from the library? I assume it can be overridden at the blueprint level too?

thank you!

Exactly

If you put a different value, it will be overridden.

The real value for creating variable types is where you need to configure regex validations (go remember the regex code for email format for example...)

Also, if you have a variable with multi-input pre-defined list that you use in many of your BPs.

It will save you that kind of painstaking labor, or too much googling for regex codes :-)

 

There doesn’t seem to be a way to hide any of these global values as a secret? I don’t want to have to put a password in every blueprint, for example. Or i want the password to differ between environments. Isn’t there a way to set a higher-level variable as a secret?

Userlevel 4
Badge +5

For that use case, you have to use the credentials provider. A credential provider doesn’t need necessarily to connect to an external system, you can use a dummy url and just build the logic in the runbook. Afterwards, you can assign that credential provider to projects and environments. 

That’s very interesting, i hadn’t understood that yet. Can you point me to an example of using the cred provider this way?

thanks!

Userlevel 4
Badge +5

https://portal.nutanix.com/page/documents/details?targetId=Self-Service-Admin-Operations-Guide-v3_7_1_1:nuc-app-mgmt-cred-account-settings-c.html

For server address: localhost

For provider secret: dummy

Variables secret: set your value

Runbook: Add at least 1 task, for example Delay 1 sec.

Then just follow the documentation on how to assign to a project as infrastructure provider.

The original answer isn’t working for me. I can set a variable type with a value, and then a variable with the same name in a blueprint, and it does not resolve to the variable type’s default value when deploying the blueprint. What am i missing?

I found a new nugget: To use a variable type set up in the Library, when setting up the blueprint, in the App Variables screen, you have to find it in the Data Type field. So instead of “String”, you’d pick “MY_USERNAME (String)”. 

It will then populate the value set in the library. You can change it here if you want, or keep the original value.