Describe the bug
When using the hashicorp/terraform
official terraform container, checkly plugin fails to run.
While I don't expect you to make a special plugin binary to cover this use case, you may want to add a note to the documentation. It's a common issue with golang programs running in alpine linux and can be hard to troubleshoot because the error message (no such file or directory
) doesn't really point you in the right direction.
Version
What version of the Checkly Terraform provider are you using? e.g. v0.6.1
v0.6.6
To Reproduce
Steps to reproduce the behavior:
Use the checkly.tf
resource file included below. Also uses install_checkly_plugin.sh
included below which is a workaround to issue #35
$ docker run -v $(pwd):/run -it --rm --entrypoint=/bin/sh hashicorp/terraform
/ # apk add bash jq curl
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
(1/5) Installing readline (8.0.4-r0)
(2/5) Installing bash (5.0.17-r0)
Executing bash-5.0.17-r0.post-install
(3/5) Installing curl (7.69.1-r1)
(4/5) Installing oniguruma (6.9.5-r1)
(5/5) Installing jq (1.6-r1)
Executing busybox-1.31.1-r16.trigger
OK: 31 MiB in 34 packages
/ # cd /run
/run # terraform init
Initializing the backend...
Initializing provider plugins...
- Finding local/checkly/checkly versions matching "0.6.6"...
Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider
local/checkly/checkly: could not connect to local: Failed to request discovery
document: Get "https://local/.well-known/terraform.json": dial tcp: lookup
local on 192.168.65.1:53: read udp 172.17.0.2:44185->192.168.65.1:53: i/o
timeout
/run # ./install_checkly_plugin.sh
++ uname -s
+ [[ Linux == Darwin ]]
++ uname -s
+ [[ Linux == Linux ]]
+ platform=linux_amd64
+ jq_url_cmd='.assets[] | select(.name | endswith("linux_amd64.gz")).browser_download_url'
+ jq_ver_cmd='.name | sub("v(?<ver>.*)"; "\(.ver)")'
++ curl -s https://api.github.com/repos/checkly/terraform-provider-checkly/releases/latest
++ jq -r '.assets[] | select(.name | endswith("linux_amd64.gz")).browser_download_url'
+ url=https://github.com/checkly/terraform-provider-checkly/releases/download/v0.6.6/terraform-provider-checkly_v0.6.6_linux_amd64.gz
++ curl -s https://api.github.com/repos/checkly/terraform-provider-checkly/releases/latest
++ jq -r '.name | sub("v(?<ver>.*)"; "\(.ver)")'
+ ver=0.6.6
+ curl -OL https://github.com/checkly/terraform-provider-checkly/releases/download/v0.6.6/terraform-provider-checkly_v0.6.6_linux_amd64.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 674 100 674 0 0 1345 0 --:--:-- --:--:-- --:--:-- 1345
100 13.0M 100 13.0M 0 0 3692k 0 0:00:03 0:00:03 --:--:-- 5363k
++ basename https://github.com/checkly/terraform-provider-checkly/releases/download/v0.6.6/terraform-provider-checkly_v0.6.6_linux_amd64.gz
+ filename=terraform-provider-checkly_v0.6.6_linux_amd64.gz
+ gunzip terraform-provider-checkly_v0.6.6_linux_amd64.gz
+ filename=terraform-provider-checkly_v0.6.6_linux_amd64
+ chmod +x terraform-provider-checkly_v0.6.6_linux_amd64
+ PLUGIN_DIR=/root/.terraform.d/plugins/local/checkly/checkly/0.6.6/linux_amd64
+ mkdir -p /root/.terraform.d/plugins/local/checkly/checkly/0.6.6/linux_amd64
+ mv terraform-provider-checkly_v0.6.6_linux_amd64 /root/.terraform.d/plugins/local/checkly/checkly/0.6.6/linux_amd64/terraform-provider-checkly_v0.6.6
/run # terraform init
Initializing the backend...
Initializing provider plugins...
- Finding local/checkly/checkly versions matching "0.6.6"...
- Installing local/checkly/checkly v0.6.6...
- Installed local/checkly/checkly v0.6.6 (unauthenticated)
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.
/run # terraform apply
var.checkly_api_key
Enter a value: XXXXXXX
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 "local/checkly/checkly" to obtain schema:
fork/exec
.terraform/plugins/local/checkly/checkly/0.6.6/linux_amd64/terraform-provider-checkly_v0.6.6:
no such file or directory
Root cause
The root cause is that the checkly plugin was built with glibc, and the hashicorp/terraform
container is based on alpine, which uses musl
I think which isn't compatible with glibc dynamically linked binaries.
[pid 110] 20:39:56.588163 execve(".terraform/plugins/local/checkly/checkly/0.6.6/linux_amd64/terraform-provider-checkly_v0.6.6", [".terraform/plugins/local/checkly/checkly/0.6.6/linux_amd64/terraform-provider-checkly_v0.6.6"], ["HOSTNAME=a5663fe4b03c", "SHLVL=1", "HOME=/root", "OLDPWD=/", "TERM=xterm", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "PWD=/run", "TF_PLUGIN_MAGIC_COOKIE=XXXX", "PLUGIN_MIN_PORT=10000", "PLUGIN_MAX_PORT=25000", "PLUGIN_PROTOCOL_VERSIONS=5", "PLUGIN_CLIENT_CERT=-----BEGIN CERTIFICATE-----\nMIICMDCC[...]lmnoy\n-----END CERTIFICATE-----\n"]) = -1 ENOENT (No such file or directory)
/run # ls -l .terraform/plugins/local/checkly/checkly/0.6.6/
total 0
lrwxrwxrwx 1 root root 66 Sep 29 20:08 linux_amd64 -> /root/.terraform.d/plugins/local/checkly/checkly/0.6.6/linux_amd64
/run # file /root/.terraform.d/plugins/local/checkly/checkly/0.6.6/linux_amd64/terraform-provider-checkly_v0.6.6
/root/.terraform.d/plugins/local/checkly/checkly/0.6.6/linux_amd64/terraform-provider-checkly_v0.6.6:
ELF 64-bit LSB executable,
x86-64, version 1 (SYSV),
dynamically linked,
interpreter /lib64/ld-linux-x86-64.so.2,
Go BuildID=6PyyWzGCc1vlcg1_uJbd/ioHX04eG2EIZEiyYC7Ve/HR5DHbDVZW5T_FDk1Y-m/QnUCYvlhZbIl5yrQMHD5,
not stripped
/run # ldd /root/.terraform.d/plugins/local/checkly/checkly/0.6.6/linux_amd64/terraform-provider-checkly_v0.6.6
/lib64/ld-linux-x86-64.so.2 (0x7f64fffbf000)
libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7f64fffbf000)
libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f64fffbf000)
/run # ls -l /lib64/ld-linux-x86-64.so.2
ls: /lib64/ld-linux-x86-64.so.2: No such file or directory
/run # ls -l /lib64
ls: /lib64: No such file or directory
So the interpreter (/lib64/ld-linux-x86-64.so.2
) specified in the header of the checkly plugin /root/.terraform.d/plugins/local/checkly/checkly/0.6.6/linux_amd64
doesn't exist.
Workaround
Two options come to mind, although there are probably several others.
-
Build your own terraform container based on golang:buster
. You could base it on the Dockerfile at https://github.com/hashicorp/terraform/blob/master/Dockerfile
-
Add the package libc6-compat
to the hashicorp/terraform
container before attempting to run terraform apply
:
/run # apk add libc6-compat
(1/2) Upgrading musl (1.1.24-r8 -> 1.1.24-r9)
(2/2) Installing libc6-compat (1.1.24-r9)
OK: 38 MiB in 38 packages
/run # /root/.terraform.d/plugins/local/checkly/checkly/0.6.6/linux_amd64/terraform-provider-checkly_v0.6.6
This binary is a plugin. These are not meant to be executed directly.
Please execute the program that consumes these plugins, which will
load any plugins automatically
^ Now the checkly plugin binary will execute instead of saying no such file or directory
.
terraform apply
also works now:
/run # terraform apply
var.checkly_api_key
Enter a value: XXXX
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:
# checkly_check.example-check will be created
+ resource "checkly_check" "example-check" {
+ activated = true
+ degraded_response_time = 15000
[...]
}
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:
Expected behavior
A clear and concise description of what you expected to happen.
Terraform applies successfully and I see the checkly checks in the web dashboard at https://app.checklyhq.com
TF Resource files
If applicable, add TF resource file examples to help explain your problem.
terraform {
required_version = ">= 0.13"
required_providers {
checkly = {
source = "local/checkly/checkly"
version = "0.6.6"
}
}
}
variable "checkly_api_key" {}
provider "checkly" {
api_key = "var.checkly_api_key"
}
resource "checkly_check" "example-check" {
name = "Example check"
type = "API"
activated = true
should_fail = false
frequency = 1
double_check = true
ssl_check = true
use_global_alert_settings = true
locations = [
"us-west-1"
]
request {
url = "https://api.example.com/"
follow_redirects = true
assertion {
source = "STATUS_CODE"
comparison = "EQUALS"
target = "200"
}
}
}
Install script (workaround to #35)
#!/usr/bin/env bash
set -x
# Determine architecture
if [[ $(uname -s) == Darwin ]]
then
platform='darwin_amd64'
elif [[ $(uname -s) == Linux ]]
then
platform='linux_amd64'
else
echo "No supported architecture found"
exit 1
fi
jq_url_cmd=".assets[] | select(.name | endswith(\"${platform}.gz\")).browser_download_url"
jq_ver_cmd=".name | sub(\"v(?<ver>.*)\"; \"\(.ver)\")"
# Find latest binary release URL for this platform
url="$(curl -s https://api.github.com/repos/checkly/terraform-provider-checkly/releases/latest | jq -r "${jq_url_cmd}")"
# Get the version of the latest binary release (e.g. 0.6.6)
ver="$(curl -s https://api.github.com/repos/checkly/terraform-provider-checkly/releases/latest | jq -r "${jq_ver_cmd}")"
# Download the tarball
curl -OL ${url}
# Rename and copy to your Terraform plugin folder
filename=$(basename $url)
gunzip ${filename}
filename=${filename%.gz}
chmod +x ${filename}
# /Users/rchapman/.terraform.d/plugins/local/checkly/checkly/0.6.6/darwin_amd64/terraform-provider-checkly_v0.6.6
PLUGIN_DIR=~/.terraform.d/plugins/local/checkly/checkly/$ver/$platform
mkdir -p $PLUGIN_DIR
mv $filename ${PLUGIN_DIR}/${filename%_${platform}}
Additional context
#35 Checkly provider plugin does not work with terraform 0.13