Add back classes and interfaces published in earlier `cdktf-cli` versions
See original GitHub issueCommunity Note
- Please vote on this issue by adding a š reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave ā+1ā or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Description
After upgrading from 7.0.0
to 8.0.0
Iāve noticed that the published cdktf-cli
NPM package no longer contains the cdktf-cli/bin/cmds/ui/models/terraform
directory where classes like AbstractTerraformPlan
lived.
Is it possible that you can add them back?
The reason why I need this is that Iāve written a policy framework for Terraform CDK that includes the ability to validate changes to Terraform plans.
I have a very specific use case where I want a differentiation between the resource changes from before & after.
import { promises as fs } from 'fs';
import { Delta, diff } from '@n1ru4l/json-patch-plus';
import { TerraformResource } from 'cdktf';
import is from '@sindresorhus/is';
// These are the interfaces and classes I need
import {
PlannedResourceAction,
AbstractTerraformPlan,
PlannedResource,
ResourceChanges,
} from 'cdktf-cli/bin/cmds/ui/models/terraform';
const camelCaseObjectDeep = require('camelcase-object-deep');
export interface PlanFile {
readonly resource_changes: ResourceChanges[];
}
export { PlannedResourceAction };
export interface TerraformPlanResourceChange<R extends TerraformResource>
extends ResourceChanges,
PlannedResource {
readonly difference: Delta;
}
export class TerraformPlan extends AbstractTerraformPlan {
readonly #resourceChanges: readonly ResourceChanges[];
static async create(planFile: string | PlanFile): Promise<TerraformPlan> {
const plan = is.string(planFile)
? (JSON.parse(await fs.readFile(planFile, 'utf8')) as PlanFile)
: planFile;
return new TerraformPlan(plan);
}
constructor(plan: PlanFile) {
super('', plan.resource_changes as ResourceChanges[], {});
this.#resourceChanges = plan.resource_changes;
}
getApplicableResource(id: string): PlannedResource | undefined {
return this.applyableResources.find(r => r.id === id);
}
hasApplicableResource(id: string): boolean {
return this.applyableResources.some(r => r.id === id);
}
getResourceChanges(): readonly TerraformPlanResourceChange<any>[] {
return this.#resourceChanges
.filter(({ address }) => this.hasApplicableResource(address))
.map(resource => {
const before = camelCaseObjectDeep(resource.change.before);
const after = camelCaseObjectDeep(resource.change.after);
return {
...resource,
difference: diff(
{ left: before, right: after },
{ includePreviousValue: true },
),
change: {
...resource.change,
before,
after,
},
...this.getApplicableResource(resource.address)!,
};
});
}
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Use Your Preferred Programming Language with CDKTF
HashiCorp Terraform now supports writing configurations in HCL or your choice of C#, Python, TypeScript, Java, or Go with Cloud DevelopmentĀ ...
Read more >HashiCorp Live: CDK for Terraform - YouTube
Join Taylor Dolezal, Anubhav Mishra, and CDK for Terraform contributor Sebastian Korfmann as they provision infrastructure resources inĀ ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@skorfmann if you or anyone else is interested, Iāve made the code open source. Iāve extracted most of it for now into a public repository https://github.com/marcus-sa/terraform-cdk-extras Will most likely wrap it up and publish them as separate NPM packages sometime next week.
@marcus-sa thanks for creating this issue, please have a look at https://github.com/hashicorp/terraform-cdk/pull/1379 which I believe would solve your issue. Could you confirm, please?
As mentioned there, the mid term fix is more along the lines https://github.com/hashicorp/terraform-cdk/pull/804 š