Hey, can you use Pulumi.Yaml to add config variabl...
# getting-started
e
Hey, can you use Pulumi.Yaml to add config variables, or do you need to have the stackname.yaml to be able to get the correct values?
e
You can put some config variables into the Pulumi.yaml: https://www.pulumi.com/blog/project-config-mvp/
e
thank you, where does it say how you can use it in your code?
Why does pulumi say it is missing required configuration variable, when I have configured it in the Pulumi.Yaml file?
Pulumi.yaml
Copy code
name: Core.Api.IaC
description: Deploys rg-orchard-dev infrastructure
runtime: dotnet
template:
  config:
    core-api-iac:targetDomain:
      description: The domain to serve the website at (e.g. <http://www.example.com|www.example.com>)
      value: <http://orchardcore.net|orchardcore.net>
The code that tries to get the value
Copy code
// GET CONFIG VALUES FROM YAML FILE PULUMI
var config = new Config("core-api-iac");

var targetDomain = config.Require("targetDomain");
<http://Pulumi.Log.Info|Pulumi.Log.Info>($"targetDomain: {targetDomain}");
I believe the documentation could be much better explained, used 2 days just to get the config working in my program.
e
Copy code
runtime: dotnet
template:
  config:
You put it under the template section, that's just for templates not for plain projects.
e
So what is the correct way, the only way I got it working was doing this:
Copy code
var config = new Config();
        
        // PULUMI LOG OUT TENANT ID
        var tenantId = config.Require("tenant-id");
        <http://Pulumi.Log.Info|Pulumi.Log.Info>($"Tenant ID: {tenantId}");
        
        // PULUMI LOG OUT OBJECT ID 
        var objectId = config.Require("object-id");
        <http://Pulumi.Log.Info|Pulumi.Log.Info>($"Object ID: {objectId}");
        
        // PULUMI LOG OUT HOST NAME SSL NAME
        var hostNameSslName = config.Require("host-name");
        <http://Pulumi.Log.Info|Pulumi.Log.Info>($"Host Name SSL Name: {hostNameSslName}");

        // PULUMI LOG OOUT SKU CAPACITY
        var skuCapacity = config.Require("sku-capacity");
        <http://Pulumi.Log.Info|Pulumi.Log.Info>($"SKU Capacity: {skuCapacity}");
        
        // PULUMI LOG OUT SKU NAME
        var skuName = config.Require("sku-name");
        <http://Pulumi.Log.Info|Pulumi.Log.Info>($"SKU Name: {skuName}");
        
        // PULUMI LOG OUT SKU FAMILY
        var skuFamily = config.Require("sku-family");
        <http://Pulumi.Log.Info|Pulumi.Log.Info>($"SKU Family: {skuFamily}");
        
        
        // PULUMI LOG OUT SKU SIZE
        var skuSize = config.Require("sku-size");
        <http://Pulumi.Log.Info|Pulumi.Log.Info>($"SKU Size: {skuSize}");
Copy code
name: Core-Api-Ioc
description: A minimal Azure Native C# Pulumi program
runtime: dotnet
config:
  tenant-id: 8csdsfsdfsdf2-sdfdsf
  object-id: bfsdfdsfs76389
  host-name: sdfdfs.s
  sku-capacity: 1
  sku-name: B1
  sku-family: B
  sku-size: B1
But I would actually like to use Pulumi.Yaml to categorize stuff, the way I had it in this exmaple
Copy code
config:
    core-api-iac:targetDomain:
      description: The domain to serve the website at (e.g. <http://www.example.com|www.example.com>)
      value: <http://orchardcore.net|orchardcore.net>
e
Copy code
config:
    core-api-iac:targetDomain:
      description: The domain to serve the website at (e.g. <http://www.example.com|www.example.com>)
      default: <http://orchardcore.net|orchardcore.net>
Use
default
not
value
e
oh, let me try that.
Do you know why I get could not validate here. Trying to add some more values to the yaml file, but clearly it doesnt work.
e
Try:
Copy code
Core-Api-Ioc:data:
  default:
    active: true
    nums:
     - 1
     - 2
     - 3
Although I know support for general objects isn't fully finished yet, but I think just setting it as a default might still work
e
and that works, are you the engineer who have made this?
e
No I didn't make it
e
could the error say: Missing default value, try again? or just assume default is there, and then go ahead with the rest
thanks though
e
It's tricky because of all the different shapes of data that you could get here, but we do want to do a pass over making the error messages better. They are currently just a very raw response from the JSON validator we're using.
e
Thanks for the help though, I really didnt see any where to understand the docs. But now I got it, I try to write a blog post about this
e
👍 Yeh we need to add information about all this to https://www.pulumi.com/docs/intro/concepts/config/ at some point, a blog post about it isn't really docs
e
I know, but then I remember it for the next time, and hopefully some people can find my blog post if they were also struggling. https://thecloudway.wordpress.com/
Do you know if you can also nest like this?
Copy code
Core-Api-Ioc:dbscoredevpool__dbsncoredev_dbscoredevpool:
  default:
    servername: dbsncoredev
    sku-properties:
      default:
        capacity: 1
        name: B1
        family: B
        size: B1
        tier: Basic
e
yeh that should be fine, we don't recurse into the value set as "default" it should support any json value there.
e
cool! 🙂