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

Brittle Workflow for Generated Providers File #66

Closed
skorfmann opened this issue May 10, 2020 · 2 comments · Fixed by #79
Closed

Brittle Workflow for Generated Providers File #66

skorfmann opened this issue May 10, 2020 · 2 comments · Fixed by #79
Assignees
Labels
bug Something isn't working
Milestone

Comments

@skorfmann
Copy link
Contributor

skorfmann commented May 10, 2020

The process of writing the providers.tf.json file is a bit brittle.

  • The Terraform version constraint is written on cdktf get
  • The actual provider config is merged on cdktf synth

This breaks, when a user removes the synthesize target folder (e.g. dist). On the next synth, the provider config is still written, but the version constraints are lost.

On the other hand, when doing another cdktf get, the providers.tf.json is overwritten and leaves the dist folder in an invalid state. In order to run a cdktf get successfully, the dist folder has to be deleted.

Example

{
  "//": "generated from `cdktf get`",
  "terraform": {
    "required_providers": {
      "aws": "~> 2.0"
    }
  },
  "//": "generated from `cdktf synth`",
  "provider": {
    "aws": [
      {
        "region": "eu-central-1",
        "ignore_tags": [
          {
            "keys": [
              "foo"
            ]
          }
        ]
      }
    ]
  }
}

Possible Solution 1:

  • Perform cdktf get in a temporary folder
  • Write some kind of lock file for exact provider and module versions in project root directory
  • Generate version constraints on synth from that lock file.

This would make sure, that the provider / module classes are always matching the source they were generated from. An upgrade would be an explicit run of cdktf get, which would regenerated the lock file.

Example

Given the following cdktf.json file:

{
  "language": "python",
  "app": "pipenv run ./main.py",
  "terraformProviders": ["aws@~> 2.0"],
  "output": "imports"
}

This could generated the following cdktf.lock file

{
  "providers": {
    "aws": {
      "version": "2.59.0"
    }
  },
  "modules": {}
}

Possible Solution 2:

Go with the approach described in #43 and make each resource (including providers) aware of the version they were generated from. Use this version information to generate the correct Terraform provider version constraints.

References

This is loosely related to #43

@skorfmann skorfmann added the bug Something isn't working label May 10, 2020
@anubhavmishra anubhavmishra added this to the alpha release milestone May 11, 2020
@skorfmann
Copy link
Contributor Author

As discussed yesterday, we'll go with a simpler approach for now:

  • Perform provider download in a temporary directory
  • Write terraform.tf.json configuration in the codeMakerOutput directory root
  • Copy this file into output directory during synth

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 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 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants