Hi all, I am new to the infra as code and to Pulu...
# azure
g
Hi all, I am new to the infra as code and to Pulumi so please bear with me 🙂 I am probably making a really simple mistake but need guidance on (1) what is the better way here (2) what is the issue in my case. Here are the details; Project Name -> 'azure-project' At the root of this project I have initiated a azure python project and it has the files
'__main__.py', '.gitignore', 'Pulumi.<stack-name>.yaml', Pulumi.yaml' and requirement.txt file
then I have a folder named 'azure' and inside that folder I have a folder named 'storage' -- both have the files
'__init__.py'
in them. In my storage folder I have a
'main.py'
file that has the following content
Copy code
import pulumi
import pulumi_azure_native as azure_native

config = pulumi.Config()

location = config.require("azure-native:location")
resource_group_name = config.require("azure-project:resourceGroupName")
storage_account_name = config.require("azure-project:storageAccountName")


# Define a resource group
resource_group = azure_native.resources.ResourceGroup(
    "resource_group", resource_group_name=resource_group_name, location=location
)

# Create an Azure Storage Account using the name from the config
storage_account = azure_native.storage.StorageAccount(
    "storage_account",
    account_name=storage_account_name,
    resource_group_name=resource_group.name,
    location=resource_group.location,
    sku=azure_native.storage.SkuArgs(name=azure_native.storage.SkuName.STANDARD_LRS),
    kind=azure_native.storage.Kind.STORAGE_V2,
)

# Export the connection string of the storage account
primary_connection_string = pulumi.Output.all(
    resource_group.name, storage_account.name
).apply(
    lambda args: pulumi_azure_storage.get_storage_account_connection_string(
        resource_group_name=args[0], storage_account_name=args[1]
    )
)

pulumi.export("primary_connection_string", primary_connection_string)
and my yaml file at the root level has the following content.
Copy code
config:
  azure-native:location: "WestEurope"
  dost-azure-project:resourceGroupName: "pulumi-test-dev"
  dost-azure-project:storageAccountName: "pulumi-test-storage-account"
  dost-azure-project:registryName: "pulumi-test-acr"
Unfortunately, I am getting this error ' error: Missing required configuration variable 'azure-projectazure nativelocation' To me it seems that my main.py file in the azure/storage folder is not getting the config values from the .yaml file Basically, what I want to do is to have a structure where I can have e.g. 'storage', 'containerregistry', 'serviceplan', 'database' etc. as module inside a folder called 'azure' using python Any help/guidance in this regard will be really helpful.
a
azure-native
is another "config bag" so you'd have to get config values like so:
Copy code
azure_config = pulumi.Config("azure-native")
location = azure_config.require("location")
g
Well that is pretty interesting @adventurous-butcher-54166 is there any documentation/reference about this? Thanks btw I will try this
a
It's a bit hidden but can be found here: https://www.pulumi.com/docs/concepts/config/#code Another thing I'd recommend especially if you have access to multiple Azure tenants & subscriptions is pinning those as well – otherwise deployment will happen in the subscription selected via azcli (
az account set --subscription <subscription_name>
).
Copy code
azure-native:location: westeurope
azure-native:subscriptionId: <your subscription guid>
azure-native:tenantId: <your tenant guid>
Then in code I always do:
Copy code
azure_config.require("subscriptionId")
azure_config.require("tenantId")
I've seen cases where some resources have been deployed in a correct subscription and then in a later pulumi deployment new resources would be deployed to a wrong subscription so that's why I have this as a working rule.
g
awesome! Thank you @adventurous-butcher-54166 I will look into this.