Hello Team, Good morning. I am having a bit of cha...
# aws
f
Hello Team, Good morning. I am having a bit of challenge executing this task. I would appreciate any help. I have two AWS accounts, for production and dev environments. I have a domain (example.com) in Route53 of the production account. However, I want to create a new stack and deploy to the dev environment. If the stack name is testing, it should create a record in the production environment as testing.example.com, and then create a hosted zone in the dev account.
s
I’ll give you a couple high-level tips that should help. 1. To work with two different AWS accounts, you’ll need two different AWS providers. You can define explicit providers in your Pulumi program and then specify, for each resource, which provider should be used. 2. You can programmatically retrieve the stack name in your program, and then use that in a conditional (like determining which provider to use). All in all, what you’re describing sounds entirely doable.
f
Thank you, @salmon-account-74572. I will try this out and give you feedback.
@salmon-account-74572 Please, correct me if I am wrong. 1. I will create a Route53 record in the production account. 2. Create a hosted zone in the dev account.
s
I’m not really sure what you’re trying to achieve, so I can’t tell you if what you’re suggesting is correct or not. Also, be aware that I’m going to be OOO (out of office) for the next week, so any further replies may be delayed. Good luck!
f
Hello @salmon-account-74572. Let me try to break the task down. The parent domain is inside the Production account (example.com). And under that domain, a subdomain, a subdomain was created (dev.example.com), where dev is the stack name. Now what I want to achieve is the use of ephemeral environments. So now, when I create a name stack, say testing, it should have that record registered on the production account as (testing.example.com).
d
Scott is out this week but will be back next week.
f
Thank you.
I have been able to solve this.
s
@flaky-finland-22550 Hey, sorry I was out last week. Glad you were able to resolve it! Are you able to share some more details, so that others finding this thread can benefit?
f
Okay please. I had a different stack which was already provisioning a hosted zone on the dev account. So what I did was to create a StackReference to the nameserver file then return the domainName and nameServers.
Copy code
const environment = pulumi.getStack();
const commonStack = new pulumi.StackReference(`example/${environment}`);

const subDNS = commonStack.getOutput("dns").apply((t) => {
  return {
    domainName: t.domainName as string,
    nameServers: t.nameServers as string[]
  };
});
After that, I set the credentials for the production account and exported it (for local testing). I then retrieved the hosted zone from the production account.
Copy code
const parentHostedZone = aws.route53.getZone({ name: exampleDomainName, privateZone: false });
After that, I created a Route53 record and passed the domainName and nameServers I had referenced from the other stack, and the zoneId of the production hosted zone
Copy code
export const subdomainRecord = new aws.route53.Record(`${environment}-subdomain-record`, {
  allowOverwrite: true,
  name: subDNS.domainName,
  type: "NS",
  ttl: 300,
  records: subDNS.nameServers,
  zoneId: parentHostedZone.then(zr => zr.zoneId)
}, { protect: false });
s
Awesome, thanks for sharing!
f
Thank you too for your tip. It really helped me in achieving my goal.
s
Happy to help!