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

Check if firewall exists before deleting #78

Merged
merged 1 commit into from
Sep 2, 2021
Merged

Check if firewall exists before deleting #78

merged 1 commit into from
Sep 2, 2021

Conversation

zulh-civo
Copy link
Member

Close #76


Here is the full logs when I destroy the resources in #76 using this branch. Look for Unable to find firewall 78d936aa-bd2c-4831-8f91-2df957332f3e - probably it's been deleted line. It will no longer throw an error.

$ tf destroy --auto-approve
2021-08-30T10:07:39.887+0800 [INFO]  Terraform version: 1.0.3
2021-08-30T10:07:39.887+0800 [INFO]  Go runtime version: go1.16.4
2021-08-30T10:07:39.887+0800 [INFO]  CLI args: []string{"/usr/local/bin/terraform", "destroy", "--auto-approve"}
2021-08-30T10:07:39.887+0800 [INFO]  Loading CLI configuration from /Users/zulh/.terraformrc
2021-08-30T10:07:39.888+0800 [INFO]  CLI command args: []string{"destroy", "--auto-approve"}
2021-08-30T10:07:39.964+0800 [INFO]  Failed to read plugin lock file .terraform/plugins/darwin_amd64/lock.json: open .terraform/plugins/darwin_amd64/lock.json: no such file or directory
2021-08-30T10:07:39.964+0800 [INFO]  backend/local: starting Apply operation
2021-08-30T10:07:39.965+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-30T10:07:40.014+0800 [INFO]  provider.terraform-provider-civo_v99.0.0: configuring server automatic mTLS: timestamp=2021-08-30T10:07:40.014+0800
2021-08-30T10:07:40.086+0800 [INFO]  terraform: building graph: GraphTypeValidate
2021-08-30T10:07:40.088+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-30T10:07:40.135+0800 [INFO]  provider.terraform-provider-civo_v99.0.0: configuring server automatic mTLS: timestamp=2021-08-30T10:07:40.135+0800
2021-08-30T10:07:40.212+0800 [INFO]  backend/local: apply calling Plan
2021-08-30T10:07:40.212+0800 [INFO]  terraform: building graph: GraphTypePlan
2021-08-30T10:07:40.214+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-30T10:07:40.260+0800 [INFO]  provider.terraform-provider-civo_v99.0.0: configuring server automatic mTLS: timestamp=2021-08-30T10:07:40.260+0800
2021-08-30T10:07:40.331+0800 [WARN]  ValidateProviderConfig from "provider[\"registry.terraform.io/civo/civo\"]" changed the config value, but that value is unused
civo_network.my_custom_network: Refreshing state... [id=9b2d3da4-baa0-482a-812e-1b6743ba9330]
2021-08-30T10:07:40.332+0800 [INFO]  provider.terraform-provider-civo_v99.0.0: 2021/08/30 10:07:40 [INFO] retriving the network 9b2d3da4-baa0-482a-812e-1b6743ba9330: timestamp=2021-08-30T10:07:40.332+0800
2021-08-30T10:07:42.142+0800 [WARN]  Provider "registry.terraform.io/civo/civo" produced an invalid plan for civo_network.my_custom_network, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .region: planned value cty.StringVal("") for a non-computed attribute
civo_firewall.my_custom_firewall: Refreshing state... [id=78d936aa-bd2c-4831-8f91-2df957332f3e]
2021-08-30T10:07:42.146+0800 [INFO]  provider.terraform-provider-civo_v99.0.0: 2021/08/30 10:07:42 [INFO] retriving the firewall 78d936aa-bd2c-4831-8f91-2df957332f3e: timestamp=2021-08-30T10:07:42.146+0800
2021-08-30T10:07:42.542+0800 [INFO]  ReferenceTransformer: reference not found: "civo_firewall.my_custom_firewall"
civo_firewall_rule.http: Refreshing state... [id=a200ad52-4b48-4251-8575-4bade7ed0952]
2021-08-30T10:07:42.544+0800 [INFO]  provider.terraform-provider-civo_v99.0.0: 2021/08/30 10:07:42 [INFO] firewallID: 78d936aa-bd2c-4831-8f91-2df957332f3e: timestamp=2021-08-30T10:07:42.544+0800
2021-08-30T10:07:42.544+0800 [INFO]  provider.terraform-provider-civo_v99.0.0: 2021/08/30 10:07:42 [INFO] RuleID: a200ad52-4b48-4251-8575-4bade7ed0952: timestamp=2021-08-30T10:07:42.544+0800
2021-08-30T10:07:42.544+0800 [INFO]  provider.terraform-provider-civo_v99.0.0: 2021/08/30 10:07:42 [INFO] retriving the firewall rule a200ad52-4b48-4251-8575-4bade7ed0952: timestamp=2021-08-30T10:07:42.544+0800
civo_kubernetes_cluster.my_cluster: Refreshing state... [id=7345d915-5168-4fe2-b6f6-3c75fb946a50]
2021-08-30T10:07:42.548+0800 [INFO]  provider.terraform-provider-civo_v99.0.0: 2021/08/30 10:07:42 [INFO] retrieving the kubernetes cluster 7345d915-5168-4fe2-b6f6-3c75fb946a50: timestamp=2021-08-30T10:07:42.548+0800
2021-08-30T10:07:43.552+0800 [INFO]  provider.terraform-provider-civo_v99.0.0: 2021/08/30 10:07:43 [INFO] rules &{ID:a200ad52-4b48-4251-8575-4bade7ed0952 FirewallID:78d936aa-bd2c-4831-8f91-2df957332f3e Protocol:tcp StartPort:80 EndPort: Cidr:[] Direction: Label:web-server}: timestamp=2021-08-30T10:07:43.552+0800
2021-08-30T10:07:43.553+0800 [WARN]  Provider "registry.terraform.io/civo/civo" produced an unexpected new value for civo_firewall_rule.http during refresh.
      - .direction: was cty.StringVal("ingress"), but now cty.StringVal("")
2021-08-30T10:07:44.718+0800 [WARN]  Provider "registry.terraform.io/civo/civo" produced an invalid plan for civo_kubernetes_cluster.my_cluster, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .tags: planned value cty.StringVal("") for a non-computed attribute
2021-08-30T10:07:44.722+0800 [INFO]  terraform: building graph: GraphTypePlanDestroy
2021-08-30T10:07:44.723+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-30T10:07:44.768+0800 [INFO]  provider.terraform-provider-civo_v99.0.0: configuring server automatic mTLS: timestamp=2021-08-30T10:07:44.768+0800

Note: Objects have changed outside of Terraform

Terraform detected the following changes made outside of Terraform since the last "terraform apply":

  # civo_firewall_rule.http has been changed
  ~ resource "civo_firewall_rule" "http" {
      - direction   = "ingress" -> null
        id          = "a200ad52-4b48-4251-8575-4bade7ed0952"
        # (6 unchanged attributes hidden)
    }

Unless you have made equivalent changes to your configuration, or ignored the relevant attributes using ignore_changes, the following plan may include actions to undo or respond to these changes.

─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

  # civo_firewall.my_custom_firewall will be destroyed
  - resource "civo_firewall" "my_custom_firewall" {
      - id         = "78d936aa-bd2c-4831-8f91-2df957332f3e" -> null
      - name       = "my-custom-firewall" -> null
      - network_id = "9b2d3da4-baa0-482a-812e-1b6743ba9330" -> null
    }

  # civo_firewall_rule.http will be destroyed
  - resource "civo_firewall_rule" "http" {
      - cidr        = [
          - "",
        ] -> null
      - end_port    = "80" -> null
      - firewall_id = "78d936aa-bd2c-4831-8f91-2df957332f3e" -> null
      - id          = "a200ad52-4b48-4251-8575-4bade7ed0952" -> null
      - label       = "web-server" -> null
      - protocol    = "tcp" -> null
      - start_port  = "80" -> null
    }

  # civo_kubernetes_cluster.my_cluster will be destroyed
  - resource "civo_kubernetes_cluster" "my_cluster" {
      - api_endpoint           = "https://212.2.243.143:6443" -> null
      - created_at             = "2021-08-30 02:04:02 +0000 UTC" -> null
      - dns_entry              = "7345d915-5168-4fe2-b6f6-3c75fb946a50.k8s.civo.com" -> null
      - firewall_id            = "78d936aa-bd2c-4831-8f91-2df957332f3e" -> null
      - id                     = "7345d915-5168-4fe2-b6f6-3c75fb946a50" -> null
      - installed_applications = [] -> null
      - instances              = [
          - {
              - cpu_cores = 2
              - disk_gb   = 15
              - hostname  = "k3s-my-cluster-20130122-node-pool-91e4"
              - ram_mb    = 4096
              - size      = ""
              - status    = "ACTIVE"
              - tags      = []
            },
        ] -> null
      - kubeconfig             = (sensitive value)
      - kubernetes_version     = "1.20.0-k3s1" -> null
      - master_ip              = "212.2.243.143" -> null
      - name                   = "my_cluster" -> null
      - network_id             = "9b2d3da4-baa0-482a-812e-1b6743ba9330" -> null
      - num_target_nodes       = 1 -> null
      - pools                  = [
          - {
              - count          = 1
              - id             = "8ee0af9c-b600-4c06-a554-7fd4302eb51c"
              - instance_names = [
                  - "k3s-my-cluster-20130122-node-pool-91e4",
                ]
              - instances      = [
                  - {
                      - cpu_cores = 2
                      - disk_gb   = 15
                      - hostname  = "k3s-my-cluster-20130122-node-pool-91e4"
                      - ram_mb    = 4096
                      - size      = "g3.k3s.medium"
                      - status    = "ACTIVE"
                      - tags      = []
                    },
                ]
              - size           = "g3.k3s.medium"
            },
        ] -> null
      - ready                  = true -> null
      - status                 = "ACTIVE" -> null
      - target_nodes_size      = "g3.k3s.medium" -> null
    }

  # civo_network.my_custom_network will be destroyed
  - resource "civo_network" "my_custom_network" {
      - default = false -> null
      - id      = "9b2d3da4-baa0-482a-812e-1b6743ba9330" -> null
      - label   = "my-custom-network" -> null
      - name    = "cust-433e075e-a401-my-custom-network" -> null
    }

Plan: 0 to add, 0 to change, 4 to destroy.
2021-08-30T10:07:44.846+0800 [INFO]  backend/local: apply calling Apply
2021-08-30T10:07:44.846+0800 [INFO]  terraform: building graph: GraphTypeApply
2021-08-30T10:07:44.848+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-30T10:07:44.895+0800 [INFO]  provider.terraform-provider-civo_v99.0.0: configuring server automatic mTLS: timestamp=2021-08-30T10:07:44.895+0800
2021-08-30T10:07:44.967+0800 [WARN]  ValidateProviderConfig from "provider[\"registry.terraform.io/civo/civo\"]" changed the config value, but that value is unused
civo_firewall_rule.http: Destroying... [id=a200ad52-4b48-4251-8575-4bade7ed0952]
2021-08-30T10:07:44.968+0800 [INFO]  Starting apply for civo_firewall_rule.http
2021-08-30T10:07:44.969+0800 [INFO]  provider.terraform-provider-civo_v99.0.0: 2021/08/30 10:07:44 [INFO] retriving the firewall rule a200ad52-4b48-4251-8575-4bade7ed0952: timestamp=2021-08-30T10:07:44.969+0800
civo_kubernetes_cluster.my_cluster: Destroying... [id=7345d915-5168-4fe2-b6f6-3c75fb946a50]
2021-08-30T10:07:44.969+0800 [INFO]  Starting apply for civo_kubernetes_cluster.my_cluster
2021-08-30T10:07:44.970+0800 [INFO]  provider.terraform-provider-civo_v99.0.0: 2021/08/30 10:07:44 [INFO] deleting the kubernetes cluster 7345d915-5168-4fe2-b6f6-3c75fb946a50: timestamp=2021-08-30T10:07:44.970+0800
civo_firewall_rule.http: Destruction complete after 3s
civo_kubernetes_cluster.my_cluster: Destruction complete after 4s
civo_firewall.my_custom_firewall: Destroying... [id=78d936aa-bd2c-4831-8f91-2df957332f3e]
2021-08-30T10:07:49.213+0800 [INFO]  Starting apply for civo_firewall.my_custom_firewall
2021-08-30T10:07:49.214+0800 [INFO]  provider.terraform-provider-civo_v99.0.0: 2021/08/30 10:07:49 [INFO] Checking if firewall 78d936aa-bd2c-4831-8f91-2df957332f3e exists: timestamp=2021-08-30T10:07:49.214+0800
2021-08-30T10:07:50.165+0800 [INFO]  provider.terraform-provider-civo_v99.0.0: 2021/08/30 10:07:50 [INFO] Unable to find firewall 78d936aa-bd2c-4831-8f91-2df957332f3e - probably it's been deleted: timestamp=2021-08-30T10:07:50.165+0800
civo_firewall.my_custom_firewall: Destruction complete after 1s
civo_network.my_custom_network: Destroying... [id=9b2d3da4-baa0-482a-812e-1b6743ba9330]
2021-08-30T10:07:50.195+0800 [INFO]  Starting apply for civo_network.my_custom_network
2021-08-30T10:07:50.195+0800 [INFO]  provider.terraform-provider-civo_v99.0.0: 2021/08/30 10:07:50 [INFO] deleting the network 9b2d3da4-baa0-482a-812e-1b6743ba9330: timestamp=2021-08-30T10:07:50.195+0800
civo_network.my_custom_network: Destruction complete after 3s

Destroy complete! Resources: 4 destroyed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check if firewall exists before deleting
2 participants