-
Notifications
You must be signed in to change notification settings - Fork 194
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
New option: --append
to allow importing to existing workspace
#151
Conversation
@stemaMSFT and @grayzu Despite the implementaions, I'm not so sure whether the option name |
I don't have a great alternative name for this, but I do agree that the name seems a little verbose. @grayzu let me know if you have any thoughts. |
@stemaMSFT Shall we just call this |
--append
--append
to allow importing to existing workspace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hey @magodo, @grayzu and I were wondering why this behavior should not be by default available for the user. Rather than having to specify --append, maybe by default appending to a directory and having to specify --overwrite instead. What are your thoughts? This may be a potential revert to modify the behavior while still addressing the overarching issues. |
@stemaMSFT The reason is "appending" to an existing directory might affecting user's data, so is regarded as a potential dangerous action. The default behavior is neither
One potential improvement is to make both modes consistent to be: check whether the directroy is empty. If not, tell the users to either use |
Just Idea: If |
@koudaiii In order to understand the change that is to happen, that needs to complete the full process, including TF resource addresses specifying, importing and cfg generation. That seems not what |
@magodo, I see !! I misunderstood it. Thank you for your help 😄 |
For local backend,
aztfy
will by default ensure the output directory is empty at the very begining. This is to avoid any conflicts happen for existing user files, including the terraform configuration, provider configuration, the state file, etc. As a result,aztfy
generates a pretty new workspace for users.One limitation of doing so is users can't import resources to existing state file via
aztfy
. To support this scenario, this PR adds a new option--append
. This option will makeaztfy
skip the empty guarantee for the output directory. If the output directory is empty, then it has no effect. Otherwise, it will ensure the provider setting (create a file for it if not exists). Then it proceeds the following steps.This means if the output directory has an active Terraform workspace, i.e. there exists a state file, any resource imported by the
aztfy
will be imported into that state file. Especially, the file generated byaztfy
in this case will be named differently than normal, where each file will has.aztfy
suffix before the extension (e.g.main.aztfy.tf
), to avoid potential file name conflicts.Test
❯ AZTFY_E2E=1 go test -timeout=30m -v -run=TestMutateOutputDir ./internal/test === RUN TestMutateOutputDir Initializing... List resources... Import resources... Importing /subscriptions/67a9759d-d099-4aa8-8675-e6cfd669c3f4/resourceGroups/aztfy-rg-budmjjug1 as azurerm_resource_group.round1_0 Generating Terraform configurations... Initializing... List resources... Import resources... Importing /subscriptions/67a9759d-d099-4aa8-8675-e6cfd669c3f4/resourceGroups/aztfy-rg-budmjjug2 as azurerm_resource_group.round2_0 Generating Terraform configurations... --- PASS: TestMutateOutputDir (133.90s) PASS ok github.com/Azure/aztfy/internal/test 134.036s