nbering / terraform-provider-ansible

"Logical" provider for integrating with an Ansible Dynamic Inventory script.
https://nbering.github.io/terraform-provider-ansible/
Mozilla Public License 2.0
329 stars 64 forks source link

Terraform v0.12 compatibility #15

Closed devurandom closed 5 years ago

devurandom commented 5 years ago

Terraform v0.12 cannot load terraform-provider-ansible and prints following message:

Error: failed to load provider "ansible": Incompatible API version with plugin. Plugin version: 4, Client versions: [5]

See-Also: https://www.terraform.io/upgrade-guides/0-12.html

nbering commented 5 years ago

We just recently got the first beta release of 0.12. I was looking to test out one of the alpha versions and encountered a similar issue for virtually every plugin.

I'm certainly due to cut a new release soon for compatibility with core.

jtopjian commented 5 years ago

@nbering Let me know if you need any help with compiling against v0.12. I've just finished getting the OpenStack provider in good shape for it.

It's highly recommended to switch to Go 1.11.5+ and then use Go Modules for vendoring (which is very simple. The wiki page does an excellent job at documenting: https://github.com/golang/go/wiki/Modules). Once that's in place, you can do something like:

$ go get github.com/hashicorp/terraform@latest-commit-hash
$ go mod tidy
$ go mod vendor

That'll bring in v0.12 core into vendor. Once that's done, you can compile / test as normal, but the plugin will be based on v0.12.

edit: Also, you can do this in a separate branch for now if you'd like. Switching back and forth between v0.11 and v0.12 branches will allow you to compile/test for that version of Terraform.

nbering commented 5 years ago

It was also my plan to switch to Go modules for this. Vendoring has been a big hurdle for getting into Go development. I'll likely get this done within the week.

jtopjian commented 5 years ago

@nbering One quick note: when you test with v0.12, you will run into some syntax errors. This is because v0.12 is a little more strict with the HCL syntax. One potentially confusing area is with the concept of "blocks".

In a nutshell, documentation and fixtures referencing vars will need updated to look like:

resource "ansible_host" "example" {
    ...
    vars = {
        ansible_user = "admin"
    }
}

Note the =. This is because vars is of TypeMap and not an actual schema definition with sub-items.

Let me know if you run into any other issues.

nbering commented 5 years ago

Well... that's delightful.

I hadn't been paying attention to Terraform internals much for the 0.12 updates. Looks like the tfstate format changed, which breaks the Inventory Script portion of the integration.

Fortunately, it looks like the new format is actually easier to read since it stores lists as json arrays and dictionaries as json objects. It shouldn't be too much work to update the python code.

nbering commented 5 years ago

https://github.com/nbering/terraform-inventory/pull/8 adds Terraform 0.12 compatibility in the paired inventory script.