Giter Site home page Giter Site logo

civo / terraform-provider-civo Goto Github PK

View Code? Open in Web Editor NEW
68.0 12.0 53.0 4.92 MB

Terraform Civo provider

Home Page: https://www.civo.com

License: Mozilla Public License 2.0

Go 98.29% Shell 1.11% Makefile 0.50% Handlebars 0.10%
terraform terraform-provider civo

terraform-provider-civo's Introduction

Terraform Provider

Requirements

  • Terraform 0.13.x
  • Go 1.14.x or later (to build the provider plugin)

Building The Provider

Clone repository to: $GOPATH/src/github.com/civo/terraform-provider-civo

$ mkdir -p $GOPATH/src/github.com/terraform-providers; cd $GOPATH/src/github.com/terraform-providers
$ git clone https://github.com/civo/terraform-provider-civo.git

Enter the provider directory and build the provider

$ cd $GOPATH/src/github.com/terraform-providers/terraform-provider-civo
$ make build

Local Development: Using a local version of the Provider

If you're developing the provider locally, you can test your changes through:

$ make localdev

You'll be asked to provide the folder containing the declaration of the resources to be installed in civo and the civo region in which deploy those resources. No provider declaration is necessary because automatically produced by the script.

Documentation

  • For new Terraform users, we have guides written for you on Civo website
  • For experienced Terraform users, the documentation is available at Terraform Registry

Developing the Provider

If you wish to work on the provider, you'll first need Go installed on your machine (version 1.14.x (or later) is required). You'll also need to correctly setup a GOPATH, as well as adding $GOPATH/bin to your $PATH.

To compile the provider, run make build. This will build the provider and put the provider binary in the $GOPATH/bin directory.

$ make build
...
$ $GOPATH/bin/terraform-provider-civo
...

In order to test the provider, you can simply run make test.

$ make test

In order to run the full suite of acceptance tests, run make testacc.

Note: Acceptance tests create real resources, and often cost money to run.

$ make testacc

In order to run a specific acceptance test, use the TESTARGS environment variable. For example, the following command will run TestAccCivoDomain_Basic acceptance test only:

$ make testacc TESTARGS='-run=TestAccCivoDomain_Basic'

For information about writing acceptance tests, see the main Terraform contributing guide.

Documenting the Provider

As of 10th September 2021, we decided to use tfplugindocs to auto-generate docs from the provider code and examples.

For reference, you can see an example of the templates and output in paultyng/terraform-provider-unifi and browse the generated docs in the Terraform Registry.

Another example would be https://github.com/fastly/terraform-provider-fastly - which rendered in the Terraform Registry.

Caveat

While the tfplugindocs is still in active development by the Hashicorp and works fine for most cases, except when it comes to generating attribute descriptions located in nested schemas. We think this isn't too critical since the attribute keys are self explanatory. However, we will still watch the issue and update the docs once it's fixed.

terraform-provider-civo's People

Contributors

alejandrojnm avatar alessandroargentieri avatar alexsjones avatar andyjeffries avatar augustasv avatar dependabot[bot] avatar donnmyth avatar dtomasi avatar fernando-villalba avatar fgrehm avatar haardikdharma10 avatar hazsetata avatar itsroy69 avatar jadolg avatar jamesgawn avatar jdbohrman avatar kunal-kushwaha avatar lakshya8066 avatar pratikmota avatar praveen005 avatar saiyam1814 avatar satakshigarg avatar sindhuinti avatar stack72 avatar surajnarwade avatar uzaxirr avatar vishalanarase avatar willthames avatar zulh-civo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-provider-civo's Issues

Unable to create multiple instances

$ tf apply --auto-approve

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

Terraform will perform the following actions:

  # civo_instance.instance-1 will be created
  + resource "civo_instance" "instance-1" {
      + cpu_cores          = (known after apply)
      + created_at         = (known after apply)
      + disk_gb            = (known after apply)
      + firewall_id        = (known after apply)
      + hostname           = "instance-1"
      + id                 = (known after apply)
      + initial_password   = (sensitive value)
      + initial_user       = "civo"
      + network_id         = (known after apply)
      + private_ip         = (known after apply)
      + pseudo_ip          = (known after apply)
      + public_ip          = (known after apply)
      + public_ip_required = "create"
      + ram_mb             = (known after apply)
      + size               = "g3.xsmall"
      + source_id          = (known after apply)
      + source_type        = (known after apply)
      + status             = (known after apply)
      + template           = "8eb48e20-e5db-49fe-9cdf-cc8f381c61c6"
    }

  # civo_instance.instance-2 will be created
  + resource "civo_instance" "instance-2" {
      + cpu_cores          = (known after apply)
      + created_at         = (known after apply)
      + disk_gb            = (known after apply)
      + firewall_id        = (known after apply)
      + hostname           = "instance-2"
      + id                 = (known after apply)
      + initial_password   = (sensitive value)
      + initial_user       = "civo"
      + network_id         = (known after apply)
      + private_ip         = (known after apply)
      + pseudo_ip          = (known after apply)
      + public_ip          = (known after apply)
      + public_ip_required = "create"
      + ram_mb             = (known after apply)
      + size               = "g3.xsmall"
      + source_id          = (known after apply)
      + source_type        = (known after apply)
      + status             = (known after apply)
      + template           = "8eb48e20-e5db-49fe-9cdf-cc8f381c61c6"
    }

Plan: 2 to add, 0 to change, 0 to destroy.
civo_instance.instance-2: Creating...
civo_instance.instance-1: Creating...
civo_instance.instance-2: Still creating... [10s elapsed]
civo_instance.instance-2: Still creating... [20s elapsed]
civo_instance.instance-2: Still creating... [30s elapsed]
civo_instance.instance-2: Still creating... [40s elapsed]
civo_instance.instance-2: Still creating... [50s elapsed]
civo_instance.instance-2: Still creating... [1m0s elapsed]
civo_instance.instance-2: Creation complete after 1m6s [id=3f194bc8-ab5f-450b-be5c-7338c5a0bc6d]
╷
│ Error: [ERR] failed to create instance: DatabaseQuotaLockFailedError: Failed to lock the account's quota for updating, are you in the middle of creating another resource
│
│   with civo_instance.instance-1,
│   on main.tf line 42, in resource "civo_instance" "instance-1":
│   42: resource "civo_instance" "instance-1" {
│
╵

Fix all message in the system

  • Fix all message in the system using this format

log.Printf("[INFO] Create a xxx service") -> For Info

log.Printf("[DEBUG] Create: %#v", Value) -> For Debug

Empty state when refreshing firewall resource created in another region

Terraform config file:

provider "civo" {
    token = "api-token"
    region = "LON1"
}

resource "civo_firewall" "www" {
  name = "www"
  region = "NYC1"
}

Terminal traces:

$ tf apply --auto-approve

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

Terraform will perform the following actions:

  # civo_firewall.www will be created
  + resource "civo_firewall" "www" {
      + id         = (known after apply)
      + name       = "www"
      + network_id = (known after apply)
      + region     = "NYC1"
    }

Plan: 1 to add, 0 to change, 0 to destroy.
civo_firewall.www: Creating...
civo_firewall.www: Creation complete after 5s [id=a6a12049-b55d-4d4e-a520-a339acfc72cb]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.



$ tf refresh && tf show
civo_firewall.www: Refreshing state... [id=a6a12049-b55d-4d4e-a520-a339acfc72cb]




$ tf refresh && tf show
╷
│ Warning: Empty or non-existent state
│
│ There are currently no resources tracked in the state, so there is nothing to refresh.

How to fix:

Add the following block in firewall's Read, Update and Delete function. It only exists in Create function currently.

if attr, ok := d.GetOk("region"); ok {
    apiClient.Region = attr.(string)
}

Terraform tries to perform in-place update when there is no `firewall_id` set in configuration file

We added firewall support when launching Kubernetes cluster in #73 where we are saving firewall_id in the state after the cluster is created.

Example configuration file:

# Query xsmall instance size
data "civo_instances_size" "xsmall" {
    filter {
        key = "type"
        values = ["kubernetes"]
    }

    sort {
        key = "ram"
        direction = "asc"
    }
}

# Create a cluster
resource "civo_kubernetes_cluster" "my-cluster" {
    name = "my-cluster"
    applications = "Portainer,Linkerd:Linkerd & Jaeger"
    num_target_nodes = 2
    target_nodes_size = element(data.civo_instances_size.xsmall.sizes, 0).name
}

Now, when we run terraform apply command again after the first terraform apply, the following error will appear:

$ tf apply --auto-approve

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

Terraform will perform the following actions:

  # civo_kubernetes_cluster.my-cluster will be created
  + resource "civo_kubernetes_cluster" "my-cluster" {
      + api_endpoint           = (known after apply)
      + applications           = "Portainer,Linkerd:Linkerd & Jaeger"
      + created_at             = (known after apply)
      + dns_entry              = (known after apply)
      + id                     = (known after apply)
      + installed_applications = (known after apply)
      + instances              = (known after apply)
      + kubeconfig             = (sensitive value)
      + kubernetes_version     = (known after apply)
      + master_ip              = (known after apply)
      + name                   = "my-cluster"
      + network_id             = (known after apply)
      + num_target_nodes       = 2
      + pools                  = (known after apply)
      + ready                  = (known after apply)
      + region                 = (known after apply)
      + status                 = (known after apply)
      + target_nodes_size      = "g3.k3s.xsmall"
    }

Plan: 1 to add, 0 to change, 0 to destroy.
civo_kubernetes_cluster.my-cluster: Creating...
civo_kubernetes_cluster.my-cluster: Still creating... [10s elapsed]
civo_kubernetes_cluster.my-cluster: Still creating... [20s elapsed]
civo_kubernetes_cluster.my-cluster: Still creating... [30s elapsed]
civo_kubernetes_cluster.my-cluster: Still creating... [40s elapsed]
civo_kubernetes_cluster.my-cluster: Still creating... [50s elapsed]
civo_kubernetes_cluster.my-cluster: Still creating... [1m0s elapsed]
civo_kubernetes_cluster.my-cluster: Still creating... [1m10s elapsed]
civo_kubernetes_cluster.my-cluster: Still creating... [1m20s elapsed]
civo_kubernetes_cluster.my-cluster: Still creating... [1m30s elapsed]
civo_kubernetes_cluster.my-cluster: Still creating... [1m40s elapsed]
civo_kubernetes_cluster.my-cluster: Still creating... [1m50s elapsed]
civo_kubernetes_cluster.my-cluster: Still creating... [2m0s elapsed]
civo_kubernetes_cluster.my-cluster: Creation complete after 2m3s [id=ada61c67-3a2e-41d6-a4e1-cd508390f1ba]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.



$ tf apply --auto-approve
civo_kubernetes_cluster.my-cluster: Refreshing state... [id=ada61c67-3a2e-41d6-a4e1-cd508390f1ba]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # civo_kubernetes_cluster.my-cluster will be updated in-place
  ~ resource "civo_kubernetes_cluster" "my-cluster" {
      - firewall_id            = "2634fdcf-1048-4da2-af4c-83f7c84d8670" -> null
        id                     = "ada61c67-3a2e-41d6-a4e1-cd508390f1ba"
        name                   = "my-cluster"
        # (15 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
civo_kubernetes_cluster.my-cluster: Modifying... [id=ada61c67-3a2e-41d6-a4e1-cd508390f1ba]
╷
│ Error: [ERR] Firewall change ("firewall_id") for existing cluster is not available at this moment
│
│   with civo_kubernetes_cluster.my-cluster,
│   on main.tf line 15, in resource "civo_kubernetes_cluster" "my-cluster":
│   15: resource "civo_kubernetes_cluster" "my-cluster" {
│
╵

The error was caused by this line since Civo API does not yet support firewall change for cluster after it's been created.

The issue here is, we didn't declare firewall_id in our configuration file and when we rerun the terraform apply command again, it thinks we want to change it to empty/null.

To fix this, we need to mark both Computed: true and Optional: true into the firewall_id schema. Currently, it only has Optional: true.

Can't update the size of `civo_isntance`

First created a civo_instance using the following tf file:

resource "civo_instance" "my-test-instance" {
    hostname = "kubeform-test"
    tags = ["python", "nginx"]
    notes = "this is a note for the server"
    size = "g3.xsmall"
    template = "8eb48e20-e5db-49fe-9cdf-cc8f381c61c6"  
}

Then updated the size to g3.large.

resource "civo_instance" "my-test-instance" {
    hostname = "kubeform-test"
    tags = ["python", "nginx"]
    notes = "this is a note for the server"
    size = "g3.large"
    template = "8eb48e20-e5db-49fe-9cdf-cc8f381c61c6"  
}

Got this error from terraform apply:

civo_instance.my-test-instance: Refreshing state... [id=f5d9f705-3cbb-4049-9423-4fd90076d674]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # civo_instance.my-test-instance will be updated in-place
  ~ resource "civo_instance" "my-test-instance" {
        id                 = "f5d9f705-3cbb-4049-9423-4fd90076d674"
      ~ size               = "g3.xsmall" -> "g3.large"
        tags               = [
            "nginx",
            "python",
        ]
        # (17 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
civo_instance.my-test-instance: Modifying... [id=f5d9f705-3cbb-4049-9423-4fd90076d674]
╷
│ Error: [WARN] An error occurred while resizing the instance f5d9f705-3cbb-4049-9423-4fd90076d674
│ 
│   with civo_instance.my-test-instance,
│   on main.tf line 14, in resource "civo_instance" "my-test-instance":
│   14: resource "civo_instance" "my-test-instance" {
│ 
╵

Unable to change imported node pool size

When using terraform import civo_kubernetes_node_pool to import node pool that was created outside of Terraform (e.g. via Civo.com web UI), the node pool ID stored in the terraform.tfstate file is incorrect.

It does look like this currently:

{
   "mode":"managed",
   "type":"civo_kubernetes_node_pool",
   "name":"gitlab",
   "provider":"provider[\"registry.terraform.io/civo/civo\"]",
   "instances":[
      {
         "schema_version":0,
         "attributes":{
            "cluster_id":"e0f903bd-0237-48ed-976e-b5a0ff9fca62",
            "id":"e0f903bd-0237-48ed-976e-b5a0ff9fca62:71a6d794-418d-460a-9b63-462319cc30bc",
            "num_target_nodes":2,
            "region":"NYC1",
            "target_nodes_size":"g3.k3s.small"
         },
         "sensitive_attributes":[
            
         ],
         "private":"bnVsbA==",
         "dependencies":[
            "civo_kubernetes_cluster.civo_cluster"
         ]
      }
   ]
}

Note that e0f903bd-0237-48ed-976e-b5a0ff9fca62:71a6d794-418d-460a-9b63-462319cc30bc part where e0f903bd is cluster ID and 71a6d794 is node pool ID.

It should be saved like this:

{
   "mode":"managed",
   "type":"civo_kubernetes_node_pool",
   "name":"gitlab",
   "provider":"provider[\"registry.terraform.io/civo/civo\"]",
   "instances":[
      {
         "schema_version":0,
         "attributes":{
            "cluster_id":"73b63ad6-d7c7-4563-b6f1-f410f9057021",
            "id":"36621ded-e3fb-42c1-8dcf-49290bd36fc4",
            "num_target_nodes":2,
            "region":"NYC1",
            "target_nodes_size":"g3.k3s.small"
         },
         "sensitive_attributes":[
            
         ],
         "private":"bnVsbA==",
         "dependencies":[
            "civo_kubernetes_cluster.civo_cluster"
         ]
      }
   ]
}

...where 36621ded is the node pool ID.

The problem with current implementation is, the node pool size change / scaling operation via Terraform is not working. It doesn't show any error but nothing happened on Civo size (meaning Civo API doesn't receive a proper request).

ResponseDecodeFailed: failed to decode the response expected from the API

hi @alejandrojnm ,

as requested in slack, the issue regarding the ResponseDecodeFailed.

How to test:

terraform {
  required_providers {
    civo = {
      source = "civo/civo"
      version = "0.10.4"
    }
  }
}
resource "civo_instance" "my-test-instance" {
  region = "LON1"
  hostname = "foo.com"
  size = "g3.small"
  template = "d927ad2f-5073-4ed6-b2eb-b8e61aef29a8"
}
resource "civo_instance" "my-test-instance2" {
  region = "LON1"
  hostname = "bar.com"
  size = "g3.small"
  template = "d927ad2f-5073-4ed6-b2eb-b8e61aef29a8"
}

First terraform apply:

civo_instance.my-test-instance2: Still creating... [10s elapsed]
civo_instance.my-test-instance2: Still creating... [20s elapsed]
civo_instance.my-test-instance: Still creating... [20s elapsed]
civo_instance.my-test-instance: Still creating... [30s elapsed]
civo_instance.my-test-instance2: Still creating... [30s elapsed]
civo_instance.my-test-instance2: Still creating... [40s elapsed]
civo_instance.my-test-instance: Still creating... [40s elapsed]
civo_instance.my-test-instance2: Still creating... [50s elapsed]
civo_instance.my-test-instance: Still creating... [50s elapsed]
civo_instance.my-test-instance2: Creation complete after 54s [id=ab79827b-5713-489f-89f8-6478a5149db2]
civo_instance.my-test-instance: Still creating... [1m0s elapsed]
╷
│ Error: [ERR] failed to create instance: ResponseDecodeFailed: failed to decode the response expected from the API
│ 
│   with civo_instance.my-test-instance,
│   on main.tf line 10, in resource "civo_instance" "my-test-instance":
│   10: resource "civo_instance" "my-test-instance" {
│ 
╵

imediatly second time called terraform apply:

➜  civoclient-test terraform apply --auto-approve
civo_instance.my-test-instance2: Refreshing state... [id=ab79827b-5713-489f-89f8-6478a5149db2]
Note: Objects have changed outside of Terraform
Terraform detected the following changes made outside of Terraform since the last "terraform apply":
  # civo_instance.my-test-instance2 has been changed
  ~ resource "civo_instance" "my-test-instance2" {
        id                 = "ab79827b-5713-489f-89f8-6478a5149db2"
      + tags               = []
        # (17 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:
  + create
  ~ update in-place
Terraform will perform the following actions:
  # civo_instance.my-test-instance will be created
  + resource "civo_instance" "my-test-instance" {
      + cpu_cores          = (known after apply)
      + created_at         = (known after apply)
      + disk_gb            = (known after apply)
      + hostname           = "foo.com"
      + id                 = (known after apply)
      + initial_password   = (known after apply)
      + initial_user       = "civo"
      + network_id         = (known after apply)
      + private_ip         = (known after apply)
      + pseudo_ip          = (known after apply)
      + public_ip          = (known after apply)
      + public_ip_required = "create"
      + ram_mb             = (known after apply)
      + region             = "LON1"
      + size               = "g3.small"
      + source_id          = (known after apply)
      + source_type        = (known after apply)
      + status             = (known after apply)
      + template           = "d927ad2f-5073-4ed6-b2eb-b8e61aef29a8"
    }
  # civo_instance.my-test-instance2 will be updated in-place
  ~ resource "civo_instance" "my-test-instance2" {
      - firewall_id        = "1f70db6f-e1fa-46a8-8476-a138d8677188" -> null
        id                 = "ab79827b-5713-489f-89f8-6478a5149db2"
        tags               = []
      + template           = "d927ad2f-5073-4ed6-b2eb-b8e61aef29a8"
        # (16 unchanged attributes hidden)
    }
Plan: 1 to add, 1 to change, 0 to destroy.
civo_instance.my-test-instance: Creating...
civo_instance.my-test-instance2: Modifying... [id=ab79827b-5713-489f-89f8-6478a5149db2]
civo_instance.my-test-instance2: Modifications complete after 4s [id=ab79827b-5713-489f-89f8-6478a5149db2]
civo_instance.my-test-instance: Still creating... [10s elapsed]
civo_instance.my-test-instance: Still creating... [20s elapsed]
civo_instance.my-test-instance: Still creating... [30s elapsed]
civo_instance.my-test-instance: Still creating... [40s elapsed]
civo_instance.my-test-instance: Still creating... [50s elapsed]
civo_instance.my-test-instance: Creation complete after 52s [id=17156f2b-6195-43cf-901b-b9846f6fe03e]
Apply complete! Resources: 1 added, 1 changed, 0 destroyed.

This one was succesful...

Create volume failed

$ tf apply --auto-approve

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

Terraform will perform the following actions:

  # civo_volume.db will be created
  + resource "civo_volume" "db" {
      + bootable    = false
      + created_at  = (known after apply)
      + id          = (known after apply)
      + mount_point = (known after apply)
      + name        = "backup-data"
      + size_gb     = 1
    }

Plan: 1 to add, 0 to change, 0 to destroy.
civo_volume.db: Creating...
╷
│ Error: [ERR] failed to create a new config: Error: Unknown error response - status: 400 Bad Request, code: 400, reason: {"code":"parameter_network_id_invalid","result":"failed","reason":"The network_id supplied was empty"}
│
│   with civo_volume.db,
│   on main.tf line 1, in resource "civo_volume" "db":
│    1: resource "civo_volume" "db" {
│
╵

Related to #67

Inconistent result after applying Firewall Rule

I get the following error when trying to add firewall rules to a firewall in terraform:

│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to civo_firewall_rule.network["inbound_http"],
│ provider "provider[\"registry.terraform.io/civo/civo\"]" produced an
│ unexpected new value: Root resource was present, but now absent.
│ 
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.

Usually the first rule in a map will show up in the webUI, even though it does produce this error.

My config:

terraform { 
    required_providers {
        civo = {
            source = "civo/civo"
            version = "~> 0.10.2"
        }
    }
}

provider "civo" {
    region = var.region
}

resource "civo_network" "network" {
    label  = var.network_name
    region = var.region
}

resource "civo_firewall" "network" {
    name       = var.network_name
    network_id = civo_network.network.id
}

resource "civo_firewall_rule" "network" {
    firewall_id = civo_firewall.network.id
    region      = var.region
    
    for_each = var.firewall_rules

    label      = each.key
    protocol   = each.value.protocol
    start_port = each.value.start_port
    end_port   = each.value.end_port
    cidr       = each.value.cidr
    direction  = each.value.direction
}

variable "region" {
    description = "The region in which the network will be deployed."
    type        = string
}

variable "network_name" {
    description = "Desired name of the network."
    type        = string
}

variable "firewall_rules" {
    description = "Map of firewall rules. The key is used as the label. See https://registry.terraform.io/providers/civo/civo/latest/docs/resources/firewall_rule for details."
    type        = map(object({
        protocol   = string
        start_port = number
        end_port   = number
        cidr       = list(string)
        direction  = string
    }))
    default = {}
}

Inputs

region       = "LON1"
network_name = "main"

firewall_rules = {
  inbound_http = {
    protocol = "tcp"
    start_port = 80
    end_port = 80
    cidr = ["0.0.0.0/0"]
    direction = "ingress"
  },
}

civo volumes

customer should be able to

  • Create a new volume
  • List volumes
  • Attach a volume to an instance
  • Detach a volume from an instance
  • Deleting a volume

Firewall Issues - [ERR] failed to create a new firewall: UnknownError

On running Terraform apply I am running into the following error:

╷
│ Error: [ERR] failed to create a new firewall: UnknownError
│ 
│   with civo_firewall_rule.https,
│   on vpc.tf line 35, in resource "civo_firewall_rule" "https":
│   35: resource "civo_firewall_rule" "https" {
│ 
╵

Config:

terraform {
  required_version = ">= 0.13.0"
  required_providers {
    civo = {
      source = "civo/civo"
      version = "0.10.4"
    }
  }
}

provider "civo" {
  region = var.civo_region
}

resource "civo_network" "test" {
    label = "Test-Project"
}

resource "civo_firewall" "test" {
  name = "Test-Project"
  network_id = civo_network.test.id
}

resource "civo_firewall_rule" "http" {
  firewall_id = civo_firewall.test.id
  protocol = "tcp"
  start_port = "80"
  # end_port = "80"
  cidr = ["0.0.0.0/0"]
  direction = "ingress"
  label = "HTTP Ingress"
  depends_on = [civo_firewall.test]
}

resource "civo_firewall_rule" "https" {
  firewall_id = civo_firewall.test.id
  protocol = "tcp"
  start_port = "443"
  # end_port = "443"
  cidr = ["0.0.0.0/0"]
  direction = "ingress"
  label = "HTTPS Ingress"
  depends_on = [civo_firewall.test]
}

It appears the first rule applies fine however the second doesn't, I don't see anything obviously wrong with the config and if I take the first rule out the second works. It seems only one rule is able to be applied at a time. Also I tried with both end port defined and commented out.

Thanks,
Luke

Importing a node pool crashes

terraform import civo_kubernetes_node_pool.main <node-id>:<pool:id> results in

╷
│ Error: Plugin did not respond
│
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).ImportResourceState call. The plugin logs may contain more
│ details.
╵

Stack trace from the terraform-provider-civo_v0.10.9 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xd41cd1]

goroutine 25 [running]:
github.com/civo/terraform-provider-civo/civo.resourceKubernetesClusterNodePoolImport(0xc0005bfb80, 0xf27520, 0xc0001abf40, 0x19, 0xc000127490, 0x1, 0x30, 0x7f49572da5b8)
        /home/runner/work/terraform-provider-civo/terraform-provider-civo/civo/resource_kubernetes_cluster_nodepool.go:229 +0x191
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Provider).ImportState(0xc00052a280, 0x10ca6c8, 0xc000662e80, 0xc000653aa8, 0xc000216500, 0x49, 0x203000, 0x203000, 0x203000, 0x0, ...)
        /home/runner/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/provider.go:369 +0x328
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ImportResourceState(0xc00012e498, 0x10ca6c8, 0xc000662e80, 0xc000674640, 0xc000662e80, 0xee6060, 0xc000655800)
        /home/runner/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1021 +0xe5
github.com/hashicorp/terraform-plugin-go/tfprotov5/server.(*server).ImportResourceState(0xc00065e160, 0x10ca770, 0xc000662e80, 0xc00008d5e0, 0xc00065e160, 0xc000655860, 0xc000302ba0)
        /home/runner/go/pkg/mod/github.com/hashicorp/[email protected]/tfprotov5/server/server.go:349 +0xdc
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ImportResourceState_Handler(0xee6060, 0xc00065e160, 0x10ca770, 0xc000655860, 0xc000083500, 0x0, 0x10ca770, 0xc000655860, 0xc0003141c0, 0x66)
        /home/runner/go/pkg/mod/github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:398 +0x214
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0000d6000, 0x10d3298, 0xc000001680, 0xc000468200, 0xc0004026c0, 0x15d60d8, 0x0, 0x0, 0x0)
        /home/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:1194 +0x52b
google.golang.org/grpc.(*Server).handleStream(0xc0000d6000, 0x10d3298, 0xc000001680, 0xc000468200, 0x0)
        /home/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:1517 +0xd0c
google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc0006561c0, 0xc0000d6000, 0x10d3298, 0xc000001680, 0xc000468200)
        /home/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:859 +0xab
created by google.golang.org/grpc.(*Server).serveStreams.func1
        /home/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:857 +0x1fd

Error: The terraform-provider-civo_v0.10.9 plugin crashed!

Changing node size not applied

I created a cluster with g3.xsmall nodes, then updated the size to g3.small which provided the following output

Terraform will perform the following actions:

  # civo_kubernetes_cluster.this will be updated in-place
  ~ resource "civo_kubernetes_cluster" "this" {
        id                     = "19dccf7e-2cb3-40da-a207-bba1654f6f26"
        name                   = "openfaas-cluster"
      ~ target_nodes_size      = "g3.xsmall" -> "g3.small"
        # (15 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

civo_kubernetes_cluster.this: Modifying... [id=19dccf7e-2cb3-40da-a207-bba1654f6f26]
civo_kubernetes_cluster.this: Modifications complete after 5s [id=19dccf7e-2cb3-40da-a207-bba1654f6f26]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

It says its going to update in place, bit in the UI i still see a node pool with 3x g3.xsmall nodes and no additional node groups or indication that it did anything.

image

Unable to create multiple firewall rules

$ ls -la
total 16
drwxr-xr-x   6 zulh  staff  192 Aug 26 12:44 .
drwxr-xr-x  30 zulh  staff  960 Aug 26 10:48 ..
drwxr-xr-x   3 zulh  staff   96 Aug  9 10:06 .terraform
drwxr-xr-x   3 zulh  staff   96 Aug  9 10:33 .terraform.d
-rw-r--r--   1 zulh  staff  644 Aug 26 12:43 main.tf
-rw-r--r--   1 zulh  staff  355 Aug 26 12:41 provider.tf


$ tf init

Initializing the backend...

Initializing provider plugins...
- Finding civo/civo versions matching "0.10.9"...
- Installing civo/civo v0.10.9...
- Installed civo/civo v0.10.9 (signed by a HashiCorp partner, key ID CA1DE390990EBE66)

Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/cli/plugins/signing.html

Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.


$ ls -la
total 24
drwxr-xr-x   7 zulh  staff   224 Aug 26 12:46 .
drwxr-xr-x  30 zulh  staff   960 Aug 26 10:48 ..
drwxr-xr-x   3 zulh  staff    96 Aug  9 10:06 .terraform
drwxr-xr-x   3 zulh  staff    96 Aug  9 10:33 .terraform.d
-rw-r--r--   1 zulh  staff  1252 Aug 26 12:46 .terraform.lock.hcl
-rw-r--r--   1 zulh  staff   644 Aug 26 12:43 main.tf
-rw-r--r--   1 zulh  staff   355 Aug 26 12:41 provider.tf


$ cat main.tf
resource "civo_network" "cluster_net" {
  label  = "my-custom-network"
}

resource "civo_firewall" "www" {
  name       = "www"
  network_id = civo_network.cluster_net.id
}

resource "civo_firewall_rule" "http" {
  firewall_id = civo_firewall.www.id
  protocol    = "tcp"
  start_port  = "80"
  end_port    = "80"
  direction   = "ingress"
  label       = "server web"
  depends_on  = [civo_firewall.www]
}

resource "civo_firewall_rule" "https" {
  firewall_id = civo_firewall.www.id
  protocol    = "tcp"
  start_port  = "443"
  end_port    = "443"
  direction   = "ingress"
  label       = "server web"
  depends_on  = [civo_firewall.www]
}


$ export TF_LOG=INFO
$ echo $TF_LOG
INFO


$ tf apply --auto-approve
2021-08-26T12:46:59.953+0800 [INFO]  Terraform version: 1.0.3
2021-08-26T12:46:59.954+0800 [INFO]  Go runtime version: go1.16.4
2021-08-26T12:46:59.954+0800 [INFO]  CLI args: []string{"/usr/local/bin/terraform", "apply", "--auto-approve"}
2021-08-26T12:46:59.954+0800 [INFO]  CLI command args: []string{"apply", "--auto-approve"}
2021-08-26T12:47:00.020+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-26T12:47:00.024+0800 [INFO]  backend/local: starting Apply operation
2021-08-26T12:47:00.031+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T12:47:00.251+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T12:47:00.250+0800
2021-08-26T12:47:00.338+0800 [INFO]  terraform: building graph: GraphTypeValidate
2021-08-26T12:47:00.345+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T12:47:00.394+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T12:47:00.394+0800
2021-08-26T12:47:00.473+0800 [INFO]  backend/local: apply calling Plan
2021-08-26T12:47:00.473+0800 [INFO]  terraform: building graph: GraphTypePlan
2021-08-26T12:47:00.475+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T12:47:00.521+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T12:47:00.520+0800
2021-08-26T12:47:00.596+0800 [WARN]  ValidateProviderConfig from "provider[\"registry.terraform.io/civo/civo\"]" changed the config value, but that value is unused
2021-08-26T12:47:00.603+0800 [INFO]  ReferenceTransformer: reference not found: "civo_firewall.www"
2021-08-26T12:47:00.603+0800 [INFO]  ReferenceTransformer: reference not found: "civo_firewall.www"

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

Terraform will perform the following actions:

  # civo_firewall.www will be created
  + resource "civo_firewall" "www" {
      + id         = (known after apply)
      + name       = "www"
      + network_id = (known after apply)
    }

  # civo_firewall_rule.http will be created
  + resource "civo_firewall_rule" "http" {
      + cidr        = (known after apply)
      + direction   = "ingress"
      + end_port    = "80"
      + firewall_id = (known after apply)
      + id          = (known after apply)
      + label       = "server web"
      + protocol    = "tcp"
      + region      = (known after apply)
      + start_port  = "80"
    }

  # civo_firewall_rule.https will be created
  + resource "civo_firewall_rule" "https" {
      + cidr        = (known after apply)
      + direction   = "ingress"
      + end_port    = "443"
      + firewall_id = (known after apply)
      + id          = (known after apply)
      + label       = "server web"
      + protocol    = "tcp"
      + region      = (known after apply)
      + start_port  = "443"
    }

  # civo_network.cluster_net will be created
  + resource "civo_network" "cluster_net" {
      + default = (known after apply)
      + id      = (known after apply)
      + label   = "my-custom-network"
      + name    = (known after apply)
    }

Plan: 4 to add, 0 to change, 0 to destroy.
2021-08-26T12:47:00.609+0800 [INFO]  backend/local: apply calling Apply
2021-08-26T12:47:00.609+0800 [INFO]  terraform: building graph: GraphTypeApply
2021-08-26T12:47:00.611+0800 [INFO]  ReferenceTransformer: reference not found: "civo_firewall.www#destroy"
2021-08-26T12:47:00.611+0800 [INFO]  ReferenceTransformer: reference not found: "civo_firewall.www#destroy"
2021-08-26T12:47:00.612+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T12:47:00.659+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T12:47:00.659+0800
2021-08-26T12:47:00.732+0800 [WARN]  ValidateProviderConfig from "provider[\"registry.terraform.io/civo/civo\"]" changed the config value, but that value is unused
civo_network.cluster_net: Creating...
2021-08-26T12:47:00.734+0800 [INFO]  Starting apply for civo_network.cluster_net
2021-08-26T12:47:00.734+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:47:00 [INFO] creating the new network my-custom-network: timestamp=2021-08-26T12:47:00.734+0800
2021-08-26T12:47:02.911+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:47:02 [INFO] retriving the network 52c49e78-febf-4015-b889-f56385e62336: timestamp=2021-08-26T12:47:02.911+0800
2021-08-26T12:47:03.591+0800 [WARN]  Provider "provider[\"registry.terraform.io/civo/civo\"]" produced an unexpected new value for civo_network.cluster_net, 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: was null, but now cty.StringVal("")
civo_network.cluster_net: Creation complete after 3s [id=52c49e78-febf-4015-b889-f56385e62336]
civo_firewall.www: Creating...
2021-08-26T12:47:03.623+0800 [INFO]  Starting apply for civo_firewall.www
2021-08-26T12:47:03.624+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:47:03 [INFO] creating a new firewall www: timestamp=2021-08-26T12:47:03.624+0800
2021-08-26T12:47:05.623+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:47:05 [INFO] retriving the firewall 85873fad-c942-488b-8372-7899956cce2f: timestamp=2021-08-26T12:47:05.623+0800
civo_firewall.www: Creation complete after 3s [id=85873fad-c942-488b-8372-7899956cce2f]
civo_firewall_rule.http: Creating...
2021-08-26T12:47:07.396+0800 [INFO]  Starting apply for civo_firewall_rule.http
civo_firewall_rule.https: Creating...
2021-08-26T12:47:07.396+0800 [INFO]  Starting apply for civo_firewall_rule.https
2021-08-26T12:47:07.397+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:47:07 [DEBUG] setting computed for "cidr" from ComputedKeys: timestamp=2021-08-26T12:47:07.397+0800
2021-08-26T12:47:07.397+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:47:07 [DEBUG] setting computed for "cidr" from ComputedKeys: timestamp=2021-08-26T12:47:07.397+0800
2021-08-26T12:47:07.397+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:47:07 [INFO] configuring a new firewall rule for firewall 85873fad-c942-488b-8372-7899956cce2f: timestamp=2021-08-26T12:47:07.397+0800
2021-08-26T12:47:07.397+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:47:07 [INFO] configuring a new firewall rule for firewall 85873fad-c942-488b-8372-7899956cce2f: timestamp=2021-08-26T12:47:07.397+0800
2021-08-26T12:47:07.397+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:47:07 [INFO] Config: &{FirewallID:85873fad-c942-488b-8372-7899956cce2f Region: Protocol:tcp StartPort:443 EndPort:443 Cidr:[] Direction:ingress Label:server web}: timestamp=2021-08-26T12:47:07.397+0800
2021-08-26T12:47:07.397+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:47:07 [INFO] creating a new firewall rule for firewall 85873fad-c942-488b-8372-7899956cce2f: timestamp=2021-08-26T12:47:07.397+0800
2021-08-26T12:47:07.397+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:47:07 [INFO] Config: &{FirewallID:85873fad-c942-488b-8372-7899956cce2f Region: Protocol:tcp StartPort:80 EndPort:80 Cidr:[] Direction:ingress Label:server web}: timestamp=2021-08-26T12:47:07.397+0800
2021-08-26T12:47:07.397+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:47:07 [INFO] creating a new firewall rule for firewall 85873fad-c942-488b-8372-7899956cce2f: timestamp=2021-08-26T12:47:07.397+0800
2021-08-26T12:47:09.111+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:47:09 [INFO] RuleID: cb01ff7b-26ff-4529-8f94-ab3ec44a157e: timestamp=2021-08-26T12:47:09.111+0800
2021-08-26T12:47:09.112+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:47:09 [INFO] firewallID: 85873fad-c942-488b-8372-7899956cce2f: timestamp=2021-08-26T12:47:09.111+0800
2021-08-26T12:47:09.112+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:47:09 [INFO] RuleID: cb01ff7b-26ff-4529-8f94-ab3ec44a157e: timestamp=2021-08-26T12:47:09.111+0800
2021-08-26T12:47:09.112+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:47:09 [INFO] retriving the firewall rule cb01ff7b-26ff-4529-8f94-ab3ec44a157e: timestamp=2021-08-26T12:47:09.111+0800
2021-08-26T12:47:10.026+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:47:10 [INFO] rules &{ID:cb01ff7b-26ff-4529-8f94-ab3ec44a157e FirewallID:85873fad-c942-488b-8372-7899956cce2f Protocol:tcp StartPort:80 EndPort: Cidr:[] Direction:ingress Label:server web}: timestamp=2021-08-26T12:47:10.026+0800
civo_firewall_rule.http: Creation complete after 3s [id=cb01ff7b-26ff-4529-8f94-ab3ec44a157e]
╷
│ Error: [ERR] failed to create a new firewall: RegionUnavailable: Timed out communicating with that region
│
│   with civo_firewall_rule.https,
│   on main.tf line 20, in resource "civo_firewall_rule" "https":
│   20: resource "civo_firewall_rule" "https" {
│
╵


$ tf show
2021-08-26T12:50:01.847+0800 [INFO]  Terraform version: 1.0.3
2021-08-26T12:50:01.848+0800 [INFO]  Go runtime version: go1.16.4
2021-08-26T12:50:01.848+0800 [INFO]  CLI args: []string{"/usr/local/bin/terraform", "show"}
2021-08-26T12:50:01.848+0800 [INFO]  CLI command args: []string{"show"}
2021-08-26T12:50:01.913+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-26T12:50:01.915+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T12:50:01.964+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T12:50:01.964+0800
# civo_firewall.www:
resource "civo_firewall" "www" {
    id         = "85873fad-c942-488b-8372-7899956cce2f"
    name       = "www"
    network_id = "52c49e78-febf-4015-b889-f56385e62336"
}

# civo_firewall_rule.http:
resource "civo_firewall_rule" "http" {
    cidr        = [
        "",
    ]
    direction   = "ingress"
    end_port    = "80"
    firewall_id = "85873fad-c942-488b-8372-7899956cce2f"
    id          = "cb01ff7b-26ff-4529-8f94-ab3ec44a157e"
    label       = "server web"
    protocol    = "tcp"
    start_port  = "80"
}

# civo_network.cluster_net:
resource "civo_network" "cluster_net" {
    default = false
    id      = "52c49e78-febf-4015-b889-f56385e62336"
    label   = "my-custom-network"
    name    = "cust-433e075e-a401-my-custom-network"
}

When I checked Civo.com, only one firewall rule get created:

1

And when I rerun it, then it creates the second firewall rule:

$ tf apply --auto-approve
2021-08-26T12:53:22.001+0800 [INFO]  Terraform version: 1.0.3
2021-08-26T12:53:22.001+0800 [INFO]  Go runtime version: go1.16.4
2021-08-26T12:53:22.001+0800 [INFO]  CLI args: []string{"/usr/local/bin/terraform", "apply", "--auto-approve"}
2021-08-26T12:53:22.003+0800 [INFO]  CLI command args: []string{"apply", "--auto-approve"}
2021-08-26T12:53:22.074+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-26T12:53:22.075+0800 [INFO]  backend/local: starting Apply operation
2021-08-26T12:53:22.082+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T12:53:22.134+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T12:53:22.134+0800
2021-08-26T12:53:22.210+0800 [INFO]  terraform: building graph: GraphTypeValidate
2021-08-26T12:53:22.212+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T12:53:22.258+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T12:53:22.258+0800
2021-08-26T12:53:22.335+0800 [INFO]  backend/local: apply calling Plan
2021-08-26T12:53:22.335+0800 [INFO]  terraform: building graph: GraphTypePlan
2021-08-26T12:53:22.337+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T12:53:22.383+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T12:53:22.383+0800
2021-08-26T12:53:22.456+0800 [WARN]  ValidateProviderConfig from "provider[\"registry.terraform.io/civo/civo\"]" changed the config value, but that value is unused
civo_network.cluster_net: Refreshing state... [id=52c49e78-febf-4015-b889-f56385e62336]
2021-08-26T12:53:22.461+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:53:22 [INFO] retriving the network 52c49e78-febf-4015-b889-f56385e62336: timestamp=2021-08-26T12:53:22.461+0800
2021-08-26T12:53:23.961+0800 [WARN]  Provider "registry.terraform.io/civo/civo" produced an invalid plan for civo_network.cluster_net, 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.www: Refreshing state... [id=85873fad-c942-488b-8372-7899956cce2f]
2021-08-26T12:53:23.965+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:53:23 [INFO] retriving the firewall 85873fad-c942-488b-8372-7899956cce2f: timestamp=2021-08-26T12:53:23.965+0800
2021-08-26T12:53:24.821+0800 [INFO]  ReferenceTransformer: reference not found: "civo_firewall.www"
2021-08-26T12:53:24.821+0800 [INFO]  ReferenceTransformer: reference not found: "civo_firewall.www"
civo_firewall_rule.http: Refreshing state... [id=cb01ff7b-26ff-4529-8f94-ab3ec44a157e]
2021-08-26T12:53:24.824+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:53:24 [INFO] firewallID: 85873fad-c942-488b-8372-7899956cce2f: timestamp=2021-08-26T12:53:24.824+0800
2021-08-26T12:53:24.824+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:53:24 [INFO] RuleID: cb01ff7b-26ff-4529-8f94-ab3ec44a157e: timestamp=2021-08-26T12:53:24.824+0800
2021-08-26T12:53:24.824+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:53:24 [INFO] retriving the firewall rule cb01ff7b-26ff-4529-8f94-ab3ec44a157e: timestamp=2021-08-26T12:53:24.824+0800
2021-08-26T12:53:25.635+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:53:25 [INFO] rules &{ID:cb01ff7b-26ff-4529-8f94-ab3ec44a157e FirewallID:85873fad-c942-488b-8372-7899956cce2f Protocol:tcp StartPort:80 EndPort: Cidr:[] Direction:ingress Label:server web}: timestamp=2021-08-26T12:53:25.635+0800

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

Terraform will perform the following actions:

  # civo_firewall_rule.https will be created
  + resource "civo_firewall_rule" "https" {
      + cidr        = (known after apply)
      + direction   = "ingress"
      + end_port    = "443"
      + firewall_id = "85873fad-c942-488b-8372-7899956cce2f"
      + id          = (known after apply)
      + label       = "server web"
      + protocol    = "tcp"
      + region      = (known after apply)
      + start_port  = "443"
    }

Plan: 1 to add, 0 to change, 0 to destroy.
2021-08-26T12:53:25.650+0800 [INFO]  backend/local: apply calling Apply
2021-08-26T12:53:25.650+0800 [INFO]  terraform: building graph: GraphTypeApply
2021-08-26T12:53:25.652+0800 [INFO]  ReferenceTransformer: reference not found: "civo_firewall.www#destroy"
2021-08-26T12:53:25.654+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T12:53:25.713+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T12:53:25.712+0800
2021-08-26T12:53:25.788+0800 [WARN]  ValidateProviderConfig from "provider[\"registry.terraform.io/civo/civo\"]" changed the config value, but that value is unused
civo_firewall_rule.https: Creating...
2021-08-26T12:53:25.791+0800 [INFO]  Starting apply for civo_firewall_rule.https
2021-08-26T12:53:25.792+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:53:25 [DEBUG] setting computed for "cidr" from ComputedKeys: timestamp=2021-08-26T12:53:25.792+0800
2021-08-26T12:53:25.792+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:53:25 [INFO] configuring a new firewall rule for firewall 85873fad-c942-488b-8372-7899956cce2f: timestamp=2021-08-26T12:53:25.792+0800
2021-08-26T12:53:25.792+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:53:25 [INFO] Config: &{FirewallID:85873fad-c942-488b-8372-7899956cce2f Region: Protocol:tcp StartPort:443 EndPort:443 Cidr:[] Direction:ingress Label:server web}: timestamp=2021-08-26T12:53:25.792+0800
2021-08-26T12:53:25.792+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:53:25 [INFO] creating a new firewall rule for firewall 85873fad-c942-488b-8372-7899956cce2f: timestamp=2021-08-26T12:53:25.792+0800
2021-08-26T12:53:28.263+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:53:28 [INFO] RuleID: 4addb235-f59b-4220-8af0-60ad7c1611de: timestamp=2021-08-26T12:53:28.263+0800
2021-08-26T12:53:28.263+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:53:28 [INFO] firewallID: 85873fad-c942-488b-8372-7899956cce2f: timestamp=2021-08-26T12:53:28.263+0800
2021-08-26T12:53:28.264+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:53:28 [INFO] RuleID: 4addb235-f59b-4220-8af0-60ad7c1611de: timestamp=2021-08-26T12:53:28.263+0800
2021-08-26T12:53:28.264+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:53:28 [INFO] retriving the firewall rule 4addb235-f59b-4220-8af0-60ad7c1611de: timestamp=2021-08-26T12:53:28.263+0800
2021-08-26T12:53:29.118+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:53:29 [INFO] rules &{ID:4addb235-f59b-4220-8af0-60ad7c1611de FirewallID:85873fad-c942-488b-8372-7899956cce2f Protocol:tcp StartPort:443 EndPort: Cidr:[] Direction:ingress Label:server web}: timestamp=2021-08-26T12:53:29.118+0800
civo_firewall_rule.https: Creation complete after 3s [id=4addb235-f59b-4220-8af0-60ad7c1611de]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.


$ tf show
2021-08-26T12:53:33.148+0800 [INFO]  Terraform version: 1.0.3
2021-08-26T12:53:33.148+0800 [INFO]  Go runtime version: go1.16.4
2021-08-26T12:53:33.148+0800 [INFO]  CLI args: []string{"/usr/local/bin/terraform", "show"}
2021-08-26T12:53:33.149+0800 [INFO]  CLI command args: []string{"show"}
2021-08-26T12:53:33.215+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-26T12:53:33.217+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T12:53:33.266+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T12:53:33.265+0800
# civo_firewall.www:
resource "civo_firewall" "www" {
    id         = "85873fad-c942-488b-8372-7899956cce2f"
    name       = "www"
    network_id = "52c49e78-febf-4015-b889-f56385e62336"
}

# civo_firewall_rule.http:
resource "civo_firewall_rule" "http" {
    cidr        = [
        "",
    ]
    direction   = "ingress"
    end_port    = "80"
    firewall_id = "85873fad-c942-488b-8372-7899956cce2f"
    id          = "cb01ff7b-26ff-4529-8f94-ab3ec44a157e"
    label       = "server web"
    protocol    = "tcp"
    start_port  = "80"
}

# civo_firewall_rule.https:
resource "civo_firewall_rule" "https" {
    cidr        = [
        "",
    ]
    direction   = "ingress"
    end_port    = "443"
    firewall_id = "85873fad-c942-488b-8372-7899956cce2f"
    id          = "4addb235-f59b-4220-8af0-60ad7c1611de"
    label       = "server web"
    protocol    = "tcp"
    start_port  = "443"
}

# civo_network.cluster_net:
resource "civo_network" "cluster_net" {
    default = false
    id      = "52c49e78-febf-4015-b889-f56385e62336"
    label   = "my-custom-network"
    name    = "cust-433e075e-a401-my-custom-network"
}

terraform plan throwing Error: Error in function call

On running terraform plan, i get the below error

Error: Error in function call

on instances.tf line 5, in resource "civo_instance" "my-test-instance":
5: size = element(data.civo_instances_size.small.sizes, 0).name
|----------------
| data.civo_instances_size.small.sizes is empty list of object

The screenshot below shows compilation error in the instances.tf file

Screenshot-3

Cannot use provider with Terraform v0.13

This is more of a heads up/warning but I was playing around with the civo provider today and noticed that it is unusable since upgrading to Terraform version 0.13.0-beta1.

Despite having the provider locally as described in the docs (which previously worked fine), with the upgrade to v0.13 terraform now seems to ignore this and search the registry for the civo provider, where it is not currently available from.

Obviously terraform 0.13 is still in beta, but I thought it best to bring this to attention before 0.13 is released for general use.

image

DNS record type causes update in-place

When using a resource civo_dns_domain_record to create a DNS record the type must be "A", but the terraform.tfstate stores this type as "a".

This difference causes an update in-place each time you try to apply anything.
image

can't add node pool version 0.10.6

Given this main.tf, and using 0.10.6 civo provider.

resource "civo_kubernetes_cluster" "my-cluster" {
    name = "tftest2"
    region = "LON1"
    applications = "Traefik"
    num_target_nodes = 1
    target_nodes_size = "g3.k3s.xsmall"
}

which was applied successfully.

after which I amended the file to add a resource, and expected a node-pool to be added.

resource "civo_kubernetes_cluster" "my-cluster" {
    name = "tftest2"
    region = "LON1"
    applications = "Traefik"
    num_target_nodes = 1
    target_nodes_size = "g3.k3s.xsmall"
}

resource "civo_kubernetes_node_pool" "front-end" {
   cluster_id = civo_kubernetes_cluster.my-cluster.id
   num_target_nodes = 4
}

terraform apply fails. And I see this error first:

2021-07-23T10:48:32.979Z [WARN] Provider "registry.terraform.io/civo/civo" produced an unexpected new value for civo_kubernetes_cluster.my-cluster during refresh.

after which the command fails with

Error: DatabaseKubernetesClusterNotFound: Failed to find the Kubernetes cluster in the internal database

which doesn't make sense to me, as via terraform console I can obtain info

> civo_kubernetes_cluster.my-cluster.id
"eb89156e-3744-4b59-bf9a-5bf155388c96

command output of terraform apply with TF_LOG=INFO

civo_kubernetes_cluster.my-cluster: Refreshing state... [id=eb89156e-3744-4b59-bf9a-5bf155388c96]
2021-07-23T10:48:31.056Z [INFO]  provider.terraform-provider-civo_v0.10.6: 2021/07/23 10:48:31 [INFO] retrieving the kubernetes cluster eb89156e-3744-4b59-bf9a-5bf155388c96: timestamp=2021-07-23T10:48:31.056Z
2021-07-23T10:48:32.979Z [WARN]  Provider "registry.terraform.io/civo/civo" produced an unexpected new value for civo_kubernetes_cluster.my-cluster during refresh.
      - .built_at: was cty.StringVal("2021-07-23 10:48:20.325 +0000 UTC"), but now cty.StringVal("2021-07-23 10:48:32.84 +0000 UTC")
2021-07-23T10:48:32.988Z [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

Note: Objects have changed outside of Terraform

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

  # civo_kubernetes_cluster.my-cluster has been changed
  ~ resource "civo_kubernetes_cluster" "my-cluster" {
      ~ built_at               = "2021-07-23 10:48:20.325 +0000 UTC" -> "2021-07-23 10:48:32.84 +0000 UTC"
        id                     = "eb89156e-3744-4b59-bf9a-5bf155388c96"
        name                   = "tftest2"
        # (16 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:
  + create

Terraform will perform the following actions:

  # civo_kubernetes_node_pool.front-end will be created
  + resource "civo_kubernetes_node_pool" "front-end" {
      + cluster_id        = "eb89156e-3744-4b59-bf9a-5bf155388c96"
      + id                = (known after apply)
      + num_target_nodes  = 4
      + target_nodes_size = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.
2021-07-23T10:48:33.012Z [INFO]  backend/local: apply calling Apply
2021-07-23T10:48:33.012Z [INFO]  terraform: building graph: GraphTypeApply
2021-07-23T10:48:33.017Z [INFO]  provider: configuring client automatic mTLS
2021-07-23T10:48:33.190Z [INFO]  provider.terraform-provider-civo_v0.10.6: configuring server automatic mTLS: timestamp=2021-07-23T10:48:33.190Z
2021-07-23T10:48:33.496Z [WARN]  ValidateProviderConfig from "provider[\"registry.terraform.io/civo/civo\"]" changed the config value, but that value is unused
civo_kubernetes_node_pool.front-end: Creating...
2021-07-23T10:48:33.505Z [INFO]  Starting apply for civo_kubernetes_node_pool.front-end
╷
│ Error: DatabaseKubernetesClusterNotFound: Failed to find the Kubernetes cluster in the internal database
│ 
│   with civo_kubernetes_node_pool.front-end,
│   on main.tf line 9, in resource "civo_kubernetes_node_pool" "front-end":
│    9: resource "civo_kubernetes_node_pool" "front-end" {
│ 
╵

Missing `direction` in `civo_firewall_rule`'s state

The API is giving null for firewall rule's direction field.

Screenshots:

Screenshot 2021-08-27 at 2 58 34 PM

Screenshot 2021-08-27 at 2 59 58 PM

Due to that, the direction state becomes empty. Example state file:

{
   "version":4,
   "terraform_version":"1.0.3",
   "serial":68,
   "lineage":"3ad22ac4-06de-aaeb-c6ea-fb1a3171e837",
   "outputs":{
      
   },
   "resources":[
      {
         "mode":"managed",
         "type":"civo_firewall_rule",
         "name":"http",
         "provider":"provider[\"registry.terraform.io/civo/civo\"]",
         "instances":[
            {
               "schema_version":0,
               "attributes":{
                  "cidr":[
                     ""
                  ],
                  "direction":"",
                  "end_port":"80",
                  "firewall_id":"35b1a10e-f8ff-4dca-9ca7-18bcefca21a0",
                  "id":"01fe67e3-6f09-44b1-8b3d-37f74b2f017b",
                  "label":"web-server",
                  "protocol":"tcp",
                  "region":null,
                  "start_port":"80"
               },
               "sensitive_attributes":[
                  
               ],
               "private":"bnVsbA==",
               "dependencies":[
                  "civo_firewall.my_custom_firewall",
                  "civo_network.my_custom_network"
               ]
            }
         ]
      }
   ]
}

Since we have ForceNew attribute for direction schema, a new firewall rule will always get created when we run terraform apply command — even we didn't change anything in the Terraform configuration file.

Example:

Screenshot 2021-08-27 at 3 15 43 PM

This happens because the current state is ("") and Terraform sees otherwise in our Terraform configuration file (e.g. ingress) and it thinks the direction field has changed and say "let's create a new one".

To fix:

Not much we can do here or in civogo. The change needs to be in Civo API. This issue was created just for tracking purpose so we can retest it again after the API is updated to correctly return direction value.

Applications -traefik Not Respected

I've spun up a few clusters using the Pulumi provider, which wraps this.

I'm using applications: ["-traefik"], but I always get traefik deployed to my cluster.

Confusing example with node_size data block

In the docs it shows how to search for small nodes

data "civo_instances_size" "small" {
    filter {
        key = "name"
        values = ["small"]
        match_by = "re"
    }
}

Which (in the kubernetes doc) is used to create a cluster with 4 "small" nodes.

This actually pulls out the first entry returned which is the xsmall nodes, as seen in this output.

Outputs:

node_size = {
  "filter" = toset([
    {
      "all" = false
      "key" = "name"
      "match_by" = "re"
      "values" = tolist([
        "small",
      ])
    },
  ])
  "id" = "terraform-20210512072045928100000001"
  "sizes" = tolist([
    {
      "cpu" = 1
      "description" = "Extra Small"
      "disk" = 25
      "name" = "g3.xsmall"
      "ram" = 1024
      "selectable" = true
      "type" = "instance"
    },
    {
      "cpu" = 1
      "description" = "Small"
      "disk" = 25
      "name" = "g3.small"
      "ram" = 2048
      "selectable" = true
      "type" = "instance"
    },
    {
      "cpu" = 1
      "description" = "Extra Small"
      "disk" = 15
      "name" = "g3.k3s.xsmall"
      "ram" = 1024
      "selectable" = true
      "type" = "kubernetes"
    },
    {
      "cpu" = 1
      "description" = "Small"
      "disk" = 15
      "name" = "g3.k3s.small"
      "ram" = 2048
      "selectable" = true
      "type" = "kubernetes"
    },
  ])
  "sort" = tolist(null) /* of object */
}

If i change the selector to g3.small it then outputs

  # civo_kubernetes_cluster.this will be updated in-place
  ~ resource "civo_kubernetes_cluster" "this" {
        id                     = "19dccf7e-2cb3-40da-a207-bba1654f6f26"
        name                   = "openfaas-cluster"
      ~ target_nodes_size      = "g3.xsmall" -> "g3.small"
        # (15 unchanged attributes hidden)
    }

which is selecting the small size.

unable to use the custom module with terraform

When trying to use civo/civo provider with custom module results in the module being searched under hashicorp/civo and the module is not initialised.

Clone the reproducer https://github.com/kameshsampath/civo-example and doing terraform init will result in the following error:

Initializing modules...
- k3s in modules/k3s

Initializing the backend...

Initializing provider plugins...
- Finding hashicorp/helm versions matching "2.2.0"...
- Finding latest version of hashicorp/civo...
- Finding hashicorp/null versions matching "3.1.0"...
- Finding civo/civo versions matching "0.10.9"...
- Finding hashicorp/kubernetes versions matching "2.4.1"...
- Installing hashicorp/helm v2.2.0...
- Installed hashicorp/helm v2.2.0 (signed by HashiCorp)
- Installing hashicorp/null v3.1.0...
- Installed hashicorp/null v3.1.0 (signed by HashiCorp)
- Installing civo/civo v0.10.9...
- Installed civo/civo v0.10.9 (signed by a HashiCorp partner, key ID CA1DE390990EBE66)
- Installing hashicorp/kubernetes v2.4.1...
- Installed hashicorp/kubernetes v2.4.1 (signed by HashiCorp)

Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/cli/plugins/signing.html
╷
│ Error: Failed to query available provider packages
│ 

If you try to run without custom module things work as expected.

CC: @saiyam1814 @alejandrojnm

Allow network data source query by `region`

Related to #83, the following network query via data source will fail.

Config file:

data "civo_network" "test" {
    label = "Default"
    region = "LON1"
}

Traces

╷
│ Error: ExactlyOne
│
│   with data.civo_network.test,
│   on main.tf line 17, in data "civo_network" "test":
│   17: data "civo_network" "test" {
│
│ "id": only one of `id,label,region` can be specified, but `label,region` were specified.
╵
╷
│ Error: ExactlyOne
│
│   with data.civo_network.test,
│   on main.tf line 18, in data "civo_network" "test":
│   18:     label = "Default"
│
│ "label": only one of `id,label,region` can be specified, but `label,region` were specified.
╵

User should be able to query network by region with/without label. And not just by label.

return a descriptive error when api call fails

Iam getting the following error:

[ERROR] eval: *terraform.evalReadDataRefresh, err: Unable to load records: [ERR] error retrieving all templates: Unknow Error

For this piece of code:

data "civo_template" "ubuntu" {
   filter {
        key = "code"
        values = ["ubuntu-18.04"]
   }
}

I got the same error for this other piece of code (note, the error above started to appear out of no where, the code usually fail in bellow step)

Error: [ERR] failed to create instance: Unknow Error

  on ../civo_ha/provider.tf line 57, in resource "civo_instance" "node_02":
  57: resource "civo_instance" "node_02" {

And last week I got the same error beacuse I was using a wrong token, this lead to almost impossible way to troubleshoot what´s is going on.

`civo_kubernetes_cluster` scale up is not working as expected

First created a civo_kubernetes_cluster resource using the following tf file:

resource "civo_kubernetes_cluster" "my-cluster" {
    name = "my-cluster"
    num_target_nodes = 3
    target_nodes_size = "g3.k3s.xsmall"
}

Then updated the num_target_nodes field to 5 and applied again.

resource "civo_kubernetes_cluster" "my-cluster" {
    name = "my-cluster"
    num_target_nodes = 5
    target_nodes_size = "g3.k3s.xsmall"
}

Expected to see 5 nodes on the cluster. But it only scales up to 4 and the terraform apply command returns successfully.

Failed to install provider

Hello,

Trying to play with Terraform provider of CIVO. Getting the below error after running terraform plan - screenshot attached
Screenshot-1

F:\codebase\civo-terraform\config>terraform plan

Error: Could not load plugin

Plugin reinitialization required. Please run "terraform init".

Plugins are external binaries that Terraform uses to access and manipulate
resources. The configuration provided requires plugins which can't be located,
don't satisfy the version constraints, or are otherwise incompatible.

Terraform automatically discovers provider requirements from your
configuration, including providers used in child modules. To see the
requirements and constraints, run "terraform providers".

Failed to instantiate provider "registry.terraform.io/hashicorp/civo" to
obtain schema: unknown provider "registry.terraform.io/hashicorp/civo"

F:\codebase\civo-terraform\config>terraform init

Initializing the backend...

Initializing provider plugins...

  • Finding latest version of hashicorp/civo...

Error: Failed to install provider

Error while installing hashicorp/civo: provider registry registry.terraform.io
does not have a provider named registry.terraform.io/hashicorp/civo

Check if provided network ID exists in region before creating volume

When the provider has no region, it will use NYC1 region as default (I believe this is being done by Civo API server and not by civogo).

When user did a data query for network, it will return a network from NYC1 (note: network data source can't accept both label and region at this moment).

Now, when user wants to create a civo_volume in LON1 region, the passed down network id is incorrect/not exists in LON1. The id is network ID in NYC1 region.

Hence, the volume creation failed (see traces below). What we should do here is, we should check if the provided network ID exists in region before creating volume.

Also, we need to allow user to query network data source by label and region and not just limited to label. I'll create a separate issue for this one.


Case 1

provider "civo" {
    token = "api-token"
}

data "civo_network" "default_network" {
    label = "Default"
}

resource "civo_volume" "db" {
    name = "backup-data"
    size_gb = 5
    network_id = data.civo_network.default_network.id
    depends_on = [
      data.civo_network.default_network
    ]
}

Result:

backup-data volume created successfully in NYC1 region (I guess Civo API uses NYC1 as default region)


Case 2

provider "civo" {
    token = "api-token"
    region = "LON1"
}

data "civo_network" "default_network" {
    label = "Default"
}

resource "civo_volume" "db" {
    name = "backup-data"
    size_gb = 5
    network_id = data.civo_network.default_network.id
    depends_on = [
      data.civo_network.default_network
    ]
}

Result:

backup-data volume created successfully in LON1 region


Case 3

provider "civo" {
    token = "api-token"
}

data "civo_network" "default_network" {
    label = "Default"
}

resource "civo_volume" "db" {
    name = "backup-data"
    size_gb = 5
    network_id = data.civo_network.default_network.id
    depends_on = [
      data.civo_network.default_network
    ]
    region = "LON1"
}

Result:

The volume didn't created. The following error occured:

tf apply --auto-approve
civo_volume.db: Refreshing state... [id=f71a6e92-8372-4d26-91d3-d756168ce917]

Note: Objects have changed outside of Terraform

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

  # civo_volume.db has been deleted
  - resource "civo_volume" "db" {
      - id         = "f71a6e92-8372-4d26-91d3-d756168ce917" -> null
      - name       = "backup-data" -> null
      - network_id = "5c16ab17-933a-46ed-96c6-8a093a0179e1" -> null
      - size_gb    = 5 -> null
    }

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:
  + create

Terraform will perform the following actions:

  # civo_volume.db will be created
  + resource "civo_volume" "db" {
      + id          = (known after apply)
      + mount_point = (known after apply)
      + name        = "backup-data"
      + network_id  = "fb3cdfff-66ba-4048-9f37-8625237cbe67"
      + region      = "LON1"
      + size_gb     = 5
    }

Plan: 1 to add, 0 to change, 0 to destroy.
civo_volume.db: Creating...
╷
│ Error: [ERR] failed to create a new volume: Error: Unknown error response - status: 400 Bad Request, code: 400, reason: {"code":"parameter_network_id_invalid","result":"failed","reason":"The network_id supplied was empty"}
│
│   with civo_volume.db,
│   on main.tf line 7, in resource "civo_volume" "db":
│    7: resource "civo_volume" "db" {
│
╵

Unable to create kubernetes cluster

When trying to create a cluster i get the following error:

Error: [ERR] failed to create the kubernets cluster: DatabaseServiceNotFoundError: Failed to find the size within the internal database

Show available node sizes in documentation

The documentation doesn't show any hints on the available node sizes for a Kubernetes Cluster.
You can find a reference to a Data Source in the Example Usage for the civo_kubernetes_cluster, but that one is a bit misleading, because the Data Source is not configured in the example.

Furthermore if you then check out the Data Source, you still have to get to know a fitting value to match against or fiddle around with Terraform to get the information.

I think it is better to add a table to the documentation or to link a external source with information about the current sizes, so people can easily start with creating cluster 🚀


Currently a way to check sizes is either via https://www.civo.com/api/sizes#listing-available-sizes
or with following Data Source in Terraform:

data "civo_instances_size" "test" {
    filter {
        key = "name"
        values = [""]
        match_by = "re"
    }
}

output "sizes" {
  value = data.civo_instances_size.test.sizes
}

EDIT:
The sizes can also be shown via Civo CLI, but Civo CLI should not be a requirement to have a quick working Terraform setup:

civo kubernetes size
+----------------+-------------+------------+-----+-------+-----+------------+
| Name           | Description | Type       | CPU | RAM   | SSD | Selectable |
+----------------+-------------+------------+-----+-------+-----+------------+
| g3.k3s.xsmall  | Extra Small | Kubernetes |   1 |  1024 |  15 | Yes        |
| g3.k3s.small   | Small       | Kubernetes |   1 |  2048 |  15 | Yes        |
| g3.k3s.medium  | Medium      | Kubernetes |   2 |  4096 |  15 | Yes        |
| g3.k3s.large   | Large       | Kubernetes |   4 |  8192 |  15 | Yes        |
| g3.k3s.xlarge  | Extra Large | Kubernetes |   6 | 16384 |  15 | Yes        |
| g3.k3s.2xlarge | 2X Large    | Kubernetes |   8 | 32768 |  15 | Yes        |
+----------------+-------------+------------+-----+-------+-----+------------+

Firewall rule CIDR should be required

The cidr field in civo_firewall_rule is currently optional. But the docs says it's required.

I think it should be required because a valid firewall rule should have a CIDR. Otherwise, it will be empty like this:

Screenshot 2021-08-26 at 9 27 10 AM

Unable to destroy multiple firewall rules

$ tf show
2021-08-26T12:55:58.978+0800 [INFO]  Terraform version: 1.0.3
2021-08-26T12:55:58.978+0800 [INFO]  Go runtime version: go1.16.4
2021-08-26T12:55:58.978+0800 [INFO]  CLI args: []string{"/usr/local/bin/terraform", "show"}
2021-08-26T12:55:58.978+0800 [INFO]  CLI command args: []string{"show"}
2021-08-26T12:55:59.041+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-26T12:55:59.043+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T12:55:59.092+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T12:55:59.092+0800
# civo_firewall.www:
resource "civo_firewall" "www" {
    id         = "85873fad-c942-488b-8372-7899956cce2f"
    name       = "www"
    network_id = "52c49e78-febf-4015-b889-f56385e62336"
}

# civo_firewall_rule.http:
resource "civo_firewall_rule" "http" {
    cidr        = [
        "",
    ]
    direction   = "ingress"
    end_port    = "80"
    firewall_id = "85873fad-c942-488b-8372-7899956cce2f"
    id          = "cb01ff7b-26ff-4529-8f94-ab3ec44a157e"
    label       = "server web"
    protocol    = "tcp"
    start_port  = "80"
}

# civo_firewall_rule.https:
resource "civo_firewall_rule" "https" {
    cidr        = [
        "",
    ]
    direction   = "ingress"
    end_port    = "443"
    firewall_id = "85873fad-c942-488b-8372-7899956cce2f"
    id          = "4addb235-f59b-4220-8af0-60ad7c1611de"
    label       = "server web"
    protocol    = "tcp"
    start_port  = "443"
}

# civo_network.cluster_net:
resource "civo_network" "cluster_net" {
    default = false
    id      = "52c49e78-febf-4015-b889-f56385e62336"
    label   = "my-custom-network"
    name    = "cust-433e075e-a401-my-custom-network"
}


$ tf destroy --auto-approve
2021-08-26T12:56:06.102+0800 [INFO]  Terraform version: 1.0.3
2021-08-26T12:56:06.102+0800 [INFO]  Go runtime version: go1.16.4
2021-08-26T12:56:06.102+0800 [INFO]  CLI args: []string{"/usr/local/bin/terraform", "destroy", "--auto-approve"}
2021-08-26T12:56:06.102+0800 [INFO]  CLI command args: []string{"destroy", "--auto-approve"}
2021-08-26T12:56:06.166+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-26T12:56:06.166+0800 [INFO]  backend/local: starting Apply operation
2021-08-26T12:56:06.168+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T12:56:06.217+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T12:56:06.217+0800
2021-08-26T12:56:06.292+0800 [INFO]  terraform: building graph: GraphTypeValidate
2021-08-26T12:56:06.294+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T12:56:06.343+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T12:56:06.343+0800
2021-08-26T12:56:06.420+0800 [INFO]  backend/local: apply calling Plan
2021-08-26T12:56:06.421+0800 [INFO]  terraform: building graph: GraphTypePlan
2021-08-26T12:56:06.423+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T12:56:06.468+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T12:56:06.468+0800
2021-08-26T12:56:06.541+0800 [WARN]  ValidateProviderConfig from "provider[\"registry.terraform.io/civo/civo\"]" changed the config value, but that value is unused
civo_network.cluster_net: Refreshing state... [id=52c49e78-febf-4015-b889-f56385e62336]
2021-08-26T12:56:06.543+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:56:06 [INFO] retriving the network 52c49e78-febf-4015-b889-f56385e62336: timestamp=2021-08-26T12:56:06.543+0800
2021-08-26T12:56:08.049+0800 [WARN]  Provider "registry.terraform.io/civo/civo" produced an invalid plan for civo_network.cluster_net, 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.www: Refreshing state... [id=85873fad-c942-488b-8372-7899956cce2f]
2021-08-26T12:56:08.054+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:56:08 [INFO] retriving the firewall 85873fad-c942-488b-8372-7899956cce2f: timestamp=2021-08-26T12:56:08.054+0800
2021-08-26T12:56:08.422+0800 [INFO]  ReferenceTransformer: reference not found: "civo_firewall.www"
2021-08-26T12:56:08.423+0800 [INFO]  ReferenceTransformer: reference not found: "civo_firewall.www"
civo_firewall_rule.http: Refreshing state... [id=cb01ff7b-26ff-4529-8f94-ab3ec44a157e]
civo_firewall_rule.https: Refreshing state... [id=4addb235-f59b-4220-8af0-60ad7c1611de]
2021-08-26T12:56:08.426+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:56:08 [INFO] firewallID: 85873fad-c942-488b-8372-7899956cce2f: timestamp=2021-08-26T12:56:08.426+0800
2021-08-26T12:56:08.426+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:56:08 [INFO] RuleID: 4addb235-f59b-4220-8af0-60ad7c1611de: timestamp=2021-08-26T12:56:08.426+0800
2021-08-26T12:56:08.426+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:56:08 [INFO] retriving the firewall rule 4addb235-f59b-4220-8af0-60ad7c1611de: timestamp=2021-08-26T12:56:08.426+0800
2021-08-26T12:56:08.426+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:56:08 [INFO] firewallID: 85873fad-c942-488b-8372-7899956cce2f: timestamp=2021-08-26T12:56:08.426+0800
2021-08-26T12:56:08.426+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:56:08 [INFO] RuleID: cb01ff7b-26ff-4529-8f94-ab3ec44a157e: timestamp=2021-08-26T12:56:08.426+0800
2021-08-26T12:56:08.426+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:56:08 [INFO] retriving the firewall rule cb01ff7b-26ff-4529-8f94-ab3ec44a157e: timestamp=2021-08-26T12:56:08.426+0800
2021-08-26T12:56:09.478+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:56:09 [INFO] rules &{ID:cb01ff7b-26ff-4529-8f94-ab3ec44a157e FirewallID:85873fad-c942-488b-8372-7899956cce2f Protocol:tcp StartPort:80 EndPort: Cidr:[] Direction:ingress Label:server web}: timestamp=2021-08-26T12:56:09.478+0800
2021-08-26T12:56:09.478+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:56:09 [INFO] rules &{ID:4addb235-f59b-4220-8af0-60ad7c1611de FirewallID:85873fad-c942-488b-8372-7899956cce2f Protocol:tcp StartPort:443 EndPort: Cidr:[] Direction:ingress Label:server web}: timestamp=2021-08-26T12:56:09.478+0800
2021-08-26T12:56:09.490+0800 [INFO]  terraform: building graph: GraphTypePlanDestroy
2021-08-26T12:56:09.492+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T12:56:09.548+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T12:56:09.548+0800

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.www will be destroyed
  - resource "civo_firewall" "www" {
      - id         = "85873fad-c942-488b-8372-7899956cce2f" -> null
      - name       = "www" -> null
      - network_id = "52c49e78-febf-4015-b889-f56385e62336" -> null
    }

  # civo_firewall_rule.http will be destroyed
  - resource "civo_firewall_rule" "http" {
      - cidr        = [
          - "",
        ] -> null
      - direction   = "ingress" -> null
      - end_port    = "80" -> null
      - firewall_id = "85873fad-c942-488b-8372-7899956cce2f" -> null
      - id          = "cb01ff7b-26ff-4529-8f94-ab3ec44a157e" -> null
      - label       = "server web" -> null
      - protocol    = "tcp" -> null
      - start_port  = "80" -> null
    }

  # civo_firewall_rule.https will be destroyed
  - resource "civo_firewall_rule" "https" {
      - cidr        = [
          - "",
        ] -> null
      - direction   = "ingress" -> null
      - end_port    = "443" -> null
      - firewall_id = "85873fad-c942-488b-8372-7899956cce2f" -> null
      - id          = "4addb235-f59b-4220-8af0-60ad7c1611de" -> null
      - label       = "server web" -> null
      - protocol    = "tcp" -> null
      - start_port  = "443" -> null
    }

  # civo_network.cluster_net will be destroyed
  - resource "civo_network" "cluster_net" {
      - default = false -> null
      - id      = "52c49e78-febf-4015-b889-f56385e62336" -> 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-26T12:56:09.629+0800 [INFO]  backend/local: apply calling Apply
2021-08-26T12:56:09.629+0800 [INFO]  terraform: building graph: GraphTypeApply
2021-08-26T12:56:09.631+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T12:56:09.678+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T12:56:09.678+0800
2021-08-26T12:56:09.752+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=cb01ff7b-26ff-4529-8f94-ab3ec44a157e]
2021-08-26T12:56:09.755+0800 [INFO]  Starting apply for civo_firewall_rule.http
2021-08-26T12:56:09.755+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:56:09 [INFO] retriving the firewall rule cb01ff7b-26ff-4529-8f94-ab3ec44a157e: timestamp=2021-08-26T12:56:09.755+0800
civo_firewall_rule.https: Destroying... [id=4addb235-f59b-4220-8af0-60ad7c1611de]
2021-08-26T12:56:09.755+0800 [INFO]  Starting apply for civo_firewall_rule.https
2021-08-26T12:56:09.756+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 12:56:09 [INFO] retriving the firewall rule 4addb235-f59b-4220-8af0-60ad7c1611de: timestamp=2021-08-26T12:56:09.756+0800
civo_firewall_rule.http: Destruction complete after 2s
╷
│ Error: [ERR] an error occurred while tring to delete firewall rule 4addb235-f59b-4220-8af0-60ad7c1611de - RegionUnavailable: Timed out communicating with that region
│
│
╵

When I checked Civo.com, it only deletes one firewall (port 80). Port 443 is still there.

2

And when I rerun it, it went through successfully. I check Civo.com and the network, firewall and firewall rule (port 443) all deleted.

$ tf show
2021-08-26T13:02:34.996+0800 [INFO]  Terraform version: 1.0.3
2021-08-26T13:02:34.996+0800 [INFO]  Go runtime version: go1.16.4
2021-08-26T13:02:34.996+0800 [INFO]  CLI args: []string{"/usr/local/bin/terraform", "show"}
2021-08-26T13:02:34.998+0800 [INFO]  CLI command args: []string{"show"}
2021-08-26T13:02:35.066+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-26T13:02:35.068+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T13:02:35.117+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T13:02:35.117+0800
# civo_firewall.www:
resource "civo_firewall" "www" {
    id         = "85873fad-c942-488b-8372-7899956cce2f"
    name       = "www"
    network_id = "52c49e78-febf-4015-b889-f56385e62336"
}

# civo_firewall_rule.https:
resource "civo_firewall_rule" "https" {
    cidr        = [
        "",
    ]
    direction   = "ingress"
    end_port    = "443"
    firewall_id = "85873fad-c942-488b-8372-7899956cce2f"
    id          = "4addb235-f59b-4220-8af0-60ad7c1611de"
    label       = "server web"
    protocol    = "tcp"
    start_port  = "443"
}

# civo_network.cluster_net:
resource "civo_network" "cluster_net" {
    default = false
    id      = "52c49e78-febf-4015-b889-f56385e62336"
    label   = "my-custom-network"
    name    = "cust-433e075e-a401-my-custom-network"
}


$ tf destroy --auto-approve
2021-08-26T13:02:39.386+0800 [INFO]  Terraform version: 1.0.3
2021-08-26T13:02:39.386+0800 [INFO]  Go runtime version: go1.16.4
2021-08-26T13:02:39.386+0800 [INFO]  CLI args: []string{"/usr/local/bin/terraform", "destroy", "--auto-approve"}
2021-08-26T13:02:39.387+0800 [INFO]  CLI command args: []string{"destroy", "--auto-approve"}
2021-08-26T13:02:39.450+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-26T13:02:39.451+0800 [INFO]  backend/local: starting Apply operation
2021-08-26T13:02:39.453+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T13:02:39.503+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T13:02:39.502+0800
2021-08-26T13:02:39.578+0800 [INFO]  terraform: building graph: GraphTypeValidate
2021-08-26T13:02:39.579+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T13:02:39.626+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T13:02:39.626+0800
2021-08-26T13:02:39.702+0800 [INFO]  backend/local: apply calling Plan
2021-08-26T13:02:39.702+0800 [INFO]  terraform: building graph: GraphTypePlan
2021-08-26T13:02:39.704+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T13:02:39.750+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T13:02:39.750+0800
2021-08-26T13:02:39.827+0800 [WARN]  ValidateProviderConfig from "provider[\"registry.terraform.io/civo/civo\"]" changed the config value, but that value is unused
civo_network.cluster_net: Refreshing state... [id=52c49e78-febf-4015-b889-f56385e62336]
2021-08-26T13:02:39.829+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 13:02:39 [INFO] retriving the network 52c49e78-febf-4015-b889-f56385e62336: timestamp=2021-08-26T13:02:39.829+0800
2021-08-26T13:02:41.568+0800 [WARN]  Provider "registry.terraform.io/civo/civo" produced an invalid plan for civo_network.cluster_net, 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.www: Refreshing state... [id=85873fad-c942-488b-8372-7899956cce2f]
2021-08-26T13:02:41.573+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 13:02:41 [INFO] retriving the firewall 85873fad-c942-488b-8372-7899956cce2f: timestamp=2021-08-26T13:02:41.573+0800
2021-08-26T13:02:42.082+0800 [INFO]  ReferenceTransformer: reference not found: "civo_firewall.www"
2021-08-26T13:02:42.082+0800 [INFO]  ReferenceTransformer: reference not found: "civo_firewall.www"
civo_firewall_rule.https: Refreshing state... [id=4addb235-f59b-4220-8af0-60ad7c1611de]
2021-08-26T13:02:42.085+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 13:02:42 [INFO] firewallID: 85873fad-c942-488b-8372-7899956cce2f: timestamp=2021-08-26T13:02:42.085+0800
2021-08-26T13:02:42.085+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 13:02:42 [INFO] RuleID: 4addb235-f59b-4220-8af0-60ad7c1611de: timestamp=2021-08-26T13:02:42.085+0800
2021-08-26T13:02:42.085+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 13:02:42 [INFO] retriving the firewall rule 4addb235-f59b-4220-8af0-60ad7c1611de: timestamp=2021-08-26T13:02:42.085+0800
2021-08-26T13:02:42.895+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 13:02:42 [INFO] rules &{ID:4addb235-f59b-4220-8af0-60ad7c1611de FirewallID:85873fad-c942-488b-8372-7899956cce2f Protocol:tcp StartPort:443 EndPort: Cidr:[] Direction:ingress Label:server web}: timestamp=2021-08-26T13:02:42.895+0800
2021-08-26T13:02:42.905+0800 [INFO]  terraform: building graph: GraphTypePlanDestroy
2021-08-26T13:02:42.907+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T13:02:42.966+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T13:02:42.966+0800

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.www will be destroyed
  - resource "civo_firewall" "www" {
      - id         = "85873fad-c942-488b-8372-7899956cce2f" -> null
      - name       = "www" -> null
      - network_id = "52c49e78-febf-4015-b889-f56385e62336" -> null
    }

  # civo_firewall_rule.https will be destroyed
  - resource "civo_firewall_rule" "https" {
      - cidr        = [
          - "",
        ] -> null
      - direction   = "ingress" -> null
      - end_port    = "443" -> null
      - firewall_id = "85873fad-c942-488b-8372-7899956cce2f" -> null
      - id          = "4addb235-f59b-4220-8af0-60ad7c1611de" -> null
      - label       = "server web" -> null
      - protocol    = "tcp" -> null
      - start_port  = "443" -> null
    }

  # civo_network.cluster_net will be destroyed
  - resource "civo_network" "cluster_net" {
      - default = false -> null
      - id      = "52c49e78-febf-4015-b889-f56385e62336" -> null
      - label   = "my-custom-network" -> null
      - name    = "cust-433e075e-a401-my-custom-network" -> null
    }

Plan: 0 to add, 0 to change, 3 to destroy.
2021-08-26T13:02:43.042+0800 [INFO]  backend/local: apply calling Apply
2021-08-26T13:02:43.043+0800 [INFO]  terraform: building graph: GraphTypeApply
2021-08-26T13:02:43.044+0800 [INFO]  provider: configuring client automatic mTLS
2021-08-26T13:02:43.112+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: configuring server automatic mTLS: timestamp=2021-08-26T13:02:43.112+0800
2021-08-26T13:02:43.187+0800 [WARN]  ValidateProviderConfig from "provider[\"registry.terraform.io/civo/civo\"]" changed the config value, but that value is unused
civo_firewall_rule.https: Destroying... [id=4addb235-f59b-4220-8af0-60ad7c1611de]
2021-08-26T13:02:43.188+0800 [INFO]  Starting apply for civo_firewall_rule.https
2021-08-26T13:02:43.188+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 13:02:43 [INFO] retriving the firewall rule 4addb235-f59b-4220-8af0-60ad7c1611de: timestamp=2021-08-26T13:02:43.188+0800
civo_firewall_rule.https: Destruction complete after 2s
civo_firewall.www: Destroying... [id=85873fad-c942-488b-8372-7899956cce2f]
2021-08-26T13:02:45.518+0800 [INFO]  Starting apply for civo_firewall.www
2021-08-26T13:02:45.520+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 13:02:45 [INFO] deleting the firewall 85873fad-c942-488b-8372-7899956cce2f: timestamp=2021-08-26T13:02:45.520+0800
civo_firewall.www: Destruction complete after 3s
civo_network.cluster_net: Destroying... [id=52c49e78-febf-4015-b889-f56385e62336]
2021-08-26T13:02:48.761+0800 [INFO]  Starting apply for civo_network.cluster_net
2021-08-26T13:02:48.762+0800 [INFO]  provider.terraform-provider-civo_v0.10.9: 2021/08/26 13:02:48 [INFO] deleting the network 52c49e78-febf-4015-b889-f56385e62336: timestamp=2021-08-26T13:02:48.762+0800
civo_network.cluster_net: Destruction complete after 2s

Destroy complete! Resources: 3 destroyed.

`civo_template` resource should be removed and `civo_template` data source should be deprecated

In line with legacy/OpenStack EOL where Civo customers can no longer perform CRUD on Templates (this was replaced by the new Disk Images), we should:

  • Remove civo_template resource and its documentation
  • Deprecate civo_template data source and update the documentation
  • Add new civo_disk_image data source, together with documentation
  • Show warning when user uses template attribute in civo_instance resource
  • Add new disk_image attribute in civo_instance resource
  • When user uses both template and disk_image attributes in civo_instance resource, raise an error
  • Update civo_instance resource documentation

Check if firewall exists before deleting

When we have the following configuration...

resource "civo_network" "my_custom_network" {
  label  = "my-custom-network"
}

resource "civo_firewall" "my_custom_firewall" {
  name       = "my-custom-firewall"
  network_id = civo_network.my_custom_network.id
}

resource "civo_firewall_rule" "http" {
  firewall_id = civo_firewall.my_custom_firewall.id
  protocol    = "tcp"
  start_port  = "80"
  end_port    = "80"
  direction   = "ingress"
  label       = "web-server"
  depends_on  = [civo_firewall.my_custom_firewall]
}

resource "civo_kubernetes_cluster" "my_cluster" {
  name              = "my_cluster"
  num_target_nodes  = 1
  target_nodes_size = "g3.k3s.medium"
  network_id        = civo_network.my_custom_network.id
  firewall_id       = civo_firewall.my_custom_firewall.id
}

...and we want to run terraform destroy command to delete all the resources above, Civo API will auto-delete the firewall when civo_kubernetes_cluster gets deleted. Meaning, when the plugin tries to delete the firewall, the firewall is already deleted — which will throw an error like below:

tf destroy --auto-approve
civo_network.my_custom_network: Refreshing state... [id=beebbc30-0658-445f-a740-7450b17d84de]
civo_firewall.my_custom_firewall: Refreshing state... [id=226bbccb-5a54-4a28-9af8-28be9cec63fa]
civo_firewall_rule.http: Refreshing state... [id=ad383bee-b10b-4126-9d06-7afdc14a6beb]
civo_kubernetes_cluster.my_cluster: Refreshing state... [id=19db89ad-857d-4c32-a3e7-5242e47977f5]

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          = "ad383bee-b10b-4126-9d06-7afdc14a6beb"
        # (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         = "226bbccb-5a54-4a28-9af8-28be9cec63fa" -> null
      - name       = "my-custom-firewall" -> null
      - network_id = "beebbc30-0658-445f-a740-7450b17d84de" -> null
    }

  # civo_firewall_rule.http will be destroyed
  - resource "civo_firewall_rule" "http" {
      - cidr        = [
          - "",
        ] -> null
      - end_port    = "80" -> null
      - firewall_id = "226bbccb-5a54-4a28-9af8-28be9cec63fa" -> null
      - id          = "ad383bee-b10b-4126-9d06-7afdc14a6beb" -> 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.51:6443" -> null
      - created_at             = "2021-08-27 06:20:50 +0000 UTC" -> null
      - dns_entry              = "19db89ad-857d-4c32-a3e7-5242e47977f5.k8s.civo.com" -> null
      - firewall_id            = "226bbccb-5a54-4a28-9af8-28be9cec63fa" -> null
      - id                     = "19db89ad-857d-4c32-a3e7-5242e47977f5" -> null
      - installed_applications = [] -> null
      - instances              = [
          - {
              - cpu_cores = 2
              - disk_gb   = 15
              - hostname  = "k3s-my-cluster-f661f3fc-node-pool-c760"
              - ram_mb    = 4096
              - size      = ""
              - status    = "ACTIVE"
              - tags      = []
            },
        ] -> null
      - kubeconfig             = (sensitive value)
      - kubernetes_version     = "1.20.0-k3s1" -> null
      - master_ip              = "212.2.243.51" -> null
      - name                   = "my_cluster" -> null
      - network_id             = "beebbc30-0658-445f-a740-7450b17d84de" -> null
      - num_target_nodes       = 1 -> null
      - pools                  = [
          - {
              - count          = 1
              - id             = "1acabb3c-fa67-4d6c-92f1-b159552d19fd"
              - instance_names = [
                  - "k3s-my-cluster-f661f3fc-node-pool-c760",
                ]
              - instances      = [
                  - {
                      - cpu_cores = 2
                      - disk_gb   = 15
                      - hostname  = "k3s-my-cluster-f661f3fc-node-pool-c760"
                      - 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      = "beebbc30-0658-445f-a740-7450b17d84de" -> null
      - label   = "my-custom-network" -> null
      - name    = "cust-433e075e-a401-my-custom-network" -> null
    }

Plan: 0 to add, 0 to change, 4 to destroy.
civo_firewall_rule.http: Destroying... [id=ad383bee-b10b-4126-9d06-7afdc14a6beb]
civo_kubernetes_cluster.my_cluster: Destroying... [id=19db89ad-857d-4c32-a3e7-5242e47977f5]
civo_firewall_rule.http: Destruction complete after 2s
civo_kubernetes_cluster.my_cluster: Destruction complete after 4s
civo_firewall.my_custom_firewall: Destroying... [id=226bbccb-5a54-4a28-9af8-28be9cec63fa]
╷
│ Error: [ERR] an error occurred while tring to delete the firewall 226bbccb-5a54-4a28-9af8-28be9cec63fa, DatabaseFirewallNotFoundError: Failed to find that firewall in the internal database
│
│
╵

What we should do here is, we should first check if the firewall exists or not. If exists, delete it. If not exist, ignore it.

Failing to find k8s cluster after deletion

After deleting a cluster outside of terraform, with the cluster still existing within the tfstate, the provider attempts to connect to the cluster, which no longer exists.

civo_kubernetes_cluster.cluster: Refreshing state... [id=<cluster guid>]

Error: [ERR] failed to find the kubernets cluster: unable to find <cluster guid>, zero matches

Terraform should recreate the cluster.
Current workaround is to rm the cluster from state before applying terraform

instances terraform creation - inconstitent state

After succesfull "terraform apply" command coressponding instances are created. But after running "terraform apply" again - it will still wants to update something.

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # civo_instance.funnel1 will be updated in-place
  ~ resource "civo_instance" "funnel1" {
        id                 = "ca39e1b2-9c95-4215-bb17-994b171cb904"
        tags               = []
      + template           = "a4204155-a876-43fa-b4d6-ea2af8774560"
        # (17 unchanged attributes hidden)
    }

  # civo_instance.funnel2 will be updated in-place
  ~ resource "civo_instance" "funnel2" {
        id                 = "3eaea460-4781-4e07-a05e-d731a74246a1"
        tags               = []
      + template           = "a4204155-a876-43fa-b4d6-ea2af8774560"
        # (17 unchanged attributes hidden)
    }

Plan: 0 to add, 2 to change, 0 to destroy.

Cluster tags shouldn't be saved in comma separated format

Assumming we have created a cluster using this config file:

# Query xsmall instance size
data "civo_instances_size" "xsmall" {
    filter {
        key = "type"
        values = ["kubernetes"]
    }

    sort {
        key = "ram"
        direction = "asc"
    }
}

# Create a cluster
resource "civo_kubernetes_cluster" "my-cluster" {
    name = "my-cluster"
    applications = "Portainer,Linkerd:Linkerd & Jaeger"
    num_target_nodes = 2
    target_nodes_size = element(data.civo_instances_size.xsmall.sizes, 0).name
    tags = "first second"
}

When we rerun terraform apply command, it shows:

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # civo_kubernetes_cluster.my-cluster will be updated in-place
  ~ resource "civo_kubernetes_cluster" "my-cluster" {
        id                     = "c0557d11-c1a8-4e27-b52d-cb09be293255"
        name                   = "my-cluster"
      ~ tags                   = "first, second" -> "first second"
        # (16 unchanged attributes hidden)
    }

Terraform think we changed the tags because we joined them using comma — but it supposed to be space separated, not comma separated.

To fix, we need to remove the strings.Join() and save the tags in space separated format. Just like how we defined in in Terraform docs and API docs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.