I'm trying to add security groups and new rules to an instance by using Terraform. Note that this instance is not being managed by Terraform. The issue I run into is that when I apply it it creates a new instance.
My Terraform code is as follows:
resource "openstack_compute_secgroup_v2" "secgroup_1" {
name = "my_secgroup"
region = "${var.region}"
description = "my security group"
rule {
from_port = 22
to_port = 22
ip_protocol = "tcp"
cidr = "x.x.x.x/x"
}
rule {
from_port = 80
to_port = 80
ip_protocol = "tcp"
cidr = "x.x.x.x/x"
}
}
resource "openstack_compute_instance_v2" "myresource" {
name = "<Name of MY Instance>"
flavor_name = "m1.medium"
region = "${var.region}"
image_id = "<Image I.D of existing instance>"
security_groups = ["${openstack_compute_secgroup_v2.secgroup_1.name}"]
}