Hi everyone! - How would I go about splitting a mo...
# general
m
Hi everyone! - How would I go about splitting a monolithic stack into a separate stacks (application, common, core) This is how I intend to restructure: • core would contain VPC, TGW, VPN, etc. • common would contain security groups, iam, s3, sns, and other shared resources • application would contain ECS, ALB, ASG Questions: 1. Is it possible to reference resources in another stack? For example, if I needed a SNS topic ARN, from common for a resource in application? 2. Are there CLI commands I should look into that exports / moves resources to a new stack?
b
This is a common question, and really there's no silver bullet answer. It depends on your needs. I generally tell users to think about the rate of change of their application in order to manage, which is a hand wavey metric you'll need to define yourself: to answer your questions: 1. Yes, stack referneces: https://www.pulumi.com/learn/building-with-pulumi/stack-references/ 2. If you have existing running resources, you can use
pulumi import
to grab the current running state. there's command that will do the migration for you
m
thank you!
s
@magnificent-smartphone-40853 Although StackReferences aren’t the primary focus of this article, it does provide an example of using a StackReference in a real use case: https://blog.scottlowe.org/2021/08/26/establishing-vpc-peering-with-pulumi-and-go/
❤️ 1
m
Unrelated question: @salmon-account-74572 - what's the need of "pulumi.String(..)" throughout the article? Is there benefit to using that instead of using using string literals, etc?
s
I found that Go’s strong typing requires the use of
pulumi.String(..)
(or similar). I’m still learning Go, however, so it’s entirely possible there’s a better/different approach. I don’t know that similar constructs/mechanisms would be required in other languages.
m
Gotcha
b
@magnificent-smartphone-40853
pulumi.String()
tells pulumi it's an input, ie could potentially be resolved asynchronously. If you're using a standard Go string, wrapping in
pulumi.String
makes the type valid
m
How would I use the Stack Reference which returns an Output<any> and then use it as an object reference that is expecting a non Input<> type? for example: const vpc: Output<awsx.ec2.Vpc> = <get stack reference output here>, const sg = new awsx.ec2.SecurityGroup(
rds-sg-${regionAlias}-${environment}-${name}
, { description:
${name} - ${environment} - security group
, vpc: vpc.get(), }); is it okay to use vpc.get() or should I be doing something else?
b
@magnificent-smartphone-40853
vpc
shouldn't be taking a plain type, if you're returning the whole vpc type, you should be able to do
vpc.id
m
the SecurityGroupArgs expects an x.ec2.Vpc type, and doesn't have an input for vpcId:
Copy code
export interface SecurityGroupArgs {
    /**
     * An existing SecurityGroup to use for this awsx SecurityGroup.  If not provided, a default
     * one will be created.
     */
    securityGroup?: aws.ec2.SecurityGroup;
    /**
     * The vpc this security group applies to.  Or [Vpc.getDefault] if unspecified.
     */
    vpc?: x.ec2.Vpc;
...
}
b
ah sorry, I missed you're using
awsx
- you should be able to pass the whole object then
also, please wrap your code in three backticks ```
1
m
Is okay to use the .get() method of the Output<any> to resolve/unwrap the promise to the expected type? or should I be using .apply() somehow?
b
Get is for existing resources, I'm unfortunately not following along with the issue here
If you want a plain value, you'll need to resolve it with an apply
a
@magnificent-smartphone-40853 Did you ever figure out how to pass an Output as its underlying type when using Stack Reference?
I'm in a similar situation where I want to define and export an ECS cluster in one stack, and pass cluster to
awsx.ecs.FargateService
seems like I simply wont be able to use
awsx