able-engineer-79880
07/14/2022, 4:42 AMimport * as pulumi from "@pulumi/pulumi";
import { ComponentResource, Input, Output } from "@pulumi/pulumi";
import * as azure_native from "@pulumi/azure-native";
import * as azure from "@pulumi/azure";
import { roleAssignment } from "../roleAssignment/roleAssignment";
let config= new pulumi.Config('env')
export class virtualNetwork {
constructor(name: string) {
const dpc_vnet_aue_001 = new azure.network.VirtualNetwork(name+"-aue-"+config.require('index'), {
addressSpaces:
config.requireObject(name+'-vnetrange'),
location: config.require('location'),
name: name+"-"+config.require('envid')+"-aue-"+config.require('index'),
resourceGroupName: "dpc-spi-networking-"+config.require('envid')+"-rg-aue-"+config.require('index'),
}, {
protect: true,
});
const vnet_id = dpc_vnet_aue_001.id
const aadplatforms_networkContributor = new roleAssignment(name+"aadplatforms_networkContributor", {
principleId: config.require('aadplatforms'),
principleType: "Group",
roleDefinition: config.require('networkContributor'),
//scope: pulumi.concat `${dpc_vnet_aue_001.id}`,
//scope: vnet_id,
scope: dpc_vnet_aue_001.id
}
)
}
}
I've commented some previous attempts but vscode just tells me that what I'm passing isn't a string.little-cartoon-10569
07/14/2022, 5:23 AMroleAssignment
) is typing is as a string instead of an Output<string>
.Output<string>
from all string
types, and my guess is that you're picking up on that, and defining the scope
value to have type string
. But it needs to be Output<string>
.
(*: Pulumi states "it's correct by design" but it confuses all newcomers, so I call that a bug.)able-engineer-79880
07/14/2022, 5:50 AMpulumi.output(args.scope).apply(v => {
pulumi.log.warn(v)
});
const vnetId = pulumi.output(args.scope).apply(v => {
return `${v}`
})
The apply function makes pulumi wait until the Output variable has a value before it executes the apply on it. This means your code will pause and wait for this to occur when you attempt to reference the variable vnetId.
It's all about parallelism and making pulumi wait until an Output object has a value before you can reference it.
Thanks @steep-sunset-89396 for explaining this to me.
I hope my poor and slightly uninformed explanation helps anyone searching for this.little-cartoon-10569
07/14/2022, 11:28 PMsteep-sunset-89396
07/14/2022, 11:32 PMable-engineer-79880
07/15/2022, 12:02 AM