Class CloudForgeSynthesizer

java.lang.Object
com.cloudforgeci.api.deploy.CloudForgeSynthesizer

public final class CloudForgeSynthesizer extends Object
In-process CDK synthesis — produces the canonical CloudFormation template CloudForgeDeployment (specifically AwsDirectDeployer, but the shape is target- agnostic) needs, without shelling out to the cdk CLI.

Same recipe cfc-testing's InteractiveDeployer already uses for its "synthesize only" / "export template" options: build a CDK App with cfc context set from DeploymentConfig.toContextMap(), construct the right com.cloudforgeci.api.launch stack for DeploymentConfig.runtime, call app.synth(). Factored out here (rather than reused from cfc-testing directly) because Manager — the first caller with no interactive CLI — cannot depend on the sample/reference repo.

Account resolution, stated plainly: DeploymentConfig.account wins when set; otherwise falls back to CDK_DEFAULT_ACCOUNT; otherwise the synthesized template's Environment is account-agnostic (same fallback InteractiveDeployer's "Export Template" option already relies on) — CloudFormation resolves AWS::AccountId pseudo-parameters against whichever real account the template is actually deployed into. This class stays entirely unaware of *why* a caller might set an explicit account (cross-account deploy, multi-region, whatever) — that's the caller's concern.

Availability-zone resolution: VpcFactory.maxAzs(2) reads Stack.availabilityZones, which CDK resolves via Fn::GetAZs (a CloudFormation-time token) only while account+region are both unresolved — true for the account-agnostic template above. The moment an explicit account is set, CDK instead routes AZ resolution through its availability-zones *synth-time* context provider — and since this deploy path never shells out to the cdk CLI to satisfy that lookup, CDK would silently return its built-in dummy values (dummy1a/dummy1b) baked straight into the template, which then fails at CloudFormation. Whenever an account is pinned, synthesize(DeploymentConfig, Path) seeds that context key itself first — see seedAvailabilityZoneContext(App, String, String, String[]).

  • Method Details

    • synthesize

      public static CloudForgeSynthesizer.Result synthesize(DeploymentConfig config, Path outputDirectory) throws IOException
      Resolves config.applicationSpec via ApplicationLoader when not already set (mutates config — matches CloudForgeDeployment.deploy()'s existing convention of resolving/preparing the config it's handed rather than requiring the caller to have already done so).
      Throws:
      IllegalArgumentException - when applicationId/stackName/runtime are missing, or no ApplicationSpec is registered for config.applicationId
      IOException - when app.synth() fails, or the output directory can't be created