Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synth should provide basic validation checks #473

Closed
lukep-coxauto opened this issue Jan 5, 2021 · 1 comment · Fixed by #896
Closed

Synth should provide basic validation checks #473

lukep-coxauto opened this issue Jan 5, 2021 · 1 comment · Fixed by #896
Labels
cdktf enhancement New feature or request

Comments

@lukep-coxauto
Copy link

lukep-coxauto commented Jan 5, 2021

Based on the below example, cdk synth should output an error that a provider is used improperly. Otherwise, an invalid file is created that could move further along in a build process to an apply step. There are likely other scenarios where synth should provide more feedback / errors.

// cdktf.json
{
  "language": "typescript",
  "app": "npm run --silent compile && node main.js",
  "terraformProviders": ["terraform-providers/docker@~> 2.0"],
  "context": {
    "excludeStackIdFromLogicalIds": "true",
    "allowSepCharsInLogicalIds": "true"
  }
}
// main.ts
import { Construct } from "constructs";
import { App, TerraformStack } from "cdktf";
import { Container } from "./.gen/providers/docker";

class MyStack extends TerraformStack {
  constructor(scope: Construct, name: string) {
    super(scope, name);
    // The line below is a semantic error, a Container should not be able to be instantiated without a Provider defined but this dependency does not show anywhere.
    new Container(this, "my-container", {
      image: "ubuntu",
      name: "ubuntu-test",
    });
  }
}

const app = new App();
new MyStack(app, "cdktf-test-docker");

app.synth();

This has no build issues and runs through synth and creates a full output file set, but it is not terraform applyable or cdktf deployable because Container has a dependency on a Provider being defined before its called. There is no enforcement of that at the synth step, which results in aruntime error when trying to run cdktf deploy

Error: Failed to query available provider packages

Could not retrieve the list of available versions for provider
hashicorp/docker: provider registry registry.terraform.io does not have a
provider named registry.terraform.io/hashicorp/docker

cdktf synth should be throwing an error when new Container() is called and the context does not have a corresponding provider already defined. The error doesn't occur until Terraform is trying to resolve the providers, which results in the unclear error message from Terraform which was really an issue in the synth step.

Here is the cdk.tf.json output file. Notice it doesn't have required providers referenced at all, so the docker_container resource cannot be resolved properly.

{
  "//": {
    "metadata": {
      "version": "0.0.19-pre.155",
      "stackName": "cdktf-test-docker"
    }
  },
  "resource": {
    "docker_container": {
      "my-container": {
        "image": "ubuntu",
        "name": "ubuntu-test",
        "//": {
          "metadata": {
            "path": "cdktf-test-docker/my-container",
            "uniqueId": "my-container",
            "stackTrace": [
              "...omitted..."
            ]
          }
        }
      }
    }
  }
}

Originally posted by @lukep-coxauto in #465 (comment)

@github-actions
Copy link
Contributor

github-actions bot commented Dec 3, 2022

I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cdktf enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants