resource "aws_subnet" "default" { vpc_id = "${aws_vpc.default.id}" cidr_block = "10.0.1.0/24" map_public_ip_on_launch = true}
--
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-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/14c54955-c29b-41fc-9e6f-2a71b547d74d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Andrew Langhorn | |
Senior Infrastructure Engineer | |
andrew....@thoughtworks.com | |
Telephone | +44 7733 339809 |
![]() |
You received this message because you are subscribed to a topic in the Google Groups "Terraform" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/terraform-tool/bXZc1KNAcgU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CAEpa1DL%2Bjg8%2BvQCVCOteM5gP_j0weCW1swzNojw-O8OZKseP8g%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CA%2BHSj0XKR%3Dp19GNT-ZZYjYTkQdwdo6Gn1SDwxDM8TErWaJyvYg%40mail.gmail.com.
Ok cool, thanks for that.There's no real reason for trying to access the default VPC, was just playing around with the variables and was wondering how it was possible. Although, just thinking about it now, there's no reason to access the default VPC, but what if you had already created a VPC for another deployment and wanted to use that one? You could enter in all the relevant information manually from the AWS console, but it would be nice to just know the id VPC and then use that to get additional information.Anyway, not critical, just a nice to have.Barry
Telephone +44 7733 339809
data "aws_vpc" "default" {
default = true
}
data "aws_subnet" "default" {
vpc_id = "${data.aws_vpc.default.id}"
default_for_az = true
availability_zone = "${var.availability_zone}"
}
data "aws_subnet_ids" "all" {
vpc_id = "${data.aws_vpc.vpc.id}"
}
resource "aws_vpc" "new_vpc" {
count = "${var.use_default == "true" ? 0 : 1}"
cidr_block = "${var.vpc_cidr_block}"
}
data "aws_vpc" "vpc" {
id = "${var.use_default == "true" ? data.aws_vpc.default.id : join(" ", aws_vpc.new_vpc.*.id)}"
}
resource "aws_subnet" "new_subnet" {
count = "${var.use_default == "true" ? 0 : 1}"
cidr_block = "${cidrsubnet(aws_vpc.new_vpc.cidr_block, 4, count.index + 1)}"
vpc_id = "${aws_vpc.new_vpc.id}"
availability_zone = "${var.availability_zone}"
}
data "aws_subnet" "subnet" {
id = "${var.use_default == "true" ? data.aws_subnet.default.id : join(" ", aws_subnet.new_subnet.*.id)}"
}
output "vpc_id" {
value = "${data.aws_vpc.vpc.id}"
}
output "subnet_id" {
value = "${data.aws_subnet.subnet.id}"
}
output "subnet_cidr_block" {
value = "${data.aws_subnet.subnet.cidr_block}"
}
output "vpc_cidr_block" {
value = "${data.aws_vpc.vpc.cidr_block}"
}
output "subnet_ids" {
value = ["${data.aws_subnet_ids.all.ids}"]
}
When I attempted to use this technique, it appears that the existing default VPC for my account and region was adopted into my application. The default VPC for my account and region was set up by our network and security group, so I do not have permissions to delete it (nor would I want to since it is shared). When I attempted to destroy my application, I received this errormodule.linux_builder.data.aws_vpc.default: 1 error(s) occurred:* module.linux_builder.data.aws_vpc.default: data.aws_vpc.default: UnauthorizedOperation: You are not authorized to perform this operation.status code: 403, request id: 46316bc5-67d6-4b07-8654-a150a426dcf5* data.aws_subnet_ids.all: 1 error(s) occurred:* data.aws_subnet_ids.all: data.aws_subnet_ids.all: UnauthorizedOperation: You are not authorized to perform this operation.status code: 403, request id: 0d745f88-aa90-4dfb-bf98-fab371f446d1Is there a way to get default VPC information without adopting it into my application's configuration?
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/7a026c08-2deb-4c4f-9b5c-320a625e0234%40googlegroups.com.To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.