diff --git a/.changelog/19656.txt b/.changelog/19656.txt new file mode 100644 index 00000000000..32399c4fe36 --- /dev/null +++ b/.changelog/19656.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_default_vpc_dhcp_options: Add `owner_id` argument. +``` \ No newline at end of file diff --git a/aws/resource_aws_default_vpc_dhcp_options.go b/aws/resource_aws_default_vpc_dhcp_options.go index 49f967b2922..f5a4fab6991 100644 --- a/aws/resource_aws_default_vpc_dhcp_options.go +++ b/aws/resource_aws_default_vpc_dhcp_options.go @@ -33,31 +33,48 @@ func resourceAwsDefaultVpcDhcpOptions() *schema.Resource { Computed: true, } + dvpc.Schema["owner_id"] = &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Optional: true, + } + return dvpc } func resourceAwsDefaultVpcDhcpOptionsCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).ec2conn - req := &ec2.DescribeDhcpOptionsInput{ - Filters: []*ec2.Filter{ - { - Name: aws.String("key"), - Values: aws.StringSlice([]string{"domain-name"}), - }, - { - Name: aws.String("value"), - Values: aws.StringSlice([]string{resourceAwsEc2RegionalPrivateDnsSuffix(meta.(*AWSClient).region)}), - }, - { - Name: aws.String("key"), - Values: aws.StringSlice([]string{"domain-name-servers"}), - }, - { - Name: aws.String("value"), - Values: aws.StringSlice([]string{"AmazonProvidedDNS"}), - }, + filters := []*ec2.Filter{ + { + Name: aws.String("key"), + Values: aws.StringSlice([]string{"domain-name"}), + }, + { + Name: aws.String("value"), + Values: aws.StringSlice([]string{resourceAwsEc2RegionalPrivateDnsSuffix(meta.(*AWSClient).region)}), + }, + { + Name: aws.String("key"), + Values: aws.StringSlice([]string{"domain-name-servers"}), }, + { + Name: aws.String("value"), + Values: aws.StringSlice([]string{"AmazonProvidedDNS"}), + }, + } + + if v, ok := d.GetOk("owner_id"); ok { + filter := &ec2.Filter{ + Name: aws.String("owner-id"), + Values: aws.StringSlice([]string{v.(string)}), + } + + filters = append(filters, filter) + } + + req := &ec2.DescribeDhcpOptionsInput{ + Filters: filters, } var dhcpOptions []*ec2.DhcpOptions diff --git a/aws/resource_aws_default_vpc_dhcp_options_test.go b/aws/resource_aws_default_vpc_dhcp_options_test.go index 51cf6c6c971..ab6cc56ee66 100644 --- a/aws/resource_aws_default_vpc_dhcp_options_test.go +++ b/aws/resource_aws_default_vpc_dhcp_options_test.go @@ -11,7 +11,7 @@ import ( func TestAccAWSDefaultVpcDhcpOptions_basic(t *testing.T) { var d ec2.DhcpOptions - resourceName := "aws_default_vpc_dhcp_options.foo" + resourceName := "aws_default_vpc_dhcp_options.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -35,13 +35,51 @@ func TestAccAWSDefaultVpcDhcpOptions_basic(t *testing.T) { }) } +func TestAccAWSDefaultVpcDhcpOptions_owner(t *testing.T) { + var d ec2.DhcpOptions + resourceName := "aws_default_vpc_dhcp_options.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ErrorCheck: testAccErrorCheck(t, ec2.EndpointsID), + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSDefaultVpcDhcpOptionsDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSDefaultVpcDhcpOptionsConfigOwner, + Check: resource.ComposeTestCheckFunc( + testAccCheckDHCPOptionsExists(resourceName, &d), + testAccMatchResourceAttrRegionalARN(resourceName, "arn", "ec2", regexp.MustCompile(`dhcp-options/dopt-.+`)), + resource.TestCheckResourceAttr(resourceName, "domain_name", resourceAwsEc2RegionalPrivateDnsSuffix(testAccGetRegion())), + resource.TestCheckResourceAttr(resourceName, "domain_name_servers", "AmazonProvidedDNS"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.Name", "Default DHCP Option Set"), + testAccCheckResourceAttrAccountID(resourceName, "owner_id"), + ), + }, + }, + }) +} + func testAccCheckAWSDefaultVpcDhcpOptionsDestroy(s *terraform.State) error { // We expect DHCP Options Set to still exist return nil } const testAccAWSDefaultVpcDhcpOptionsConfigBasic = ` -resource "aws_default_vpc_dhcp_options" "foo" { +resource "aws_default_vpc_dhcp_options" "test" { + tags = { + Name = "Default DHCP Option Set" + } +} +` + +const testAccAWSDefaultVpcDhcpOptionsConfigOwner = ` +data "aws_caller_identity" "current" {} + +resource "aws_default_vpc_dhcp_options" "test" { + owner_id = data.aws_caller_identity.current.account_id + tags = { Name = "Default DHCP Option Set" } diff --git a/website/docs/r/default_vpc_dhcp_options.html.markdown b/website/docs/r/default_vpc_dhcp_options.html.markdown index 9c46ffe3ef4..f4a852e724e 100644 --- a/website/docs/r/default_vpc_dhcp_options.html.markdown +++ b/website/docs/r/default_vpc_dhcp_options.html.markdown @@ -39,6 +39,7 @@ The following arguments are still supported: * `netbios_name_servers` - (Optional) List of NETBIOS name servers. * `netbios_node_type` - (Optional) The NetBIOS node type (1, 2, 4, or 8). AWS recommends to specify 2 since broadcast and multicast are not supported in their network. For more information about these node types, see [RFC 2132](http://www.ietf.org/rfc/rfc2132.txt). +* `owner_id` - The ID of the AWS account that owns the DHCP options set. * `tags` - (Optional) A map of tags to assign to the resource. ### Removing `aws_default_vpc_dhcp_options` from your configuration @@ -54,7 +55,6 @@ In addition to all arguments above, the following attributes are exported: * `id` - The ID of the DHCP Options Set. * `arn` - The ARN of the DHCP Options Set. -* `owner_id` - The ID of the AWS account that owns the DHCP options set. ## Import