3

When I run terraform apply with the resource:

 resource "aws_default_subnet" "my_az_default_subnet" { availability_zone = "eu-north-1" } 

I get the error:

aws_default_subnet.learntf_default_subnet: Creating... Error: Default subnet not found 

even if the default VPC and subnet exists in the specified availability_zone "eu-north-1".


provider.tf:

provider "aws" { access_key = var.aws_access_key secret_key = var.aws_secret_key region = "eu-north-1" } 

variables.tf:

variable "aws_access_key" {} variable "aws_secret_key" {} 

network.tf:

resource "aws_default_subnet" "learntf_default_subnet" { availability_zone = "eu-north-1" } 
6
  • Are you saying the default subnet exists before or after the apply? Commented Apr 10, 2020 at 11:34
  • The default subnet exists before the apply Commented Apr 10, 2020 at 12:28
  • According to the documentation: docs.aws.amazon.com/vpc/latest/userguide/…, you can only have on default subnet per AZ, so this would definitely fail. Is your issue that the error message is not as clear as you would like? Commented Apr 10, 2020 at 12:48
  • According to terraform documentation: "The aws_default_subnet behaves differently from normal resources, in that Terraform does not create this resource, but instead "adopts" it into management." (terraform.io/docs/providers/aws/r/default_subnet.html) So I would expect terraform to apply the specified resource, with no error, without creating it, and adopting it into management. Commented Apr 10, 2020 at 13:01
  • You likely need to import it into your state first then. Commented Apr 10, 2020 at 13:47

1 Answer 1

3

My mistake. It worked with.

resource "aws_default_subnet" "def_subnet" { availability_zone = "eu-north-1a" } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.