Skip to content

Commit

Permalink
[sdlf-foundations][cdk] ability to provide parameter values without -…
Browse files Browse the repository at this point in the history
…-parameters
  • Loading branch information
cnfait committed Oct 27, 2024
1 parent 2b7495c commit cbf3f74
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
7 changes: 2 additions & 5 deletions sdlf-foundations/deployspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ deploy:
build:
commands:
- |-
cdk deploy --all --require-approval never --progress events --app "python src/app.py" --outputs-file ./cdk-exports.json \
--no-previous-parameters \
--parameters pOrg="$SEEDFARMER_PARAMETER_ORG" \
--parameters pDomain="$SEEDFARMER_PARAMETER_DOMAIN" \
--parameters pChildAccountId="$AWS_ACCOUNT_ID"
env | grep "SEEDFARMER"
cdk deploy --all --require-approval never --progress events --app "python src/app.py" --outputs-file ./cdk-exports.json
- seedfarmer metadata convert -f cdk-exports.json || true
destroy:
phases:
Expand Down
15 changes: 14 additions & 1 deletion sdlf-foundations/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,25 @@

if project_name:
stack_name = f"{project_name}-{deployment_name}-{module_name}"
param_prefix = "SEEDFARMER_PARAMETER_"
else: # app.py not used in a seedfarmer context somehow
stack_name = "sdlf-foundations"
param_prefix = ""


def _param(name: str, default: str = None) -> str:
return os.getenv(f"{param_prefix}{name}", default)


app = cdk.App()
stack = cdk.Stack(app, stack_name)
stack_foundations = Foundations(stack, "foundations")
stack_foundations = Foundations(
stack,
"foundations",
org=_param("ORG"),
data_domain=_param("DATA_DOMAIN"),
account_id=os.getenv("CDK_DEFAULT_ACCOUNT"),
)

cdk.CfnOutput(
scope=stack,
Expand Down
5 changes: 4 additions & 1 deletion sdlf-foundations/src/foundations.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class Foundations(Construct):
external_interface = {}

def __init__(self, scope: Construct, id: str, **kwargs) -> None:
def __init__(self, scope: Construct, id: str, org: str, data_domain: str, account_id: str, **kwargs) -> None:
super().__init__(scope, id)

dirname = os.path.dirname(__file__)
Expand All @@ -50,6 +50,7 @@ def __init__(self, scope: Construct, id: str, **kwargs) -> None:
type="String",
allowed_pattern="(\\d{12}|^$)",
constraint_description="Must be an AWS account ID",
default=str(account_id),
)
p_childaccountid.override_logical_id("pChildAccountId")
p_org = CfnParameter(
Expand All @@ -58,13 +59,15 @@ def __init__(self, scope: Construct, id: str, **kwargs) -> None:
description="Name of the organization owning the datalake (all lowercase, no symbols or spaces)",
type="String",
allowed_pattern="[a-z0-9]{2,9}",
default=org,
)
p_org.override_logical_id("pOrg")
p_domain = CfnParameter(
self,
"pDomain",
description="Data domain name",
type="String",
default=data_domain,
)
p_domain.override_logical_id("pDomain")
# p_cloudwatchlogsretentionindays = CfnParameter(self, "pCloudWatchLogsRetentionInDays",
Expand Down

0 comments on commit cbf3f74

Please sign in to comment.