Skip to content
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

Feature Request: [Destroy|Plan|Apply] by specifying the file #9939

Closed
MisaKondo opened this issue Nov 7, 2016 · 4 comments
Closed

Feature Request: [Destroy|Plan|Apply] by specifying the file #9939

MisaKondo opened this issue Nov 7, 2016 · 4 comments

Comments

@MisaKondo
Copy link

Terraform Version

MisaKondo-no-iMac% terraform -v
Terraform v0.7.7

Affected Resource(s)

No specific resource. This issue with Terraform's core.

Terraform Configuration Files

resource "google_compute_instance" "development" {
  name         = "development"
  machine_type = "n1-standard-1"
  zone         = "us-east1-d"
  description  = "mass-remote"
  tags         = ["development", "mass"]

  disk {
    image = "ubuntu-os-cloud/ubuntu-1404-lts"
  }

  // Local SSD disk
  disk {
    type        = "local-ssd"
    scratch     = true
    auto_delete = true
  }

  network_interface {
    subnetwork = "development"
  }

  service_account {
    scopes = ["userinfo-email", "compute-ro", "storage-ro", "bigquery", "monitoring"]
  }

  scheduling {
    on_host_maintenance = "MIGRATE"
    automatic_restart   = true
  }
}

Debug Output

MisaKondo-no-iMac% terraform destroy Terraform/gcp_instances.tf
Error loading config: configuration path must be a directory: Terraform/gcp_instances.tf
MisaKondo-no-iMac% git rm Terraform/gcp_instances.tf
rm 'Terraform/gcp_instances.tf'
MisaKondo-no-iMac% terraform plan Terraform
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but
will not be persisted to local or remote state storage.

google_compute_instance.development: Refreshing state... (ID: development)
google_compute_network.remote: Refreshing state... (ID: remote)
google_compute_subnetwork.development: Refreshing state... (ID: us-east1/development)

The Terraform execution plan has been generated and is shown below.
Resources are shown in alphabetical order for quick scanning. Green resources
will be created (or destroyed and then created if an existing resource
exists), yellow resources are being changed in-place, and red resources
will be destroyed. Cyan entries are data sources to be read.

Note: You didn't specify an "-out" parameter to save this plan, so when
"apply" is called, Terraform can't guarantee this is what will execute.

- google_compute_instance.development


Plan: 0 to add, 0 to change, 1 to destroy.
MisaKondo-no-iMac% git commit -m 'remove instance setting(for destory'

Expected Behavior

I expected, terraform destroy #{target_file} is destroy #{target_file} resource.

Actual Behavior

But, destroy|plan|apply COMMAND no support file. Only directory.
I want to delete specific file resource.

Steps to Reproduce

  1. git clone -b set_gcp_environments git@github.com:MisaKondo/remote_machine.git && cd remote_machine
  2. terraform apply Terraform
  3. terraform destroy Terraform/gcp_instances.tf
  4. rm Terraform/gcp_instances.tf
  5. Terraform apply Terraform

References

@apparentlymart
Copy link
Contributor

Hi @MisaKondo,

Terraform doesn't support exactly what you expected here, but you can get a similar result using the -target argument:

terraform plan -destroy -target=google_compute_instance.development

Note that targets are resource-oriented rather than file-oriented. Terraform generally doesn't operate on individual files, but rather just treats an entire directory as a single configuration.

The -target option lets you focus operations on particular resources and their dependencies: in the above example, if another resource were depending on the google_compute_instance.development resource then it too would be targeted for destruction.

@MisaKondo
Copy link
Author

@apparentlymart
Thank you for your reply!

-target option is good.
When multi resources are testing, If erasable by specifying the file, I thought it would be convenient.
However, how to delete the specified resource was understanding.

@espoelstra
Copy link

terraform state list is a great way to see all the modules that are available as targets for terraform plan -target=module.name.

@ghost
Copy link

ghost commented Apr 4, 2020

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants