Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/default_vpc_dhcp_options - add owner_id arg #19656

Merged
merged 3 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/19656.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_default_vpc_dhcp_options: Add `owner_id` argument.
```
53 changes: 35 additions & 18 deletions aws/resource_aws_default_vpc_dhcp_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 40 additions & 2 deletions aws/resource_aws_default_vpc_dhcp_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand All @@ -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"
}
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/default_vpc_dhcp_options.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down