mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Add 'aws_default_vpc_dhcp_options' resource. (#14475)
This commit is contained in:
parent
a94adbb36d
commit
36888278b5
@ -443,6 +443,7 @@ func Provider() terraform.ResourceProvider {
|
||||
"aws_subnet": resourceAwsSubnet(),
|
||||
"aws_volume_attachment": resourceAwsVolumeAttachment(),
|
||||
"aws_vpc_dhcp_options_association": resourceAwsVpcDhcpOptionsAssociation(),
|
||||
"aws_default_vpc_dhcp_options": resourceAwsDefaultVpcDhcpOptions(),
|
||||
"aws_vpc_dhcp_options": resourceAwsVpcDhcpOptions(),
|
||||
"aws_vpc_peering_connection": resourceAwsVpcPeeringConnection(),
|
||||
"aws_vpc_peering_connection_accepter": resourceAwsVpcPeeringConnectionAccepter(),
|
||||
|
@ -0,0 +1,90 @@
|
||||
package aws
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
|
||||
func resourceAwsDefaultVpcDhcpOptions() *schema.Resource {
|
||||
// reuse aws_vpc_dhcp_options schema, and methods for READ, UPDATE
|
||||
dvpc := resourceAwsVpcDhcpOptions()
|
||||
dvpc.Create = resourceAwsDefaultVpcDhcpOptionsCreate
|
||||
dvpc.Delete = resourceAwsDefaultVpcDhcpOptionsDelete
|
||||
|
||||
// domain_name is a computed value for Default Default DHCP Options Sets
|
||||
dvpc.Schema["domain_name"] = &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
}
|
||||
// domain_name_servers is a computed value for Default Default DHCP Options Sets
|
||||
dvpc.Schema["domain_name_servers"] = &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
}
|
||||
// ntp_servers is a computed value for Default Default DHCP Options Sets
|
||||
dvpc.Schema["ntp_servers"] = &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
}
|
||||
|
||||
return dvpc
|
||||
}
|
||||
|
||||
func resourceAwsDefaultVpcDhcpOptionsCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).ec2conn
|
||||
|
||||
var domainName string
|
||||
awsRegion := meta.(*AWSClient).region
|
||||
if awsRegion == "us-east-1" {
|
||||
domainName = "ec2.internal"
|
||||
} else {
|
||||
domainName = awsRegion + ".compute.internal"
|
||||
}
|
||||
req := &ec2.DescribeDhcpOptionsInput{
|
||||
Filters: []*ec2.Filter{
|
||||
&ec2.Filter{
|
||||
Name: aws.String("key"),
|
||||
Values: aws.StringSlice([]string{"domain-name"}),
|
||||
},
|
||||
&ec2.Filter{
|
||||
Name: aws.String("value"),
|
||||
Values: aws.StringSlice([]string{domainName}),
|
||||
},
|
||||
&ec2.Filter{
|
||||
Name: aws.String("key"),
|
||||
Values: aws.StringSlice([]string{"domain-name-servers"}),
|
||||
},
|
||||
&ec2.Filter{
|
||||
Name: aws.String("value"),
|
||||
Values: aws.StringSlice([]string{"AmazonProvidedDNS"}),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
resp, err := conn.DescribeDhcpOptions(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(resp.DhcpOptions) != 1 || resp.DhcpOptions[0] == nil {
|
||||
return fmt.Errorf("Default DHCP Options Set not found")
|
||||
}
|
||||
|
||||
d.SetId(aws.StringValue(resp.DhcpOptions[0].DhcpOptionsId))
|
||||
|
||||
if err := resourceAwsVpcDhcpOptionsUpdate(d, meta); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return resourceAwsVpcDhcpOptionsRead(d, meta)
|
||||
}
|
||||
|
||||
func resourceAwsDefaultVpcDhcpOptionsDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
log.Printf("[WARN] Cannot destroy Default DHCP Options Set. Terraform will remove this resource from the state file, however resources may remain.")
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
// make testacc TEST=./builtin/providers/aws/ TESTARGS='-run=TestAccAWSDefaultVpc_'
|
||||
package aws
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func TestAccAWSDefaultVpcDhcpOptions_basic(t *testing.T) {
|
||||
var d ec2.DhcpOptions
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckAWSDefaultVpcDhcpOptionsDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccAWSDefaultVpcDhcpOptionsConfigBasic,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckDHCPOptionsExists("aws_default_vpc_dhcp_options.foo", &d),
|
||||
resource.TestCheckResourceAttr(
|
||||
"aws_default_vpc_dhcp_options.foo", "domain_name", "us-west-2.compute.internal"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"aws_default_vpc_dhcp_options.foo", "domain_name_servers", "AmazonProvidedDNS"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"aws_default_vpc_dhcp_options.foo", "tags.%", "1"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"aws_default_vpc_dhcp_options.foo", "tags.Name", "Default DHCP Option Set"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccCheckAWSDefaultVpcDhcpOptionsDestroy(s *terraform.State) error {
|
||||
// We expect DHCP Options Set to still exist
|
||||
return nil
|
||||
}
|
||||
|
||||
const testAccAWSDefaultVpcDhcpOptionsConfigBasic = `
|
||||
provider "aws" {
|
||||
region = "us-west-2"
|
||||
}
|
||||
|
||||
resource "aws_default_vpc_dhcp_options" "foo" {
|
||||
tags {
|
||||
Name = "Default DHCP Option Set"
|
||||
}
|
||||
}
|
||||
`
|
@ -0,0 +1,55 @@
|
||||
---
|
||||
layout: "aws"
|
||||
page_title: "AWS: aws_default_vpc_dhcp_options"
|
||||
sidebar_current: "docs-aws-resource-default-vpc-dhcp-options"
|
||||
description: |-
|
||||
Manage the default VPC DHCP Options resource.
|
||||
---
|
||||
|
||||
# aws\_default\_vpc\_dhcp\_options
|
||||
|
||||
Provides a resource to manage the [default AWS DHCP Options Set](http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_DHCP_Options.html#AmazonDNS)
|
||||
in the current region.
|
||||
|
||||
Each AWS region comes with a default set of DHCP options.
|
||||
**This is an advanced resource**, and has special caveats to be aware of when
|
||||
using it. Please read this document in its entirety before using this resource.
|
||||
|
||||
The `aws_default_vpc_dhcp_options` behaves differently from normal resources, in that
|
||||
Terraform does not _create_ this resource, but instead "adopts" it
|
||||
into management.
|
||||
|
||||
## Example Usage
|
||||
|
||||
Basic usage with tags:
|
||||
|
||||
```
|
||||
resource "aws_default_vpc_dhcp_options" "default" {
|
||||
tags {
|
||||
Name = "Default DHCP Option Set"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Argument Reference
|
||||
|
||||
The arguments of an `aws_default_vpc_dhcp_options` differ slightly from `aws_vpc_dhcp_options` resources.
|
||||
Namely, the `domain_name`, `domain_name_servers` and `ntp_servers` arguments are computed.
|
||||
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).
|
||||
* `tags` - (Optional) A mapping of tags to assign to the resource.
|
||||
|
||||
### Removing `aws_default_vpc_dhcp_options` from your configuration
|
||||
|
||||
The `aws_default_vpc_dhcp_options` resource allows you to manage a region's default DHCP Options Set,
|
||||
but Terraform cannot destroy it. Removing this resource from your configuration
|
||||
will remove it from your statefile and management, but will not destroy the DHCP Options Set.
|
||||
You can resume managing the DHCP Options Set via the AWS Console.
|
||||
|
||||
## Attributes Reference
|
||||
|
||||
The following attributes are exported:
|
||||
|
||||
* `id` - The ID of the DHCP Options Set.
|
@ -1344,11 +1344,15 @@
|
||||
<li<%= sidebar_current("docs-aws-resource-default-security-group") %>>
|
||||
<a href="/docs/providers/aws/r/default_security_group.html">aws_default_security_group</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li<%= sidebar_current("docs-aws-resource-default-subnet") %>>
|
||||
<a href="/docs/providers/aws/r/default_subnet.html">aws_default_subnet</a>
|
||||
</li>
|
||||
|
||||
<li<%= sidebar_current("docs-aws-resource-default-vpc-dhcp-options") %>>
|
||||
<a href="/docs/providers/aws/r/default_vpc_dhcp_options.html">aws_default_vpc_dhcp_options</a>
|
||||
</li>
|
||||
|
||||
<li<%= sidebar_current("docs-aws-resource-egress-only-internet-gateway") %>>
|
||||
<a href="/docs/providers/aws/r/egress_only_internet_gateway.html">aws_egress_only_internet_gateway</a>
|
||||
</li>
|
||||
|
Loading…
Reference in New Issue
Block a user