Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(region): add ability to specify region as an arg or get from env #4

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Args = {
'stack-name': string
'identity-store-id': string
'managing-instance-arn': string
region: string
verbose: boolean
help: boolean
}
Expand All @@ -33,6 +34,12 @@ const optionsConfig = {
default: '',
help: 'Pass the arn of the managing instance. If not provided will try to fetch for an existing one',
},
region: {
type: 'string',
short: 'r',
default: '',
help: 'Pass the region to be used. If not provided will use the value of the AWS_REGION environment variable.',
},
verbose: {
type: 'boolean',
short: 'v',
Expand Down
14 changes: 14 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,18 @@ await getOrgFormationVersion($$)
// 1. determine identity store id and managing instance arn
let identityStoreId = args['identity-store-id']
let managingInstanceArn = args['managing-instance-arn']
let region = args.region
const stackName = args['stack-name']
if (!region) {
// biome-ignore lint/nursery/noProcessEnv: <explanation>
region = process.env.AWS_REGION as string
if (!region) {
console.error(
'please set AWS_REGION environment variable or provide region as an argument'
)
process.exit(1)
}
}
if (!(identityStoreId && managingInstanceArn)) {
console.warn(
'identity-store-id or managing-instance-arn not provided, trying to determine them...'
Expand All @@ -58,6 +69,7 @@ if (!(identityStoreId && managingInstanceArn)) {
}
identityStoreId = ssoInstances[0]?.IdentityStoreId as string
managingInstanceArn = ssoInstances[0]?.InstanceArn as string
console.warn(`region: ${region}`)
console.warn(`identity-store-id: ${identityStoreId}`)
console.warn(`managing-instance-arn: ${managingInstanceArn}`)
}
Expand All @@ -79,6 +91,7 @@ console.info(`✅ Created ${TEMP_DIR}/organization-tasks.yml`)
const baseTemplateContent = createBaseOrgFormationSsoAssignmentsYml({
identityStoreId,
managingInstanceArn,
region,
})
await writeFile(`${TEMP_DIR}/sso-assignments.yml`, baseTemplateContent)
console.info(`✅ Created ${TEMP_DIR}/sso-assignments.yml`)
Expand Down Expand Up @@ -174,6 +187,7 @@ console.info('✅ Created organization-tasks.yml')
const finalSsoAssignmentsContent = createOrgFormationSsoAssignmentsYml({
identityStoreId,
managingInstanceArn,
region,
accounts,
groups,
permissionSets,
Expand Down
6 changes: 6 additions & 0 deletions src/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,18 @@ export function createOrganizationTasksYml({
export function createBaseOrgFormationSsoAssignmentsYml({
identityStoreId,
managingInstanceArn,
region,
}: {
identityStoreId: string
managingInstanceArn: string
region: string
}) {
const baseTemplateContent = nunjucksEnv.render(
'sso-assignments-base.yml.njk',
{
identityStoreId,
managingInstanceArn,
region,
groups: [
{
name: TEMP_GROUP_NAME,
Expand All @@ -368,11 +371,13 @@ type CreateOrgFormationSsoAssignmentsYmlOptions = {
permissionSets: ExtendedPermissionSet[]
assignments: AccountAssignment[]
accounts: OrgFormationAccount[]
region: string
}

export function createOrgFormationSsoAssignmentsYml({
identityStoreId,
managingInstanceArn,
region,
groups,
permissionSets,
assignments,
Expand All @@ -385,6 +390,7 @@ export function createOrgFormationSsoAssignmentsYml({
const templateContent = nunjucksEnv.render('sso-assignments.yml.njk', {
identityStoreId,
managingInstanceArn,
region,
groups,
permissionSets,
assignments,
Expand Down
2 changes: 1 addition & 1 deletion templates/sso-assignments-base.yml.njk
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ OrganizationBindings:
IncludeMasterAccount: true

DefaultOrganizationBinding: !Ref ManagementAccountBinding
DefaultOrganizationBindingRegion: eu-west-1
DefaultOrganizationBindingRegion: {{ region }}

Parameters:
IdentityStoreId:
Expand Down
2 changes: 1 addition & 1 deletion templates/sso-assignments.yml.njk
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ OrganizationBindings:
IncludeMasterAccount: true

DefaultOrganizationBinding: !Ref ManagementAccountBinding
DefaultOrganizationBindingRegion: eu-west-1
DefaultOrganizationBindingRegion: {{ region }}

Parameters:
IdentityStoreId:
Expand Down
Loading