Terraform: Unable to assign dhcp_options_id to VPC " this field cannot be set"

Created on 15 Nov 2016  ยท  4Comments  ยท  Source: hashicorp/terraform

teraform v0.7.10

aws_vpc

DHCP options

resource "aws_vpc_dhcp_options" "my_dhcp_options" {
domain_name = "prod.us-east-2.mydomain.com"
domain_name_servers = ["12.3.4", "5.6.7.8"]
ntp_servers = ["1.2.3.4","5.6.7.8"]
tags {
Name = "my_DHCP_opts"
creator = "terraform"
quality = "alpha"
}
}

Create a VPC to launch our instances into

resource "aws_vpc" "my_vpc_v1" {
cidr_block = "172.28.248.0/21"
instance_tenancy = "default"
dhcp_options_id = "${aws_vpc_dhcp_options.CONNECT_dhcp_options.id}"
enable_classiclink = 0
enable_dns_hostnames = 0
enable_dns_support = 0
tags {
Name = "my_vpc_1"
creator = "terraform"
quality = "alpha"
}
}

Expected Behavior

Should have assigned that dhcp ID to the VPC

Actual Behavior

Errors:

  • aws_vpc.CONNECT_vpc_v1: "dhcp_options_id": this field cannot be set

Steps to Reproduce

"terraform plan" or "terraform apply"

Notes:

Using us-east-2, terraform 64 bit on ubuntu 16.04

provideaws question

Most helpful comment

That worked. The docs are confusing then as you have both a data source and resource called aws_vpc with differing arguments, but without explanation of the differences.
https://www.terraform.io/docs/providers/aws/d/vpc.html vs https://www.terraform.io/docs/providers/aws/r/vpc.html

All 4 comments

This field is computed and set when you create the VPC. Could you try using the aws_vpc_dhcp_options_association resource?

Hi @djandruczyk

Thanks for opening the issue, @Ninir is indeed correct, the correct way to do this would be as follows:

resource "aws_vpc" "foo" {
    cidr_block = "10.1.0.0/16"
}

resource "aws_vpc_dhcp_options" "foo" {
    domain_name = "service.consul"
    domain_name_servers = ["127.0.0.1", "10.0.0.2"]
    ntp_servers = ["127.0.0.1"]
    netbios_name_servers = ["127.0.0.1"]
    netbios_node_type = 2

    tags {
        Name = "foo"
    }
}

resource "aws_vpc_dhcp_options_association" "foo" {
    vpc_id = "${aws_vpc.foo.id}"
    dhcp_options_id = "${aws_vpc_dhcp_options.foo.id}"
}

Hope it helps

Paul

That worked. The docs are confusing then as you have both a data source and resource called aws_vpc with differing arguments, but without explanation of the differences.
https://www.terraform.io/docs/providers/aws/d/vpc.html vs https://www.terraform.io/docs/providers/aws/r/vpc.html

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings