Antsle Forum

Welcome to our Antsle community! This forum is to connect all Antsle users to post experiences, make user-generated content available for the entire community and more. 

Please note: This forum is about discussing one specific issue at a time. No generalizations. No judgments. Please check the Forum Rules before posting. If you have specific questions about your Antsle and expect a response from our team directly, please continue to use the appropriate channels (email: [email protected]) so every inquiry is tracked. 

Please or Register to create posts and topics.

Terraform Provider Plugin

PreviousPage 3 of 5Next

I'm having the same issue as @coby-stinson and tried a few different ways to get things working.  Here is my setup.  Any help?  What version combinations work for you @mpbaum?

Versions I've tried:

Terraform OpenApi 27 | 22 | 16

EdgeLinux 2.0.0

antMan 3.0.0f

Terraform v0.12.0 | v0.12.24

Error Message:

$ terraform init

Initializing the backend...

Initializing provider plugins...

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.

$ terraform plan

Error: Failed to instantiate provider "antsle" to obtain schema: Unrecognized remote plugin message:

This usually means that the plugin is either invalid or simply
needs to be recompiled to support the latest protocol.

 

 

I had sometime this weekend (in the house because of lock down) and did a little work on this. After some trials and errors, I finally was able to get this to work with one of my Antsle setups. I built an AntMan/EdgeLinux using the community download and that’s what I used for this test.

In order to get Terraform to work, I had to configure my linux workstation with the following binary versions and setup. I hope this helps everyone trying to work on this and if there is interest, I’ll fork the repo, make updates, and put in a PR.

I'm excited to get this to work and I hope the team continues to make improvements and features available!

Versions of the Terraform and the OpenApi Provider I used:

Terraform v0.12.8

terraform-provider-openapi_0.23.0

These versions worked on the following EdgeLinux/AntMan Versions:

EdgeLinux 2.0.0

AntMan 3.0.0f

I made the following configurations to varies files:

~/.terraform.d/plugins/terraform-provider-openapi.yaml

version: 1

services:

antsle:

swagger-url: https://XXX.antsle.us/swagger.json

provider.tf

variable "apikey_auth" {

default = "Token eyJhbGciOiJI…………."

}

provider "antsle" {

api_key = var.apikey_auth

}

A few things to note to get this to work

1. I had to setup SSL in order for this to work (Documentation Link Here).  I could not use http://<privateip&gt;:3000/  I believe this link explains why.  Look at the Notes section of this link.

2. The documentation provided in the repo for the sample project shows an apikey_auth argument. This was not the case in my setup. I had to change the provider.tf to use api_key.

3. The insecure_skip_verify: true did not seem to have any affect when I used it. I believe there is a OpenAPI Provider issue there but I didn’t dig too deep into it.

4. DON’T FORGET the “TOKEN” in the apikey. I always do this and spend hours troubleshooting before I realize I forgot it.

Here are the commands I ran in the folder where my *tf files were located and the output:

$ rm -rf .terraform/ && terraform init && terraform plan && terraform apply

Initializing the backend...

Initializing provider plugins...

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.

Refreshing Terraform state in-memory prior to plan...

The refreshed state will be used to calculate this plan, but will not be

persisted to local or remote state storage.

------------------------------------------------------------------------

An execution plan has been generated and is shown below.

Resource actions are indicated with the following symbols:

+ create

Terraform will perform the following actions:

# antsle_antlets.antlet1 will be created

+ resource "antsle_antlets" "antlet1" {

+ antlet_num = 33

+ autostart = (known after apply)

+ compression = "on"

+ cpu = 1

+ dname = "antlet1"

+ dtype = (known after apply)

+ id = (known after apply)

+ ip = (known after apply)

+ ram = 1024

+ ram_display = (known after apply)

+ state = (known after apply)

+ storage_display = (known after apply)

+ template = "Ubuntu16.04"

+ uuid = (known after apply)

+ zfs_quota = (known after apply)

+ zpool = (known after apply)

+ zpool_name = "antlets"

}

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

------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so Terraform

can't guarantee that exactly these actions will be performed if

"terraform apply" is subsequently run.

An execution plan has been generated and is shown below.

Resource actions are indicated with the following symbols:

+ create

Terraform will perform the following actions:

# antsle_antlets.antlet1 will be created

+ resource "antsle_antlets" "antlet1" {

+ antlet_num = 33

+ autostart = (known after apply)

+ compression = "on"

+ cpu = 1

+ dname = "antlet1"

+ dtype = (known after apply)

+ id = (known after apply)

+ ip = (known after apply)

+ ram = 1024

+ ram_display = (known after apply)

+ state = (known after apply)

+ storage_display = (known after apply)

+ template = "Ubuntu16.04"

+ uuid = (known after apply)

+ zfs_quota = (known after apply)

+ zpool = (known after apply)

+ zpool_name = "antlets"

}

Plan: 1 to add, 0 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

antsle_antlets.antlet1: Creating...

antsle_antlets.antlet1: Creation complete after 3s [id=antlet1]

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

bradthebuilder and Matthew Massa have reacted to this post.
bradthebuilderMatthew Massa

Shout out to to @tliddle30, I came back to this post-edgelinux 2.0 upgrade to find your solution, and can confirm it works. Moreover, I also tested Terraform 0.12.24 + OpenAPI plugin v0.29.0 and got it to work as well!

➜ test-29 tree -a
.
├── main.tf
├── provider.tf
├── .terraform
│      └── plugins
│               └── linux_amd64
│                       ├── lock.json
│                       └── terraform-provider-antsle_v0.29.0
├── terraform.tfstate
└── terraform.tfstate.backup

3 directories, 6 files
➜ test-29 cat main.tf
resource "antsle_antlets" "test-antlet" {
dname = "antlet1"
template = "debian"
ram = 1024
cpu = 1
antlet_num = 33
zpool_name = "antlets"
compression = "lz4"
}
➜ test-29 cat provider.tf
variable "apikey_auth" {
default = "Token ey..."
}

provider "antsle" {
api_key = var.apikey_auth
}
➜ test-29 terraform --version
Terraform v0.12.24
+ provider.antsle v0.29.0

Your version of Terraform is out of date! The latest version
is 0.12.25. You can update by downloading from https://www.terraform.io/downloads.html
➜ test-29 terraform init

Initializing the backend...

Initializing provider plugins...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.antsle: version = "~> 0.29"

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.
➜ test-29 terraform apply

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create

Terraform will perform the following actions:

# antsle_antlets.test-antlet will be created
+ resource "antsle_antlets" "test-antlet" {
+ antlet_num = 33
+ autostart = (known after apply)
+ compression = "lz4"
+ cpu = 1
+ dname = "antlet1"
+ dtype = (known after apply)
+ id = (known after apply)
+ ip = (known after apply)
+ ram = 1024
+ ram_display = (known after apply)
+ state = (known after apply)
+ storage_display = (known after apply)
+ template = "debian"
+ uuid = (known after apply)
+ zfs_quota = (known after apply)
+ zpool = (known after apply)
+ zpool_name = "antlets"
}

Plan: 1 to add, 0 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

antsle_antlets.test-antlet: Creating...
antsle_antlets.test-antlet: Creation complete after 5s [id=antlet1]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
➜ test-29 terraform destroy
antsle_antlets.test-antlet: Refreshing state... [id=antlet1]

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
- destroy

Terraform will perform the following actions:

# antsle_antlets.test-antlet will be destroyed
- resource "antsle_antlets" "test-antlet" {
- antlet_num = 33 -> null
- autostart = false -> null
- compression = "lz4" -> null
- cpu = 1 -> null
- dname = "antlet1" -> null
- dtype = "LXC" -> null
- id = "antlet1" -> null
- ip = "10.1.1.33" -> null
- ram = 1024 -> null
- ram_display = "1 GiB" -> null
- state = "Stopped" -> null
- storage_display = "∞" -> null
- template = "debian" -> null
- uuid = "7081608d-2748-4ce5-852c-5f4d33685ce4" -> null
- zfs_quota = 0 -> null
- zpool = {
- "antsle:managed_origin" = "-"
- "capacity" = "2%"
- "compression" = "off"
- "health" = "ONLINE"
- "mounted" = "true"
- "mountpoint" = "/antlets"
- "name" = "antlets"
- "size" = "1.80T"
} -> null
- zpool_name = "antlets" -> null
}

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

Do you really want to destroy all resources?
Terraform will destroy all your managed infrastructure, as shown above.
There is no undo. Only 'yes' will be accepted to confirm.

Enter a value: yes

antsle_antlets.test-antlet: Destroying... [id=antlet1]
antsle_antlets.test-antlet: Destruction complete after 1s

Destroy complete! Resources: 1 destroyed.
➜ test-29

@coby-stinson and @tliddle30

Thank you both!

Thank you @tliddle30!  Saved me hours of work!

 

Able to create and destroy instances, but does anyone know how to create the antlet and start it once it's created using Terraform?  Seems like it starts in a Stopped state and the "state" variable appears to be "computed" only on creation.

Also - anyone have luck creating Load Balancing Rules?  Using the swagger definitions as a guide for what values to use, I created a resource definition as follows for a new lb-rule:

resource "antsle_antlets_lb-rules" "maria-lb40" {
id = 40
server-name = "maria40"
upstreams {
weight = 1
address = "10.1.1.40"
}
}

But terraform plan errors out with an "Invalid resource type":

The provider provider.antsle does not support resource type
"antsle_antlets_lb-rules".

What am I missing?

Has anyone gotten it working in windows 10 ? I'm not sure why but seem to be having issues even with using Terraform Terraform 0.12.24 + OpenAPI plugin v0.29.0 

I believe I'm missing a step with the whole configuring the openapi / antsle file.

 

This bugs me that SSL has to be setup.  Has anyone tried using the onboard Nginx as a reverse proxy ?   It almost gets there and slams into another HTTPS issue again but I can't figure out why.

In /etc/nginx/nginx.conf I added this to the server{} config:

location ~ ^/(swagger-ui|swagger.json|api)? {
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:3000;
}

The terraform-provider-openapi.yaml file looks like this:

version: 1
services:
antsle:
swagger-url: http://antsleone.lan/swagger.json
insecure_skip_verify: true

My terraform file has the provider section setup using the api_key as suggested above.

Running "terraform apply" in DEBUG output enabled gets this:

<snip>

2020-08-09T14:32:10.787Z [DEBUG] plugin.terraform-provider-antsle_v0.31.1: 2020/08/09 14:32:10 [WARN] host field not specified in the swagger configuration, falling back to retrieving the host from where the OpenAPI document is served: 'http://antsleone.lan/swagger.json'
2020-08-09T14:32:10.787Z [DEBUG] plugin.terraform-provider-antsle_v0.31.1: 2020/08/09 14:32:10 [DEBUG] getResourcePath hit the cache for 'antlets'
2020-08-09T14:32:10.788Z [DEBUG] plugin.terraform-provider-antsle_v0.31.1: 2020/08/09 14:32:10 operation security schemes missing, falling back to global security schemes (if there's any)
2020-08-09T14:32:10.788Z [DEBUG] plugin.terraform-provider-antsle_v0.31.1: 2020/08/09 14:32:10 the global configuration contains security schemes, selected the following based on order of appearance in the list &[{Name:api_key}]
2020-08-09T14:32:10.788Z [DEBUG] plugin.terraform-provider-antsle_v0.31.1: 2020/08/09 14:32:10 [DEBUG] Performing POST https://antsleone.lan/api/antlets
2020-08-09T14:32:10.788Z [DEBUG] plugin.terraform-provider-antsle_v0.31.1: 2020/08/09 14:32:10 [DEBUG] Request Header 'Authorization' sent
2020-08-09T14:32:10.788Z [DEBUG] plugin.terraform-provider-antsle_v0.31.1: 2020/08/09 14:32:10 [DEBUG] Request Header 'User-Agent' sent
2020/08/09 14:32:10 [DEBUG] antsle_antlets.antlet1: apply errored, but we're indicating that via the Error pointer rather than returning it: request POST https://antsleone.lan/api/antlets HTTP/1.1 failed. Response Error: 'Post https://antsleone.lan/api/antlets: dial tcp 192.168.7.142:443: connect: connection refused'
2020/08/09 14:32:10 [ERROR] <root>: eval: *terraform.EvalApplyPost, err: request POST https://antsleone.lan/api/antlets HTTP/1.1 failed. Response Error: 'Post https://antsleone.lan/api/antlets: dial tcp 192.168.7.142:443: connect: connection refused'
2020/08/09 14:32:10 [ERROR] <root>: eval: *terraform.EvalSequence, err: request POST https://antsleone.lan/api/antlets HTTP/1.1 failed. Response Error: 'Post https://antsleone.lan/api/antlets: dial tcp 192.168.7.142:443: connect: connection refused'

Error: request POST https://antsleone.lan/api/antlets HTTP/1.1 failed. Response Error: 'Post https://antsleone.lan/api/antlets: dial tcp 192.168.7.142:443: connect: connection refused'

The above shows that the nginx reverse proxy config gets me past the call for /swagger.json call fine.  However, something is causing it to attempt to call /api/antlets using HTTPS instead of HTTP.

Does anyone have any thoughts why ?

Is the swagger.json causing this somewhat ?

In the Terraform TRACE output I see this log entry:

2020-08-09T15:17:15.688Z [DEBUG] plugin.terraform-provider-antsle_v0.31.1: 2020/08/09 15:17:15 operation security schemes missing, falling back to global security schemes (if there's any)

2020-08-09T15:17:15.688Z [DEBUG] plugin.terraform-provider-antsle_v0.31.1: 2020/08/09 15:17:15 the global configuration contains security schemes, selected the following based on order of appearance in the list &[{Name:api_key}]

At the top of the swagger.json is this:

{
"schemes": [
"https",
"http"
], ... <snip>

I see that https is first.  Questions:

  • Is the swagger.json related to what I'm seeing ?
  • If so, is there anyway to change the order of the schemes ?
  • If so, is there anyway to possibly remove "https" from the swagger.json output ?

Digging around looks like swagger.json is coming out of antman.jar and I think it is dynamically generated (speaking outside of my experience wheel house here) so I'm thinking I'm out of luck.

Just to try it, I create a self-signed cert in Nginx for port 443 adding in the reverse proxy setup.  Now it gets past the SSL issues and calls /api/antlets aaanndddd then antmand gets a java.lang.nullpointexception:

2020-08-09 12:40:52,431 [worker-3] ERROR antman.services.antlets-srv - #error {
:cause nil
:via
[{:type java.lang.NullPointerException
:message nil
:at [clojure.lang.Numbers ops Numbers.java 1013]}]
:trace
[[clojure.lang.Numbers ops Numbers.java 1013]
[clojure.lang.Numbers lt Numbers.java 221]
[clojure.lang.Numbers lt Numbers.java 3816]
[antman.services.antlets_srv$validate_create_antlet_params invokeStatic antlets_srv.clj 128]
[antman.services.antlets_srv$validate_create_antlet_params invoke antlets_srv.clj 95]
[antman.services.antlets_srv$create_antlet invokeStatic antlets_srv.clj 155]
[antman.services.antlets_srv$create_antlet invoke antlets_srv.clj 136]

I tried using v0.23 of the OpenAPI Terraform Provider but got the same error.  I'd really like to get terraform working against my Anstle 🙁

PreviousPage 3 of 5Next