Linode_instance_shared_ips Is Not Allowed In Terraform
I tried to add shared ip on my instance but got the following error.
linode_instance_shared_ips.my-shared-ips: Creating…
Error: failed to update ips for linode 48144348: [405] Method Not Allowed with linode_instance_shared_ips.my-shared-ips,
on linode.tf line 15, in resource "linode_instance_shared_ips" "my-shared-ips":
15: resource "linode_instance_shared_ips" "my-shared-ips" {
here is my simple terraform code.
--- linode.tf ---
resource "linode_instance" "my-instance" {
label = var.dmzhost.label
type = var.dmzhost.type
region = var.region
tags = var.dmzhost.tags
image = var.dmzhost.image
root_pass = random_string.password.result
}
resource "linode_instance_shared_ips" "my-shared-ips" {
linode_id = linode_instance.my-instance.id
addresses = ["172.232.XXX.XXX"]
}
--- variable.tf ---
variable "token" {
type = string
default = "my token"
}
variable "region" {
default = "us-ord"
}
variable "dmzhost" {
default = {
label = "terraform-test1"
image = "linode/ubuntu22.04"
type = "g6-nanode-1"
tags = ["redis-ord-ha"]
swapsize = 512
}
}
resource "random_string" "password" {
length = 32
length = 11
special = true
upper = true
lower = true
numeric = true
}
172.232.XXX.XXX is assigned to my other instance. This is the second IP for that host.
My scenario is as follows:
node A: the first public IP and the second public IP
node B: the first public IP, and shared IP (node A's second public IP)
Let me know if you have any solution.
2 Replies
I've attempted to create a shared IP on my instance and ran into the same error you did:
│ Error: failed to update ips for linode 48288017: [405] Method Not Allowed
│
│ with linode_instance_shared_ips.share-primary,
│ on shared-ip.tf line 15, in resource "linode_instance_shared_ips" "share-primary":
│ 15: resource "linode_instance_shared_ips" "share-primary" {
After looking over our API documentation, there was an error from the API when pointing at v4
rather than v4beta
. I needed to modify my configuration with the api_version provider argument set to v4beta
. I had my provider {} block defined and just needed to add api_version = "v4beta"
as an argument to it.
My syntax was still incomplete even after entering this information. My primary and secondary nodes were created, but it did not boot because it did not have a configuration file. I've noticed that the Terraform Shared IP guide did not provide the necessary information on how to make a request to Linode, or provide an image
or a root_password
in the syntax, so I had to manually enter this as well:
>terraform {
required_providers {
linode = {
source = "linode/linode"
version = "2.5.2"
}
}
}
provider "linode" {
api_version = "v4beta"
token = "<your-api-token>"
}
# Share the IP with the secondary node
resource "linode_instance_shared_ips" "share-primary" {
linode_id = linode_instance.secondary.id
addresses = [linode_instance_ip.primary.address]
}
# Allocate an IP under the primary node
resource "linode_instance_ip" "primary" {
linode_id = linode_instance.primary.id
}
# Create a single primary node
resource "linode_instance" "primary" {
image = "linode/ubuntu18.04"
label = "node-primary"
type = "g6-nanode-1"
region = "us-ord"
root_pass = "<complicated-secret-password>"
}
# Create a secondary node
resource "linode_instance" "secondary" {
image = "linode/ubuntu18.04"
label = "node-secondary"
type = "g6-nanode-1"
region = "us-ord"
root_pass = "<complicated-secret-password>"
}
Even after all that troubleshooting I ran into into this error because of my previous Terraform plan that was created:
│ Error: failed to get instance (48289346) ip: [404] Not found
│
│ with linode_instance_ip.primary,
│ on linode-terraform-primarynode.tf line 22, in resource "linode_instance_ip" "primary":
│ 22: resource "linode_instance_ip" "primary" {
I then ran terraform state list
to list all the resources in the state file matching the given addresses. I then used terraform state rm
to remove the binding to my existing object which made Terraform "forget" the object while it continues to exist in my system:
root@localhost:~/terraform# terraform state list
linode_instance.primary
linode_instance.secondary
linode_instance_ip.primary
linode_instance_shared_ips.share-primary
root@localhost:~/terraform# terraform state rm linode_instance.primary
Removed linode_instance.primary
Successfully removed 1 resource instance(s).
Afterwards, I was able to successfully create two nodes that shared an IP.
Wow! Thank you. Yes, I used v4beta in Linode API successfully but have not specified any "beta" word in Terraform. Once I created a new instance, then the following code worked. I just changed two lines.
resource "linode_instance" "my-instance" {
label = var.dmzhost.label
type = var.dmzhost.type
region = var.region
tags = var.dmzhost.tags
image = var.dmzhost.image
root_pass = random_string.password.result
shared_ipv4 = ["XXX.XXX.XXX.XXX"] ### Added
}
shared_ipv4
is an IP that another instance has as an additional IP address. Then, I added api_version
.
provider "linode" {
token = "${var.token}"
api_version = "v4beta" ### Added
}
The above terraform creates/modifies a node B config in the following case:
node A: the first public IP and the second public IP
node B: the first public IP, and shared IP (node A's second public IP)
Thank you so much for your analysis and support.