Hello all, I am using Pulumi for the first time fo...
# azure
m
Hello all, I am using Pulumi for the first time for a project hosted in Azure cloud. I am using Typescript for programming the resources. I currently have the following scenario: A project with a stack named ‘dev’ that creates a ResourceGroup in Azure. The code is as follows: Another project with a stack named ‘dev’ that should create a MariaDB database and map it to the ResourceGroup just created in the other projet. My current code is this:
Copy code
export const databaseResourceGroup = new ResourceGroup(
  'resource-group-dev',
  {
    resourceGroupName: 'resource-group-dev',
    location: 'germanywestcentral',
    tags: {
      project: 'test',
      env: 'dev',
      type: 'resourcegroup'
    }
  }
)
My problem is that in the second project the ResourceGroup is not linked no matter how (getResourceGroup, Import, StackReference) but is always recreated, which leads to a fail because it just already exists.
Copy code
// const resourceGroup = await getResourceGroup({
//   resourceGroupName: databaseResourceGroupName
// })

const resourceGroup = new ResourceGroup(
      'resource-group-dev',
      {
        resourceGroupName: 'resource-group-dev',
        location: 'germanywestcentral',
        tags: {
          project: 'test',
          env: 'dev',
          type: 'resourcegroup'
        }
      },
      {
        import: `/subscriptions/<subscription-id>/resourceGroups/<resourcegroupname>`
      }
    )
Do any of you here have an idea how I can link between resources without recreating them. I would now expect a similar pattern as in the AWS CDK where I can access ARN with from methods.
w
You don’t want to do a
new ResourceGroup
in the second project. You just want to use the resource group that was created in the first stack. So, the second project only needs a declaration for the MariaDB resource that references the name of the resource group created in the first project/stack. You can use Stack References to allow the second stack to get the resource group name from the first stack (instead of hard-coding the name across both stacks): https://www.pulumi.com/docs/intro/concepts/stack/#stackreferences