salmon-account-74572
07/22/2020, 5:15 PMApplyStringArray
and ApplyString
functions to the outputs from the stack reference, but trying to create an instance using a security group and subnet from the stack reference fails. I guess it's defaulting to the first subnet in the default VPC and not using my subnet at all. Code in thread below.ref, err := pulumi.NewStackReference(ctx, "user/project/stack", nil)
if err != nil {
return err
}
Then I have this code to pull out the first subnet from an array of subnets created by the first stack:
privSubnets := ref.GetOutput(pulumi.String("ref")).ApplyStringArray(func(out interface{}) []string {
var res []string
if out != nil {
for _, v := range out.([]interface{}) {
res = append(res, v.(string))
}
}
return res
})
// Get the ID of the first public subnet
privSubnet0 := privSubnets.ApplyString(func(a []string) string {
var res string
if len(a) > 0 {
res = a[0]
}
return res
})
When I try to use privSubnet0
to create an instance, it must have a nil value because Pulumi tries to create the instance in a subnet in the default VPC (which is completely wrong). So what am I missing here?lemon-agent-27707
07/22/2020, 5:24 PMpulumi stack output
for the original stack (the one used to construct the stackref "user/proj/stack")?salmon-account-74572
07/22/2020, 5:26 PMCurrent stack outputs (16):
OUTPUT VALUE
EIP
amiId ami-0288fa05d2ca8b5c7
bastionInstanceId i-0b93a76f7d1db768f
bastionSecGrpId sg-0045840efd05c2db3
defaultRoute rtb-0a55c701f0d9bccb4
gatewayId igw-045fa2082d3efcd1e
inetRoute r-rtb-0a55c701f0d9bccb41080289494
k8sSecGrpId sg-0a4687591102705da
natGateway nat-027db1764b3ad56a1
nodeSecGrpId sg-06648ddf8796bf63c
numOfAZs 3
privRouteTableAssocIds ["rtbassoc-0db084e8424e969c2","rtbassoc-068e695773ce5bc7a","rtbassoc-03da8e12e6db0ef47"]
privRouteTableId rtb-090cc2bd626d9f5e9
privSubnetIds ["subnet-0484737a31b183d10","subnet-0db65b831d7dc5603","subnet-0a7e23caa1a74d92e"]
pubSubnetIds ["subnet-0a1b1395860d29849","subnet-00865b0cc48b28a77","subnet-04e8dfbb0e7eba4cf"]
vpcId vpc-0e9bf44c8efd1133b
All the outputs seem valid.lemon-agent-27707
07/22/2020, 5:30 PMprivSubnet0
?salmon-account-74572
07/22/2020, 5:33 PMerror: Error launching source instance: InvalidParameter: Security group sg-06648ddf8796bf63c and subnet subnet-13f5c17b belong to different networks.
status code: 400, request id: dbdce577-3acc-4134-821d-b1d17eb7a84d
The referenced subnet ID is in the default VPC, not the VPC created by the referenced stack. Here's the code that references `privSubnet0`:
controlPlane, err := ec2.NewInstance(ctx, "controlplane", &ec2.InstanceArgs{
Ami: pulumi.String(amiID.Id),
InstanceType: pulumi.String("m5a.large"),
AssociatePublicIpAddress: pulumi.Bool(false),
KeyName: pulumi.String(keyPair),
SubnetId: privSubnet0,
VpcSecurityGroupIds: pulumi.StringArray{nodeSecGrp},
Tags: pulumi.StringMap{
"Name": pulumi.String("controlplane"),
},
})
Note that nodeSecGrp
, used in the code above, is the result of a stack reference and is working fine.lemon-agent-27707
07/22/2020, 5:59 PMref.GetOutput(pulumi.String("ref"))
Should this use the name of your output instead?
ref.GetOutput(pulumi.String("privSubnetIds")
salmon-account-74572
07/22/2020, 6:02 PMlemon-agent-27707
07/22/2020, 6:09 PM