Skip to content
This repository has been archived by the owner on Jul 26, 2021. It is now read-only.

Error retrieving ID of template: json: cannot unmarshal object into Go struct field alias.childtemplates of type []interface {} #72

Closed
ghost opened this issue Dec 21, 2019 · 8 comments

Comments

@ghost
Copy link

ghost commented Dec 21, 2019

This issue was originally opened by @1605200517 as hashicorp/terraform#23726. It was migrated here as a result of the provider split. The original body of the issue is below.


Terraform Version

Terraform v0.12.18
+ provider.cloudstack v0.3.0

Terraform Configuration Files

variable "compute_template" {
  default = "debian9.4 stretch BUILD-1946"
}

variable "path_to_ssh_key" {
  default = "~/.ssh/id_rsa.pub"
}

variable "ssh_keypair_name" {
  default = "foo1_ssh_key"
}

variable "compute_offering" {
  default = "XS Instanz"
}

variable "zone" {
  default = "Enterprise_Internet_Bi"
}

variable "acl_items" {
  default = ["0.0.0.0/0"]
}

variable "vpc_offering" {
  default = "Default VPC Offering (512MB)"
}

variable "network_offering" {
  default = "NAT for VPC"
}

variable "cidr" {
  default = "10.0.1.0/24"
}

provider "cloudstack" {
  api_url    = var.api_url
  api_key    = var.api_key
  secret_key = var.secret_key
}

resource "cloudstack_ssh_keypair" "default" {
  name       = "foo1-ssh-key"
  public_key = file(var.path_to_ssh_key)
}

resource "cloudstack_vpc" "foo1-cluster" {
  name         = "foo1-terraform-vpc"
  cidr         = var.cidr
  vpc_offering = var.vpc_offering
  zone         = var.zone
}

resource "cloudstack_network_acl" "foo1-acl" {
  name   = "foo1 terraform acl"
  vpc_id = cloudstack_vpc.foo1-cluster.id
}

resource "cloudstack_network_acl_rule" "default" {
  acl_id = cloudstack_network_acl.foo1-acl.id

  rule {
    action       = "allow"
    cidr_list    = var.acl_items
    protocol     = "tcp"
    ports        = ["22"]
    traffic_type = "ingress"
  }
}

resource "cloudstack_network" "foo1-network" {
  name             = "foo1-terraform-network"
  network_offering = var.network_offering
  zone             = var.zone
  cidr             = var.cidr
  vpc_id           = cloudstack_vpc.foo1-cluster.id
  acl_id           = cloudstack_network_acl.foo1-acl.id
}

resource "cloudstack_instance" "foo1-vm" {
  name             = "foo1-virtual-machine"
  service_offering = var.compute_offering
  network_id       = cloudstack_network.foo1-network.id
  template         = var.compute_template
  zone             = var.zone
  expunge          = "true"
  keypair          = "foo1-ssh-key"
}

resource "cloudstack_ipaddress" "foo1ipaddress" {
  vpc_id = cloudstack_vpc.foo1-cluster.id
  zone   = var.zone
}

resource "cloudstack_port_forward" "default" {
  ip_address_id = cloudstack_ipaddress.foo1ipaddress.id
  forward {
    protocol           = "tcp"
    private_port       = 22
    public_port        = 22
    virtual_machine_id = cloudstack_instance.foo1-vm.id
  }
}

output "public_ip_foo1vm" {
  value = cloudstack_ipaddress.foo1ipaddress.ip_address
}

Debug Output

No debug output recognizable despite TF_LOG=trace.

Expected Behavior

Correct execution.

Actual Behavior

Error:

..
cloudstack_instance.foo2-vm: Creating...
cloudstack_network_acl_rule.default: Creation complete after 2s [id=2584bed0-bcd9-499e-b29a-e4729b366f9f]
Error: Error retrieving ID of template debian9.4 stretch BUILD-1946: json: cannot unmarshal object into Go struct field alias.childtemplates of type []interface {}

Steps to Reproduce

  1. terraform init
  2. terraform apply
@greut
Copy link
Contributor

greut commented Dec 21, 2019

@1605200517 It is likely that the CloudStack you're using is older than the library this provider was generated from. childtemplates exist in the latest releases.

@synergiator
Copy link

synergiator commented Dec 22, 2019

@greut thank you for quick feedback; please share which library do you mean in your reference. CS API in use is 4.10. Is there no backward compatibility, or is 4.10 out of its scope?

@greut
Copy link
Contributor

greut commented Dec 22, 2019

4.10 doesn't have the childtemplates, http://cloudstack.apache.org/api/apidocs-4.10/apis/listTemplates.html

The library used by this provider does however, https://godoc.org/github.com/xanzy/go-cloudstack/cloudstack#Template as it's based on CloudStack 4.11

@synergiator
Copy link

from end user point of view, it would be nice to have some sync at terraform init with the provider API; something like

"WARNING: this version supports provider API version starting from.. and you have..."

@greut
Copy link
Contributor

greut commented Dec 23, 2019

@1605200517 Agreed. I see you're familiar with the problems go-cloudstack has https://github.com/xanzy/go-cloudstack/issues I'd fork it and put the omitempty flag on that value json:"childtemplates,omitempty"

@svanharmelen
Copy link
Member

We can also try to make it backwards compatible as I try to do for most changes like this. But indeed there are some sharp edges coming from both the way I build go-cloudstack (which was one of my first Go project many many years ago) and how the CloudStack API works...

@martialblog
Copy link

Hi, if someone needs a quick workaround for this. This patch will simply remove the childtemplate code and then the provider works with 4.10 (couldn't upload a .patch file, just rename it).

0001-Remove-ChildTemplate-to-ensure-works-with-CloudStack.txt

@svanharmelen
Copy link
Member

I'm going to close this issue as I'm about to archive this repository. Development of this provider has been moved to the Apache Foundation. Please find the new home for this provider here: https://github.com/apache/cloudstack-terraform-provider

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

No branches or pull requests

4 participants