-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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: atlantis import #2783
feat: atlantis import #2783
Conversation
8a6ad94
to
65c4963
Compare
65c4963
to
af56f82
Compare
d53c1a4
to
c3f51e1
Compare
Wow. This looks very promising @krrrr38 ! I don't see how this can close the terraform pass through command #2776 . As amazing of a contribution as this is, it implements the import subcommand but not the This is a very large PR so it will take time to review. Thank you for your efforts. |
c3f51e1
to
ec0bdf6
Compare
Please give an initial review when time permits @runatlantis/maintainers cc: @albertollamaso @Fabianoshz @Fauzyy @SSKLCP (for visibility from our more recent golang expert contributors) |
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.
Aside from the metrics, only minor/nitpicks from my part.
Great PR, really nice work!
LGTM |
@krrrr38 Amazing work, thanks so much for this PR. |
Looks good to me too. Please fix the conflicts and we can get this merged. |
ec0bdf6
to
39158d4
Compare
@@ -1,9 +1,9 @@ | |||
# Apply Requirements | |||
# Command Requirements |
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.
Hm the renaming of this file will remove any existing links that point to this page.
There's a way to alias pages. If you keep this file rename in place, could you add a link for the original page apply-requirements.md to redirect to the new page?
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.
I added an empty page. I will try redirect plugin later.
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.
cc: @chenrui333 @lilincmu in case this is what you folks mentioned a couple months ago
``` | ||
### Explanation | ||
Runs `terraform import` that matches the directory/project/workspace. | ||
This command discards terraform plan result. Before apply, required `atlantis plan` again. |
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.
This command discards terraform plan result. Before apply, required `atlantis plan` again. | |
This command discards the terraform plan result. After an import and before an apply, another `atlantis plan` must be run again. |
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.
Because of the discarding of the plan after an import, should there be another flag to auto plan a project/dir/workspace after a successful import?
Also if an import command fails can we retain the plan instead of discarding it?
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.
Because of the discarding of the plan after an import, should there be another flag to auto plan a project/dir/workspace after a successful import?
Currently, there is not such flag.
I thought that if users want to import one resource, autoplan is useful. But if try to import multiple imports, autoplan make the operation slow.
terraform import
do not plan again, so I implements no-autoplan by default. We can provide such flag in the future as optional.
Also if an import command fails can we retain the plan instead of discarding it?
import_step_runner discard planfile if import has no err 👌
out, err := p.TerraformExecutor.RunCommandWithVersion(ctx, filepath.Clean(path), importCmd, envs, tfVersion, ctx.Workspace)
// If the import was successful and a plan file exists, delete the plan.
planPath := filepath.Join(path, GetPlanFilename(ctx.Workspace, ctx.ProjectName))
if err == nil {
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.
Perhaps we can have an optional subcommand like we do for atlantis apply
e.g. --auto-merge-disabled
For this case, perhaps a flag for --autoplan
, --autoplan-on-success
? This could be added in a separate PR.
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.
--autoplan
looks good for import option. We can do atlantis pllan
manually, so it is better to implement this after raised issue got votes.
@@ -124,6 +124,36 @@ Because Atlantis under the hood is running `terraform apply plan.tfplan`, any Te | |||
They're ignored because they can't be specified for an already generated planfile. | |||
If you would like to specify these flags, do it while running `atlantis plan`. | |||
|
|||
--- | |||
## atlantis import |
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.
Could you also update the tfvars section on the custom workflows page to show how to set it up for the import step? I've run into issues before where i need to pass in a custom tfvars file in order to get the import command to run correctly
https://www.runatlantis.io/docs/custom-workflows.html#tfvars-files
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.
A test with tfvars may be useful too. Ignore me if that is overkill.
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.
same with #2783 (comment)
Co-authored-by: nitrocode <[email protected]>
Co-authored-by: nitrocode <[email protected]>
Co-authored-by: nitrocode <[email protected]>
Thank you @krrrr38 ! This change is going to help a lot!! |
What an example of teamwork!!!! thanks @krrrr38 @nitrocode @Fabianoshz @albertollamaso |
Hi @krrrr38, I recently started to enable this feature in our environment. For most of the workflow steps, we have customizations (plan, apply). I've been trying to figure out how I could run terraform import from a script instead of the pre-built step. We might have a missing feature here for custom workflows, that there is no environment var holding the ADDRESS and the ID to be able to customize this. Am I right? If so, I will raise a feature request. |
@Dilergore Thank you for using new feature.
This is also discussed in the Slack and there is a dirty workaround.. (slack invitation is existed in the repository README) |
Hi, Thanks for the quick response, much appreciated. I can confirm that the above is working, I was able to implement it as a custom step in the past 20 mins. That said, I still think this should have its own dedicated variable. I will open a feature request. |
what
import
workflow stepterraform import
and discard plan file, cause existing plan file cannot be used anymore.import
workflow runinit
andimport
stepsatlantis import ADDRESS ID
import_requirements
configuration not to edit tfstate without any reviewswhy
Currently, we need to do manual terraform operations to import unmanaged resources. If support
atlantis import
, we can handle these operations on vcs operation.references
atlantis import
subcommand #217discussion
atlantis
terraform commands #2776atlantis import -- ADDR ID
--
comments can handled as terraform args.atlantis import -a ADDR -i ID
CommentCommand
need to handle command-specific parameters.atlantis import ADDR ID
<- choosedwe need to manage extraArgs and newArgs in flags.pflag cannot showADDR ID
usage in help like this?