Skip to content

Commit

Permalink
chore(cli): remove json flag from synth
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMSchmidt committed Mar 23, 2022
1 parent 2b4228d commit 76f05ef
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 117 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.10.0

**Breaking Changes**

### Remove `cdktf synth --json` Opion [#1640](https://github.com/hashicorp/terraform-cdk/pull/1640)

If you are using `cdktf synth --json` to get the synthesized JSON configuration for your Stack, you will now need to run `cdktf synth && cat ./cdktf.out/stacks/<stack-name>/cdk.tf.json` instead. The `./cdktf.out` part is your output directory (set by `cdktf.json` or via the `--output` flag).

## 0.9.4

### fix
Expand Down
4 changes: 0 additions & 4 deletions packages/cdktf-cli/bin/cmds/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,6 @@ export async function synth(argv: any) {
const checkCodeMakerOutput = argv.checkCodeMakerOutput;
const command = argv.app;
const outDir = argv.output;
const jsonOutput = argv.json;
const stack = argv.stack;

if (checkCodeMakerOutput && !(await fs.pathExists(config.codeMakerOutput))) {
console.error(
Expand All @@ -270,9 +268,7 @@ export async function synth(argv: any) {
await renderInk(
React.createElement(Synth, {
outDir,
targetStack: stack,
synthCommand: command,
jsonOutput: jsonOutput,
})
);
}
Expand Down
7 changes: 1 addition & 6 deletions packages/cdktf-cli/bin/cmds/synth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Errors } from "../../lib/errors";
const config = cfg.readConfigSync();

class Command implements yargs.CommandModule {
public readonly command = "synth [stack] [OPTIONS]";
public readonly command = "synth [OPTIONS]";
public readonly describe =
"Synthesizes Terraform code for the given app in a directory.";
public readonly aliases = ["synthesize"];
Expand All @@ -27,11 +27,6 @@ class Command implements yargs.CommandModule {
desc: "Output directory for the synthesized Terraform config",
alias: "o",
})
.option("json", {
type: "boolean",
desc: "Provide JSON output for the generated Terraform configuration.",
default: false,
})
.option("check-code-maker-output", {
type: "boolean",
desc: "Should `codeMakerOutput` existence check be performed? By default it will be checked if providers or modules are configured.",
Expand Down
38 changes: 7 additions & 31 deletions packages/cdktf-cli/bin/cmds/ui/synth.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Box, Text } from "ink";
import { Text } from "ink";

import { useCdktfProject } from "./hooks/cdktf-project";
import { StreamView } from "./components";
Expand All @@ -8,46 +8,26 @@ import { StatusBottomBar } from "./components/bottom-bars/status";

interface CommonSynthConfig {
outDir: string;
targetStack: string;
jsonOutput: boolean;
}

interface SynthConfig extends CommonSynthConfig {
synthCommand: string;
}
type SynthOutputConfig = {
jsonOutput: boolean;
currentStackName: string;
stacks: SynthesizedStack[];
};
const SynthOutput = ({
jsonOutput,
currentStackName,
stacks,
}: SynthOutputConfig): React.ReactElement => {
const stack =
stacks.find((item) => item.name === currentStackName) || stacks[0];
const SynthOutput = ({ stacks }: SynthOutputConfig): React.ReactElement => {
return (
<>
{jsonOutput && stack ? (
<Box>
<Text>{stack.content}</Text>
</Box>
) : (
<Text>
Generated Terraform code for the stacks:{" "}
{stacks?.map((s) => s.name).join(", ")}
</Text>
)}
</>
<Text>
Generated Terraform code for the stacks:{" "}
{stacks?.map((s) => s.name).join(", ")}
</Text>
);
};

export const Synth = ({
outDir,
synthCommand,
jsonOutput,
targetStack,
}: SynthConfig): React.ReactElement => {
const { returnValue, logEntries, status } = useCdktfProject(
{ outDir, synthCommand },
Expand All @@ -57,11 +37,7 @@ export const Synth = ({
return (
<StreamView logs={logEntries}>
<StatusBottomBar status={status}>
<SynthOutput
jsonOutput={jsonOutput}
currentStackName={targetStack}
stacks={status.type === "done" ? returnValue! : []}
/>
<SynthOutput stacks={status.type === "done" ? returnValue! : []} />
</StatusBottomBar>
</StreamView>
);
Expand Down
65 changes: 0 additions & 65 deletions test/typescript/multiple-stacks/__snapshots__/test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -128,68 +128,3 @@ exports[`multiple stacks CLI-driven workflow synth 2`] = `
}"
`;

exports[`multiple stacks CLI-driven workflow synth with json output 1`] = `
"
{
\\"//\\": {
\\"metadata\\": {
\\"backend\\": \\"local\\",
\\"overrides\\": {
\\"null_resource\\": [
\\"provisioner\\"
]
},
\\"stackName\\": \\"first\\",
\\"version\\": \\"stubbed\\"
},
\\"outputs\\": {
\\"first\\": {
\\"output\\": \\"output\\"
}
}
},
\\"output\\": {
\\"output\\": {
\\"value\\": \\"first\\"
}
},
\\"provider\\": {
\\"null\\": [
{}
]
},
\\"resource\\": {
\\"null_resource\\": {
\\"test\\": {
\\"//\\": {
\\"metadata\\": {
\\"path\\": \\"first/test\\",
\\"uniqueId\\": \\"test\\"
}
},
\\"provisioner\\": [
{
\\"local-exec\\": {
\\"command\\": \\"echo \\\\\\"hello deploy\\\\\\"\\"
}
}
]
}
}
},
\\"terraform\\": {
\\"backend\\": {
\\"local\\": {
\\"path\\": \\"terraform.tfstate\\"
}
},
\\"required_providers\\": {
\\"null\\": {
\\"source\\": \\"null\\",
\\"version\\": \\" ~> 3.1.0\\"
}
}
}
}
"
`;
4 changes: 0 additions & 4 deletions test/typescript/multiple-stacks/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ describe("multiple stacks", () => {
expect(driver.synthesizedStack("second").toString()).toMatchSnapshot();
});

test("synth with json output", async () => {
expect((await driver.synth("--json")).stdout).toMatchSnapshot();
});

test("diff", () => {
const firstOut = driver.diff("first");
expect(firstOut).toContain(`null_resource.test`);
Expand Down
7 changes: 0 additions & 7 deletions website/docs/cdktf/cli-reference/commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@ Options:
--log-level Which log level should be written. Only supported via setting the env CDKTF_LOG_LEVEL [string]
--app, -a Command to use in order to execute cdktf app
--output, -o Output directory [default: "cdktf.out"]
--json Provide JSON output for the generated Terraform configuration. [boolean] [default: false]
-h, --help Show help [boolean]
```

Expand All @@ -457,12 +456,6 @@ Synthesize code when providing a custom command to execute and an output directo
$ cdktf synth --app="npm compile && node main.js" --output="dirname"
```

Synthesize code for an application and output the Terraform JSON configuration.

```bash
$ cdktf synth --json
```

## watch

~> **Warning:** The `watch` command is experimental, so you should only use it in development environments. It also automatically deploys all changes without asking for confirmation.
Expand Down

0 comments on commit 76f05ef

Please sign in to comment.