-
Notifications
You must be signed in to change notification settings - Fork 457
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
feat: add import capabilities to cdktf #2972
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DanielMSchmidt
requested review from
mutahhir and
ansgarm
and removed request for
a team
June 28, 2023 14:24
DanielMSchmidt
force-pushed
the
plannable-import-second-try
branch
from
June 29, 2023 12:10
a55479a
to
1ad17e6
Compare
…g collision in providers
…g generation, updated docs
ansgarm
force-pushed
the
plannable-import-second-try
branch
from
October 5, 2023 12:58
50216c6
to
223af7b
Compare
I'm going to lock this pull request 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 related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In this PR is a feature addition regarding integrating Terraform's
import
functionality into CDKTF.Two Ways to Import
With Config Generation
There have been changes to the provider generator where a new static method
importGenerateConfig
appears on all resources.importGenerateConfig returns the new
ImportableResource
ImportableResource
adds the import block to our json config, then by runningcdktf plan <stack-name>
the resulting config (as ran through convert) is returnedThe config returned can then be added, then subsequently deployed
Without Config Generation
A new instance method
importFrom
onTerraformResource
It adds needed info (where we are importing from and to) to the global
imported
variable, whose contents are then used in thetoTerraform
method ofTerraformResource
The resource will then be imported on deploy.
Changes to CLI
In
plan
ofterraform-cli.ts
we automatically add the new tag-generate-config-out
on the detection of any import block.Testing
Due to the nature of this feature, integration tests are not included. As doing so would require having resources to be imported from elsewhere. Considering the potential for such tests to flake, I abstained from including any.
Unit Tests
Unit tests have been created for both the additions to the provider generator (tests for properly including new static functions) as well as the additions to
TerraformResource
(snapshot of json config includes import block and resource to be imported to)Local Usage
TFC Usage
Other Notes
importFrom
ofTerraformResource
and inImportableResource
cdktf
package since the recent addition of gradle, I had the pleasure of finding a bug in their examples script– specificallyreinstall.sh
. As such, changes in those files are the associated bug fix.importFrom
function onTerraformResource
could potentially have collisions with certain provider's naming, I've added an escaped attribute for such instances inattribute-model.ts
.