Terraform-provider-aws: Need to create only one resource - terraform apply

Created on 10 Sep 2017  ยท  4Comments  ยท  Source: hashicorp/terraform-provider-aws

Hi ,

I have one question regarding terraform apply. I have one main.tf calling all my reusable modules to create vpc, create storage, creating instance etc. so if i run "terraform apply" then it will create all the resources. how can i run to create only one resource by running "terraform apply". i don't want to create all the resources. can anybody help?

question upstream-terraform

Most helpful comment

There's a target parameter that will let you specify just one piece. You should run it via plan so you can see what you're getting into, like:

terraform plan -out=vpc.plan -target=module.vpc
# you should see the plan details for only the VPC creation
# to apply it to your infrastructure:
terraform apply vpc.plan

You can target multiple things, so if you want your storage and instances at the same time you can do -target=module.storage -target=module.instance both at the same time.

All 4 comments

This is basically not how a descriptive language like Terraform works. You have described the desired state and the apply command is tasked with figuring out the modifications required in order to change the current state so that it matches the desired state.

If you wish to create a smaller portion of the ressources only, eg vpc and s3 bucket, then that has to be done in a separate stack. The other stack with the rest of the ressources, eg instances, then need to use the remote state data source as explained here: https://www.terraform.io/docs/providers/terraform/d/remote_state.html

Note that this requires you to use a backend with remote storage of the statefile, eg the S3 backend https://www.terraform.io/docs/backends/types/s3.html

Hope this helps!

BR Bent

There's a target parameter that will let you specify just one piece. You should run it via plan so you can see what you're getting into, like:

terraform plan -out=vpc.plan -target=module.vpc
# you should see the plan details for only the VPC creation
# to apply it to your infrastructure:
terraform apply vpc.plan

You can target multiple things, so if you want your storage and instances at the same time you can do -target=module.storage -target=module.instance both at the same time.

Thank you for using Terraform and for opening up this question, @tsgmanh! Issues on GitHub are intended to be related to bugs or feature requests with the provider codebase.

@007 provided some great feedback for your issue, but please use https://discuss.hashicorp.com/c/terraform-providers for additional feedback, community discussions, and questions around Terraform.

If you believe that your issue was miscategorized as a question or closed in error, please create a new issue using one of the following provided templates: bug report or feature request. Please make sure to provide us with the appropriate information so we can best determine how to assist with the given issue.

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

Was this page helpful?
0 / 5 - 0 ratings