-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: bin/deploy.ts -> src/deploy.ts; bin/p6lzctl
- Loading branch information
Showing
8 changed files
with
165 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/Users/pgollucci/.p6/p6m7g8-dotfiles/p6aws |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/Users/pgollucci/.p6/p6m7g8-dotfiles/p6common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
#!/bin/sh | ||
|
||
# shellcheck shell=bash | ||
|
||
###################################################################### | ||
#< | ||
# | ||
# Function: p6_lz_main() | ||
# | ||
# Environment: LC_ALL OPTIND SHELL TERM | ||
#> | ||
#/ Synopsis | ||
#/ The entry point for bin/p6lzctl | ||
#/ | ||
###################################################################### | ||
p6_lz_main() { | ||
|
||
# sanitize env | ||
LC_ALL=C | ||
unset SHELL | ||
unset TERM | ||
|
||
local file=".deps/p6common/lib/_bootstrap.sh" | ||
. $file | ||
p6_bootstrap ".deps/p6common" | ||
p6_bootstrap ".deps/p6aws" | ||
|
||
# default options | ||
local flag_debug=0 | ||
|
||
# parse options | ||
local flag | ||
while getopts "dD" flag; do | ||
case $flag in | ||
D) flag_debug=0 ;; | ||
d) flag_debug=1 ;; | ||
*) p6_lz_usage 1 "invalid flag" ;; | ||
esac | ||
done | ||
shift $((OPTIND - 1)) | ||
|
||
# grab command | ||
local cmd="$1" | ||
shift 1 | ||
|
||
# security 101: only allow valid comamnds | ||
case $cmd in | ||
boostrap) ;; | ||
deploy) ;; | ||
esac | ||
|
||
# setup -x based on flag_debug | ||
[ ${flag_debug} = 1 ] && set -x | ||
# exit if any cli errors w/ >0 return code | ||
# the commands can still disable locally if needed | ||
set -e | ||
p6_lz_cmd_"${cmd}" "$@" | ||
set +e | ||
[ ${flag_debug} = 1 ] && set +x | ||
|
||
return 0 | ||
} | ||
|
||
###################################################################### | ||
#< | ||
# | ||
# Function: p6_lz_cmd_bootstrap(...) | ||
# | ||
# Args: | ||
# ... - | ||
# | ||
#> | ||
###################################################################### | ||
p6_lz_cmd_bootstrap() { | ||
shift 0 | ||
|
||
pnpm cdk bootstrap | ||
} | ||
|
||
###################################################################### | ||
#< | ||
# | ||
# Function: p6_lz_cmd_deploy(...) | ||
# | ||
# Args: | ||
# ... - | ||
# | ||
#> | ||
###################################################################### | ||
p6_lz_cmd_deploy() { | ||
shift 0 | ||
|
||
p6_lz_cmd_bootstrap | ||
|
||
pnpm cdk deploy p6-lz-organization p6-lz-avm --require-approval never | ||
|
||
local mgmt_account_id=$(p6_lz_util_mgmt_account_id_get) | ||
local account_ids=$(p6_lz_util_account_ids_get "$mgmt_account_id") | ||
local account_id | ||
for account_id in ${account_ids}; do | ||
p6_aws_svc_organizations_sts_su $account_id | ||
pnpm cdk bootstrap aws://$account_id/us-east-1 --trust $mgmt_account_id --trust-for-lookup $mgmt_account_id --cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess | ||
p6_aws_svc_organizations_sts_su_un | ||
done | ||
|
||
pnpm cdk deploy p6-lz-audit --require-approval never | ||
# pnpm cdk deploy p6-lz-logarchive --require-approval never | ||
# pnpm cdk deploy p6-lz-shared --require-approval never | ||
} | ||
|
||
p6_lz_util_account_ids_get() { | ||
local mgmt_account_id="$1" | ||
|
||
local account_ids=$(aws organizations list-accounts --query "Accounts[?Status=='ACTIVE'].Id" | jq -r ".[]" | grep -v "${mgmt_account_id}") | ||
|
||
echo "${account_ids}" | ||
} | ||
|
||
p6_lz_util_mgmt_account_id_get() { | ||
shift 0 | ||
|
||
local account_id=$(aws organizations describe-organization --query "Organization.MasterAccountId" --output text) | ||
|
||
echo "${account_id}" | ||
} | ||
|
||
###################################################################### | ||
#< | ||
# | ||
# Function: p6_lz_main() | ||
# | ||
#> | ||
###################################################################### | ||
p6_lz_main "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { Construct } from 'constructs' | ||
import * as cdk from 'aws-cdk-lib' | ||
|
||
export class AuditAccountStack extends cdk.Stack { | ||
constructor(scope: Construct, id: string, props: cdk.StackProps) { | ||
super(scope, id, props) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters