How can I add client in longview using terraform?
How would I add client in longview and monitor linode instance in terraform?
6 Replies
You can add Longview to monitor your Linode instance in Terraform by utilizing Terraform's documentation on how to use it with in conjunction with our services. It provides specific arguments that will allow you to create other services and also provides examples. Should you need additional assistance with using Terraform, I recommend reviewing the following documentation:
Lastly, in case you are unaware, Terraform also has a community forum where users are able to ask questions and receive insight from knowledgeable users. If you need any guidance with using Terraform, I recommend reaching out there:
I hope this message finds you well. Regarding the document you mentioned earlier, I regret to inform you that I did not find any information pertaining to the process of adding a client to Linode Longview or how to download the Longview agent in a Linode instance using a Terraform script.
I was able to locate the specific grant on how you can add a Longview client. I recommend reviewing their example usage to see how they were able to create a user with specific services.
provider "linode" {
token = "YOUR_LINODE_API_TOKEN"
}
resource "linode_instance" "example" {
label = "example-instance"
region = "us-east"
type = "g6-standard-2"
image = "linode/ubuntu20.04"
}
resource "linode_longview_client" "example" {
label = "example-client"
linode_id = linode_instance.example.id
}
resource "null_resource" "download_longview" {
depends_on = [linode_longview_client.example]
provisioner "remote-exec" {
inline = [
"curl -s https://lv.linode.com/longview/agent.sh | sudo bash"
]
}
}
I am using above Terraform script to add client and download longview agent but after running "Terraform init" command it shows that "linode_longview_client" is not the resource type.
Thanks for providing that output. After looking over the documentation again, the Linode Terraform Provider does not support Longview. What I shared before was instead the resource for configuring a user account on Linode. However, you can create a Longview client through our API. That said, I passed along your feedback to our internal tracker. This way the relevant teams can keep this in mind as we continue to improve our infrastructure and services.
I do not have a time for when this feature will be implemented, but the feedback provided is invaluable to us and we want to ensure your voice is heard.
I want to create 2 linode instance and Stackscript, In Stackscript I want to write the script to add longview client for
2 linode instances that I want to create and install longview agent in these 2 instances using Terraform.
so I have create a terraform script to do above task. but here I am not able to fetch linodeId in Stackscript
original API- curl -H "Authorization: Bearer $TOKEN" \
https://api.linode.com/v4/linode/instances/{linodeID} | json_pp
and to fetch linodeId that terrafom created I am using
curl -H "Authorization: Bearer $TOKEN" \
https://api.linode.com/v4/linode/instances/{linode_instance.foo.id} | json_pp
------------------------Terraform Script-----------------
terraform {
required_providers {
linode = {
source = "linode/linode"
version = "2.5.2"
}
}
}
provider "linode" {
token = "YOUR_LINODE_API_TOKEN"
}
// create stackscript to add client and install longview agent in linode instance
resource "linode_stackscript" "foobar" {
label = "foo"
description = "Installs longview agent"
script = <<--SCRIPT
!/bin/bash
<udf default="" label="add client into longiview and install longview agent" name="package"></udf>
apt-get -update
apt-get -q -y install jq
// API provides information about Linodes, including its region, type, Linode ID, and label
result=$(curl -H "Authorization: Bearer $token" \
https://api.linode.com/v4/linode/instances/{linode_instance.foo.id} | json_pp
)
echo "Result: $result"
label=$(echo "$result"|jq -r '.label') //store the label of linodes in "label" variable
// API add client in longview
response=$(curl -H "Content-Type: application/json" \
-H "Authorization: Bearer $token" \
-X POST -d '{
"label": "'"$label"'"
}' \
https://api.linode.com/v4/longview/clients
)
echo "Response: $response"
install_code=$(echo "$response"|jq -r '.install_code') //store the install_code of longview client in "install_code" variable
curl -s https://lv.linode.com/$install_code | sudo bash // install longview agent in linode instance
systemctl restart longview
SCRIPT
images = ["linode/ubuntu22.04", "linode/ubuntu20.04"]
rev_note = "initial version"
}
//create 2 linode instance
resource "linode_instance" "foo" {
count = 2
image = "linode/ubuntu22.04"
label = "instance-${count.index + 1}"
region = "in-maa"
type = "g6-nanode-1"
authorized_keys = ["…"]
root_pass = "…"
stackscript_id = linode_stackscript.foobar.id
stackscript_data = {
"package" = "nginx"
}
}
when I have created linode volume using terraform so I am able to fetch linodeId here.
resource "linode_instance" "foobaz" {
root_pass = "3X4mp13"
type = "g6-nanode-1"
region = "us-west"
tags = ["foobaz"]
}
resource "linode_volume" "foobar" {
label = "foo-volume"
region = linode_instance.foobaz.region
linode_id = linode_instance.foobaz.id
}
so Why I am not able get LinodeId in that curl API ?
or is there any other way to do above task using terraform?