How to add an instance to an existing security group while creating in terraform instead of creating a new security group resource?
code in var.tf
variable "sg" {
type =string
default = "sg-111436g6535hc63xc"
}
code in resource.tf
resource "aws_instance" "web" {
ami = var.ami
key_name = var.key
instance_type = var.itype
security_groups = var.sg
tags = {
Name = "HelloWorld"
}
}
But I'm getting ->
│ Error: Incorrect attribute value type
│
│ on resource.tf line 5, in resource "aws_instance" "web":
│ 5: security_groups = var.sg
│ ├────────────────
│ │ var.sg is a string, known only after apply
│
│ Inappropriate value for attribute "security_groups": set of string required.
How to solve this error?