hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io
Other
42.76k stars 9.56k forks source link

`import RESOURCE_TYPE` subcommands (=> easier coding & shell completion) #15446

Open Dominik-K opened 7 years ago

Dominik-K commented 7 years ago

A subcommand with the resource name for the import subcommand would be very helpful to start transforming to Terraform. As an example:

terraform import aws_route53_record TF_NAME  --name=dev.example.com --type=NS --zone_id=Z4KAPRWWNC7JR --set_identifier=dev

instead of

terraform import aws_route53_record.TF_NAME  Z4KAPRWWNC7JR_dev.example.com_NS_dev
apparentlymart commented 7 years ago

Hi @Dominik-K! Thanks for these ideas.

Looks like there's two different ideas packed in here:

Thanks for taking the time to write this up. All good feedback here, and we'll take it into consideration once we get into the more detailed planning for improvements to import.

Dominik-K commented 7 years ago

Thanks for your fast and detailled answer @apparentlymart.

I've just found a similar issue: it's more convenient to write

 terraform state mv aws_route53_record OLD_NAME NEW_NAME 

instead of

 terraform state mv aws_route53_record.OLD_NAME aws_route53_record.NEW_NAME

Maybe that's a good newcomer task, isn't it?

apparentlymart commented 7 years ago

That runs into some of the same concerns I mentioned above: the ability to move things is more general than just changing the name. Possibly we could have a shorthand that if the second argument contains no dots we automatically assume it's a new name for the first argument, leaving everything else unchanged:

terraform state mv aws_route_53_record.OLD_NAME NEW_NAME

...but I'm not sure if there would be unintended consequences for that. :confused:

I think the work here would be mainly in command/state_mv.go. If you'd be interested in building a prototype to help think through and test for any non-obvious problems then that'd be appreciated! But I just want to be explicit that there is a conflict here that these state commands can be potentially destructive so we have generally leaned towards being explicit, at the expense of being verbose, since that gives us better opportunity to validate the arguments and help avoid mistakes. We'd need to make sure that a change here doesn't impact our ability to do these checks.

james-flynn-ie commented 5 years ago

@apparentlymart, do we want to close this issue due to its age?