Open
Description
Community 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
Currently, the providers have to be defined directly on each stack. My provider configuration does not change between stacks. It would be nice if the cdk implementation walked up the object chain and used the first provider definition it finds, so I can define it in a single place.
Example (this doesn't work):
main.ts
import { HomelabApp } from 'src/app';
const app = new HomelabApp();
app.synth();
src/app.ts
import { App, AppOptions } from "cdktf";
import { ProxmoxProvider } from 'gen/providers/proxmox/provider';
import { K8sStack } from './k8s';
export class HomelabApp extends App {
public readonly proxmoxProvider: ProxmoxProvider;
public readonly k8sStack: K8sStack;
constructor(options?: AppOptions) {
super(options);
this.proxmoxProvider = new ProxmoxProvider(this, 'proxmox-provider', {
pmApiUrl: <redacted>,
pmUser: <redacted>,
pmPassword: <redacted>,
});
this.k8sStack = new K8sStack(this, "k8s");
}
}
src/k8s.ts
import { Construct } from "constructs";
import { TerraformStack } from "cdktf";
import { Lxc } from "gen/providers/proxmox/lxc";
export class K8sStack extends TerraformStack {
public readonly test: Lxc;
constructor(scope: Construct, id: string) {
super(scope, id);
this.test = new Lxc(this, 'lxc-test', {
<redacted config, not relevant>
});
}
}
tsconfig.json
{
"compilerOptions": {
"paths": {
"src/*": ["./src/*"],
"gen/*": ["./.gen/*"]
},
"alwaysStrict": true,
"charset": "utf8",
"declaration": true,
"experimentalDecorators": true,
"inlineSourceMap": true,
"inlineSources": true,
"lib": ["es2018"],
"module": "CommonJS",
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"strict": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"stripInternal": true,
"target": "ES2018",
"incremental": true,
"skipLibCheck": true
},
"ts-node": {
"require": ["tsconfig-paths/register"]
},
"include": ["**/*.ts"],
"exclude": ["node_modules", "cdktf.out"]
}
Error I get when running npm run synth -- --json
[2023-01-14T15:43:03.640] [ERROR] default - Error: Validation failed with the following errors:
[k8s] Found resources without a matching provider construct. Please make sure to add provider constructs [e.g. new RandomProvider(...)] to your stack 'k8s' for the following providers: proxmox
at K8sStack.runAllValidations (/Users/acdoussan/git/homelab/terraform/node_modules/cdktf/lib/terraform-stack.ts:342:13)
at StackSynthesizer.synthesize (/Users/acdoussan/git/homelab/terraform/node_modules/cdktf/lib/synthesize/synthesizer.ts:30:18)
at /Users/acdoussan/git/homelab/terraform/node_modules/cdktf/lib/app.ts:129:49
at Array.forEach (<anonymous>)
at HomelabApp.synth (/Users/acdoussan/git/homelab/terraform/node_modules/cdktf/lib/app.ts:129:12)
at Object.<anonymous> (/Users/acdoussan/git/homelab/terraform/main.ts:4:5)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Module.m._compile (/Users/acdoussan/git/homelab/terraform/node_modules/ts-node/src/index.ts:1618:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Object.require.extensions.<computed> [as .ts] (/Users/acdoussan/git/homelab/terraform/node_modules/ts-node/src/in
ERROR: cdktf encountered an error while synthesizing