Terraform w/ OpenStack provider
It's been a while since I posted to this blog so thought I'd revive it by putting up a quick update on what I've experienced with Terraform using the OpenStack provider recently.
At work, I've been the owner of the deployment of FortiSwitch Cloud in new regions. The platform that the application is running on is Kubernetes which itself is running on VMware Integrated OpenStack (VIO). We might discuss them in further detail in future posts.
One of the steps in the deployment entailed creating a new network in OpenStack (project network specifically, you can read more about OpenStack networking here). I tried creating a network by defining a Terraform Resource block, a simplified version is shown below:
resource "openstack_networking_network_v2" "network_1" {
name = "network_1"
admin_state_up = "true"
}
resource "openstack_networking_subnet_v2" "subnet_1" {
name = "subnet_1"
network_id = "${openstack_networking_network_v2.network_1.id}"
cidr = "192.168.1.0/24"
ip_version = 4
}
While the above block of code ended up creating the network and subnet that I required, whenever I tried creating a VM and assigning a port from the above Subnet, my VM was unreachable from the outside network and I couldn't ping outside the network from the VM as well despite Port Security feature being turned off.
After some initial troubleshooting, I figured it might be an issue with the underlying Physical Network options and checked with the OpenStack networking team who gave me a trace log from the Gateway which showed that my Subnet was on a certain VLAN. This was an aha moment for me and I quickly updated my code to include '
segmentation_id
'. But when I tried to plan and apply the terraform file now, I had issues. So, having access to the GUI, I tried to manually create the network with the VLAN to see if there was any more information on the error message. Turns out there was no VLAN (aka segmentation_id) field at all!
This is when I was perplexed and opened a ticket with the OpenStack team asking them for help with my network creation, they then mentioned that since I only had had 'tenant administrator' privileges and not 'cloud administrator' privileges, I could not see the segmentation ID and that they had to create the network for me with the right VLAN ID information.
Once they created the network, then there was a matter of importing that information into my Terraform files, I initially tried to use a data block as below
data "openstack_networking_network_v2" "network" {
name = "tf_test_network"
}
But despite my best attempts, I could not get this to work so I resolved to use the following import command which worked beautifully.
terraform import openstack_networking_network_v2.network_1 d90ce693-5ccf-4136-a0ed-152ce412b6b9
Another issue that I had with OpenStack was when I was trying to import the keypairs that my colleagues had created for deployments, turns out every user has their own keypairs which in hindsight makes sense but I had to perform some troubleshooting to realize.
Thank you for reading this post! Looking forward to updating this blog more regularly.
Comments
Post a Comment