Hi,
I am creating a cluster web servers. I got two errors.
"Error authorizing security group egress rules: InvalidParameterValue: Only Amazon VPC security groups may be used with this operation" and "Security group(s) can be applied to only an ELB in VPC".
Here are the errors and source. Can anyone help?
Errors:
Errors related to security group egress rules:
aws_launch_configuration.example: Creation complete after 2s (ID: terraform-20180410215736754200000001)
Error: Error applying plan:
1 error(s) occurred:
* aws_security_group.elb: 1 error(s) occurred:
* aws_security_group.elb: Error authorizing security group egress rules: InvalidParameterValue: Only Amazon VPC security groups may be used with this operation.
status code: 400, request id: 597a8900-e358-460f-8e25-4f8817c5c1a6
Here are the source code:
cat main.tf
provider "aws" {
region = "us-east-1"
}
resource "aws_autoscaling_group" "example" {
launch_configuration = "${aws_launch_configuration.example.id}"
availability_zones = ["us-east-1a","us-east-1b","us-east-1c","us-east-1d"]
min_size = 2
max_size = 10
load_balancers = ["${aws_elb.example.name}"]
health_check_type = "ELB"
tag {
key = "Name"
value = "terraform-asg-example"
propagate_at_launch = true
}
}
resource "aws_launch_configuration" "example" {
# Ubuntu Server 14.04 LTS (HVM), SSD Volume Type in us-east-1
image_id = "ami-2d39803a"
instance_type = "t2.micro"
security_groups = ["${aws_security_group.instance.id}"]
user_data = <<-EOF
#!/bin/bash
echo "Hello, World" > index.html
nohup busybox httpd -f -p "${var.server_port}" &
EOF
lifecycle {
create_before_destroy = true
}
}
resource "aws_security_group" "instance" {
name = "terraform-example-instance"
# Inbound HTTP from anywhere
ingress {
from_port = "${var.server_port}"
to_port = "${var.server_port}"
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_elb" "example" {
name = "terraform-asg-example"
security_groups = ["${aws_security_group.elb.id}"]
availability_zones = ["us-east-1a","us-east-1b","us-east-1c","us-east-1d"]
health_check {
healthy_threshold = 2
unhealthy_threshold = 2
timeout = 3
interval = 30
target = "HTTP:${var.server_port}/"
}
# This adds a listener for incoming HTTP requests.
listener {
lb_port = 80
lb_protocol = "http"
instance_port = "${var.server_port}"
instance_protocol = "http"
}
}
resource "aws_security_group" "elb" {
name = "terraform-example-elb"
# Allow all outbound
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
# Inbound HTTP from anywhere
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
cat vars.tf
variable "server_port" {
description = "The port the server will use for HTTP requests"
default = 8080
}
cat outputs.tf
output "elb_dns_name" {
value = "${aws_elb.example.dns_name}"
}
Added vpc_id to resource "aws_security_group" "elb" {}, I got, "Security group(s) can be applied to only an ELB in VPC".
Error: Error applying plan:
1 error(s) occurred:
* aws_elb.example: 1 error(s) occurred:
* aws_elb.example: InvalidConfigurationRequest: Security group(s) can be applied to only an ELB in VPC.
status code: 409, request id: 8ed46978-3d0b-11e8-b99a-a3ef9c006301
resource "aws_security_group" "elb" {
name = "terraform-example-elb"
vpc_id = "My-vpc-ID"
# Allow all outbound
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
# Inbound HTTP from anywhere
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CAHMk6OFMs1SHCRsXs5X8nHMDF22i-rGyWVNzG_pop8_N7pHO-w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
resource "aws_security_group" "elb" {
name = "terraform-example-elb"
vpc_id = "vpc-my-id"
......
}
resource "aws_security_group" "instance" {
name = "terraform-example-instance"
vpc_id = "vpc-my-id"
......* aws_security_group.elb: 1 error(s) occurred:
* aws_security_group.elb: Error creating Security Group: InvalidGroup.Duplicate: The security group 'terraform-example-elb' already exists for VPC 'vpc-24b12f5f'
status code: 400, request id: 1a7208d9-31c1-4fde-a932-646294f2d333
provider "aws" {
region = "us-east-1"
}
data "aws_availability_zones" "all" {}
resource "aws_autoscaling_group" "example" {
launch_configuration = "${aws_launch_configuration.example.id}"
availability_zones = ["${data.aws_availability_zones.all.names}"]
min_size = 2
max_size = 10
load_balancers = ["${aws_elb.example.name}"]
health_check_type = "ELB"
tag {
key = "Name"
value = "terraform-asg-example"
propagate_at_launch = true
}
}
resource "aws_launch_configuration" "example" {
image_id = "ami-2d39803a"
instance_type = "t2.micro"
security_groups = ["${aws_security_group.instance.id}"]
user_data = <<-EOF
#!/bin/bash
echo "Hello, World" > index.html
nohup busybox httpd -f -p "${var.server_port}" &
EOF
lifecycle {
create_before_destroy = true
}
}
resource "aws_security_group" "instance" {
name = "terraform-example-instance"
vpc_id = "vpc-24b12f5f"
ingress {
from_port = "${var.server_port}"
to_port = "${var.server_port}"
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_elb" "example" {
name = "terraform-asg-example"
security_groups = ["${aws_security_group.elb.id}"]
availability_zones = ["${data.aws_availability_zones.all.names}"]
health_check {
healthy_threshold = 2
unhealthy_threshold = 2
timeout = 3
interval = 30
target = "HTTP:${var.server_port}/"
}
listener {
lb_port = 80
lb_protocol = "http"
instance_port = "${var.server_port}"
instance_protocol = "http"
}
}
resource "aws_security_group" "elb" {
name = "terraform-example-elb"
vpc_id = "vpc-24b12f5f"
resource "aws_security_group" "elb" {
name = "terraform-example-elb"
#vpc_id = "vpc-my-id"
......
}
* aws_security_group.elb: 1 error(s) occurred:
* aws_security_group.elb: Error authorizing security group egress rules: InvalidParameterValue: Only Amazon VPC security groups may be used with this operation.
status code: 400, request id: e78a1dc8-c081-4b47-b9c5-6251d2ea1c4f
Error: aws_launch_configuration.example: : invalid or unknown key: subnet_id"
resource "aws_launch_configuration" "example" {
# Ubuntu Server 14.04 LTS (HVM), SSD Volume Type in us-east-1
image_id = "ami-2d39803a"
instance_type = "t2.micro"
security_groups = ["${aws_security_group.instance.id}"]
subnet_id = "subnet-my-id"
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CAMN_gXFb7AkYR5ek%3DH-TSqmjF5U_2szuANOT-tLnCOqr0_11-A%40mail.gmail.com.
Error: aws_autoscaling_group.example: : invalid or unknown key: subnets"
if I place subnets in resource "aws_autoscaling_group" "example" {}
resource "aws_autoscaling_group" "example" {
launch_configuration = "${aws_launch_configuration.example.id}"
subnets = ["${aws_subnet.tf_test_subnet.id}"]
......}
if I commented out subnets in resource "aws_autoscaling_group" "example" {}, then I got,
* aws_autoscaling_group.example: Error creating AutoScaling Group: ValidationError: At least one Availability Zone or VPC Subnet is required.
status code: 400, request id: 04451d3e-442f-11e8-af40-e1aa71748b4c
Any idea?
Here are source code:
provider "aws" {
region = "us-east-1"
}
resource "aws_subnet" "tf_test_subnet" {
vpc_id = "${aws_vpc.default.id}"
cidr_block = "10.0.0.0/24"
map_public_ip_on_launch = true
tags {
Name = "tf_test_subnet"
}
}
resource "aws_vpc" "default" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
tags {
Name = "tf_test"
}
}
resource "aws_internet_gateway" "gw" {
vpc_id = "${aws_vpc.default.id}"
tags {
Name = "tf_test_ig"
}
}
resource "aws_route_table" "r" {
vpc_id = "${aws_vpc.default.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.gw.id}"
}
tags {
Name = "aws_route_table"
}
}
resource "aws_route_table_association" "a" {
subnet_id = "${aws_subnet.tf_test_subnet.id}"
route_table_id = "${aws_route_table.r.id}"
}
resource "aws_autoscaling_group" "example" {
launch_configuration = "${aws_launch_configuration.example.id}"
#subnets = ["${aws_subnet.tf_test_subnet.id}"]
min_size = 2
max_size = 10
load_balancers = ["${aws_elb.example.name}"]
health_check_type = "ELB"
tag {
key = "Name"
value = "terraform-asg-example"
propagate_at_launch = true
}
}
resource "aws_launch_configuration" "example" {
image_id = "ami-2d39803a"
instance_type = "t2.micro"
security_groups = ["${aws_security_group.instance.id}"]
user_data = <<-EOF
#!/bin/bash
echo "Hello, World" > index.html
nohup busybox httpd -f -p "${var.server_port}" &
EOF
lifecycle {
create_before_destroy = true
}
}
resource "aws_security_group" "instance" {
name = "terraform-example-instance"
vpc_id = "${aws_vpc.default.id}"
ingress {
from_port = "${var.server_port}"
to_port = "${var.server_port}"
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_elb" "example" {
name = "terraform-asg-example"
health_check {
healthy_threshold = 2
unhealthy_threshold = 2
timeout = 3
interval = 30
target = "HTTP:${var.server_port}/"
}
listener {
lb_port = 80
lb_protocol = "http"
instance_port = "${var.server_port}"
instance_protocol = "http"
}
}
resource "aws_security_group" "elb" {
name = "terraform-example-elb"
vpc_id = "${aws_vpc.default.id}"