gorgeous-pharmacist-71907
01/04/2024, 4:15 PMstaging
and prod
i want to create an IAM user in aws that is shared/known to both environments.
so when i deploy the staging
stack for example, it'll create this user, but then when i switch to prod
, i want it to recognise the user has already been created, rather than trying to re-create it which is what happens given the resource isn't being shared between the stacks
any help would be much appreciated as I'm new to pulumilittle-library-54601
01/04/2024, 4:20 PMdry-keyboard-94795
01/04/2024, 4:24 PMgorgeous-pharmacist-71907
01/04/2024, 4:25 PMdry-keyboard-94795
01/04/2024, 4:26 PMgorgeous-pharmacist-71907
01/04/2024, 4:32 PMprod
and staging
from shared
dry-keyboard-94795
01/04/2024, 4:33 PMgorgeous-pharmacist-71907
01/04/2024, 4:36 PMdry-keyboard-94795
01/04/2024, 4:44 PMPulumi.staging.yaml
file contains enable-some-service: true
.
This way, your code is the same between production + stagingsalmon-account-74572
01/04/2024, 4:48 PMgorgeous-pharmacist-71907
01/04/2024, 4:51 PMdry-keyboard-94795
01/04/2024, 4:52 PMPulumi.yaml
index.js
).
A Stack is represented by the config Pulumi.staging.yaml
(for the staging stack)salmon-account-74572
01/04/2024, 4:52 PMsalmon-account-74572
01/04/2024, 4:53 PMdry-keyboard-94795
01/04/2024, 4:53 PMgorgeous-pharmacist-71907
01/04/2024, 4:54 PMstaging
, prod
and shared
and staging
and prod
can make use of stack references from shared
, rather than having a separate project for shared
dry-keyboard-94795
01/04/2024, 4:56 PMshared
project, so your code doesn't need to be concerned with too much branching.
You could even nest it in the same directory if you want:
• Infra/
◦ Pulumi.yaml
◦ shared/
▪︎ Pulumi.yamlgorgeous-pharmacist-71907
01/04/2024, 4:56 PMprod
and staging
resources. we have a few instances of those. because of that we just want to shared resources so there isnt conflict (e..g prod does not try and recreate that IAM user). hopefully that makes sense?gorgeous-pharmacist-71907
01/04/2024, 4:58 PMsalmon-account-74572
01/04/2024, 5:01 PMhmm, i understand, ideally id like one project with 3 stacks@gorgeous-pharmacist-71907 You could make it work that way, but IMO it would be unnecessarily complex. You want to think of a stack as an instance of the infrastructure defined in your program. This is what enables you to have identical (or nearly identical) infrastructure in your staging environment (one stack) and your production environment (a second stack)---because they run the same code, but with independent state and independent configuration values. As Anthony mentioned, it's best if you have a separate
shared
project (and every project will have at least one stack) when you have resources that need to be accessed/used/referenced by other stacks (like the IAM user in your use case).salmon-account-74572
01/04/2024, 5:02 PMgorgeous-pharmacist-71907
01/04/2024, 5:06 PMprod
and staging
(stack for each for independent config)salmon-account-74572
01/04/2024, 5:09 PMprod
and staging
stacks such that they can use configuration values to provision slightly differently (for example, maybe you want to use smaller instance types in staging, so parameterize that as a configuration value).dry-keyboard-94795
01/04/2024, 5:10 PMgorgeous-pharmacist-71907
01/04/2024, 5:11 PMgorgeous-pharmacist-71907
01/04/2024, 5:11 PMsalmon-account-74572
01/04/2024, 5:13 PMgorgeous-pharmacist-71907
01/04/2024, 7:41 PMshared
project & stack as we mentioned & exported an output named IAMUserARN
and verified with pulumi stack output
then in my index.ts
for the staging|prod
stack I've setup, i have the following:
const sharedStack = new Pulumi.StackReference("shared")
sharedStack.getOutput("IAMUserARN").apply((arn) => {
console.log(`${arn}`)
})
when i run pulumi up
, it doesnt print anything:
am i doing something wrong here?gorgeous-pharmacist-71907
01/04/2024, 7:41 PM<http://Pulumi.log.info|Pulumi.log.info>
too and i get the same resultdry-keyboard-94795
01/04/2024, 7:44 PMdry-keyboard-94795
01/04/2024, 7:44 PMgorgeous-pharmacist-71907
01/04/2024, 7:46 PMfile://
to store pulumi state
i came across this SO post which recommended setting it to just the name of the stack:
https://stackoverflow.com/questions/71491871/how-to-reference-another-stack-for-file-backenddry-keyboard-94795
01/04/2024, 7:46 PMgorgeous-pharmacist-71907
01/04/2024, 7:47 PMdry-keyboard-94795
01/04/2024, 7:53 PMbackend.url
set in Pulumi.yaml
?dry-keyboard-94795
01/04/2024, 7:53 PMgorgeous-pharmacist-71907
01/04/2024, 8:13 PMbackend.url
, thought pulumi login file://./
was enough
in any case i've added that now
just to clarify my project structure is:
infra
• shared
◦ index.ts
◦ Pulumi.yaml
◦ Pulumi.shared.yaml
• resources
◦ iam.ts
◦ ...
• index.ts
• Pulumi.yaml
• Pulumi.staging.yaml
• Pulumi.prod.yaml
i set the backend.url
but that didnt seem to work
i also tried shared/shared
as you suggested. the contents of my Pulumi.yaml
file in the shared directory is:
name: shared
runtime: nodejs
description: Shared infrastructure that can be used in other stacks
organization: testorg
backend:
url: file://./
gorgeous-pharmacist-71907
01/04/2024, 8:14 PMdry-keyboard-94795
01/04/2024, 8:15 PMgorgeous-pharmacist-71907
01/04/2024, 8:16 PMdry-keyboard-94795
01/04/2024, 8:17 PMshared/shared
as your stack reference will workgorgeous-pharmacist-71907
01/04/2024, 8:28 PMinfra
root is where im storing the state
so in infra/shared/Pulumi.yaml
, i set the backend url to file://../
and in infra/Pulumi.yaml
, i set the backend url file://./
so it points to the same dir
and then weirdly i tried shared/shared
but it demanded organization
at the beginning. changing to organization/shared/shared
seems to have workedsalmon-account-74572
01/04/2024, 8:38 PMdry-keyboard-94795
01/04/2024, 8:40 PMdry-keyboard-94795
01/04/2024, 8:42 PMsalmon-account-74572
01/04/2024, 8:43 PMGoing with pulumi cloud is the simplest way of setting up for production100 rainbow
gorgeous-pharmacist-71907
01/04/2024, 8:48 PMgorgeous-pharmacist-71907
01/04/2024, 8:48 PMgorgeous-pharmacist-71907
01/04/2024, 8:50 PM{provider}
param but the type is Pulumi.ProviderResource
.
however the sharedStack.getOutput("euWest1Provider")
wont return that typedry-keyboard-94795
01/04/2024, 8:51 PMgorgeous-pharmacist-71907
01/04/2024, 8:52 PMgorgeous-pharmacist-71907
01/04/2024, 8:52 PMgorgeous-pharmacist-71907
01/04/2024, 9:07 PMPulumi.ProviderResource
is an abstract class so no luck there
and also cant use new AWS.Provider
as that'll just create another provider in the receiving stackdry-keyboard-94795
01/04/2024, 9:09 PMdry-keyboard-94795
01/04/2024, 9:09 PMgorgeous-pharmacist-71907
01/04/2024, 9:10 PMdry-keyboard-94795
01/04/2024, 9:11 PMdry-keyboard-94795
01/04/2024, 9:12 PMgorgeous-pharmacist-71907
01/04/2024, 9:13 PMdry-keyboard-94795
01/04/2024, 9:15 PMicy-controller-6092
01/05/2024, 6:05 AMPulumi.yaml
project name
and if it's important to distinguish which program was used to create which stack, you can export static identifiers from your programicy-controller-6092
01/05/2024, 6:06 AM[service].[env]
keen to understand if there's anything I'm missing that might come to bite me later on down the road...