https://pulumi.com logo
#general
Title
# general
g

gray-fall-86820

03/07/2024, 1:15 PM
Hi all, I am new to the infra as code and to Pulumi to 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.
w

witty-battery-28013

03/08/2024, 8:08 AM
I also experienced similar issues when starting with plumi (recently). I believe it is related to how pulumi resolves configuration files, I am not sure yet but am also looking for a solution and will let u know what I find
m

melodic-tomato-39005

03/08/2024, 9:47 AM
Hi @gray-fall-86820, a few initial thoughts: • Having your Pulumi.*.yaml file at the root folder is normal and is expected to work. • Using azure-native, you don’t need to retrieve the location from config and then pass it to each of your resources. It will be automatically applied. • It seems there might be a mismatch of stack names? The yaml file says
dost-azure-project
but the error message says
azure-project
.
Also wanted to make sure you’re aware of this page: https://www.pulumi.com/docs/concepts/config/
g

gray-fall-86820

03/08/2024, 1:18 PM
Thanks @melodic-tomato-39005 -- that was just me make a mistake in writing the project name in my post. I have tried something like treat every part as a python function and then calling those in the main.py file at the root by passing the required as arguments and it works however, I should have been able to use the parameters of the config file directly in the sub module files