From cbf3f748d169a7354b51260c33e65d2accfbc986 Mon Sep 17 00:00:00 2001 From: Cyril Fait Date: Sun, 27 Oct 2024 19:34:19 +0100 Subject: [PATCH] [sdlf-foundations][cdk] ability to provide parameter values without --parameters --- sdlf-foundations/deployspec.yaml | 7 ++----- sdlf-foundations/src/app.py | 15 ++++++++++++++- sdlf-foundations/src/foundations.py | 5 ++++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/sdlf-foundations/deployspec.yaml b/sdlf-foundations/deployspec.yaml index eeebbc11..3e7d661a 100644 --- a/sdlf-foundations/deployspec.yaml +++ b/sdlf-foundations/deployspec.yaml @@ -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: diff --git a/sdlf-foundations/src/app.py b/sdlf-foundations/src/app.py index 331a85f4..33c46f06 100644 --- a/sdlf-foundations/src/app.py +++ b/sdlf-foundations/src/app.py @@ -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, diff --git a/sdlf-foundations/src/foundations.py b/sdlf-foundations/src/foundations.py index 4a3d73ab..745ca9d6 100644 --- a/sdlf-foundations/src/foundations.py +++ b/sdlf-foundations/src/foundations.py @@ -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__) @@ -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( @@ -58,6 +59,7 @@ 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( @@ -65,6 +67,7 @@ def __init__(self, scope: Construct, id: str, **kwargs) -> None: "pDomain", description="Data domain name", type="String", + default=data_domain, ) p_domain.override_logical_id("pDomain") # p_cloudwatchlogsretentionindays = CfnParameter(self, "pCloudWatchLogsRetentionInDays",