mackerelio-labs / terraform-provider-mackerel

Terraform provider for Mackerel
Apache License 2.0
21 stars 15 forks source link

Environment variable definitions affect the binding code generated by CDKTF #223

Open rokoucha opened 1 week ago

rokoucha commented 1 week ago

CDKTF is a useful tool that uses terraform like AWS CDK. CDKTF will generate a binding code from terraform providers; most providers work great. However, it behaves strangely in mackerelio-labs/mackerel.

Mackerel provider will check environment variables and change provider argument typing dynamically if defined the MACKEREL_APIKEY or MACKEREL_API_KEY. This also works when the CDKTF generates the binding code, But it doesn't work when plan or apply. Therefore, Environment variable definitions affect the binding code generated by CDKTF, and reproducibility will be lost.

Below is the generated code fragment:

If defined the MACKEREL_APIKEY or MACKEREL_API_KEY

export interface MackerelProviderConfig {
  readonly apiBase?: string;
  readonly apiKey?: string;
  readonly alias?: string;
}

export class MackerelProvider extends cdktf.TerraformProvider {
  public constructor(scope: Construct, id: string, config: MackerelProviderConfig = {}) {}
}

If not defined any environment variables:

export interface MackerelProviderConfig {
  readonly apiBase?: string;
  readonly apiKey: string;
  readonly alias?: string;
}

export class MackerelProvider extends cdktf.TerraformProvider {
  public constructor(scope: Construct, id: string, config: MackerelProviderConfig) {}
}
Arthur1 commented 5 days ago

@rokoucha Thank you for your report.

There are two ideas about the specification: one is that we are happy to have constraints at schema level, and the other is that we don't want schema to be dynamic. Please give me some time to review how it is implemented in a general provider and consider pros/cons of making the provider's schema static.

There would be a workaround to set an empty environment variable during code generation by cdktf.