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

mysterious-piano-88140

09/14/2021, 7:36 PM
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.
1
b

bored-oyster-3147

09/14/2021, 7:40 PM
What backend are you using? I.E. Pulumi SaaS, blob storage, local files, etc..
m

mysterious-piano-88140

09/14/2021, 7:44 PM
Pulumi SaaS for the deployment. Our Projects are written in Typescript.
b

bored-oyster-3147

09/14/2021, 7:47 PM
Ok so that weeds out the error I was thinking of. You're not getting an error in project 2 during deployment at all? Can you see the state for both project 1 and project 2 in the pulumi portal?
m

mysterious-piano-88140

09/14/2021, 7:58 PM
Project 1 is deployed flawlessly. Project 2 does not, because it tries to create the ResourceGroup that already exists. This is also displayed as an error. I have replaced customer data with xxx
Copy code
Type                                     Name                                    Plan       Info
     pulumi:pulumi:Stack                      xxxx-dev                    1 error
 +   └─ azure-native:resources:ResourceGroup  xxx-resource-group-dev  create     2 errors
 
Diagnostics:
  pulumi:pulumi:Stack (xxx-dev):
    error: preview failed
 
  azure-native:resources:ResourceGroup (xxx-resource-group-dev):
    error: Duplicate resource URN 'urn:pulumi:dev::xxxx::azure-native:resources:ResourceGroup::xxx-resource-group-dev'; try giving it a unique name
    error: Preview failed: resource '/subscriptions/<subscriptionid>/resourceGroups/xxx-resource-group-dev57917a4a' does not exist
w

witty-candle-66007

09/14/2021, 8:02 PM
I replied in #azure You shouldn’t have a declaration for the resource group in the second stack. Instead in the second stack, reference the name of the RG created in the first stack.
🙌 1
b

bored-oyster-3147

09/14/2021, 8:02 PM
Ah I didn't realize that was what he was doing. Yes Pulumi has a DSL, by declaring it in both stacks you are telling both stacks to provision it.
m

mysterious-piano-88140

09/14/2021, 9:02 PM
@witty-candle-66007 @bored-oyster-3147 Thanks for the quick reply. With the stack reference - as Mitch said - it works now! 🙌
48 Views