-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
New Resource: ServiceDiscovery PrivateDNS Namespace #2589
Merged
radeksimko
merged 2 commits into
hashicorp:master
from
atsushi-ishibashi:private_dns_namespace
Dec 12, 2017
+256
−0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
aws/resource_aws_service_discovery_private_dns_namespace.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/servicediscovery" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func resourceAwsServiceDiscoveryPrivateDnsNamespace() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceAwsServiceDiscoveryPrivateDnsNamespaceCreate, | ||
Read: resourceAwsServiceDiscoveryPrivateDnsNamespaceRead, | ||
Delete: resourceAwsServiceDiscoveryPrivateDnsNamespaceDelete, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
}, | ||
"vpc": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"hosted_zone": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceAwsServiceDiscoveryPrivateDnsNamespaceCreate(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).sdconn | ||
|
||
requestId := resource.PrefixedUniqueId(fmt.Sprintf("tf-%s", d.Get("name").(string))) | ||
input := &servicediscovery.CreatePrivateDnsNamespaceInput{ | ||
Name: aws.String(d.Get("name").(string)), | ||
Vpc: aws.String(d.Get("vpc").(string)), | ||
CreatorRequestId: aws.String(requestId), | ||
} | ||
|
||
if v, ok := d.GetOk("description"); ok { | ||
input.Description = aws.String(v.(string)) | ||
} | ||
|
||
resp, err := conn.CreatePrivateDnsNamespace(input) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{servicediscovery.OperationStatusSubmitted, servicediscovery.OperationStatusPending}, | ||
Target: []string{servicediscovery.OperationStatusSuccess}, | ||
Refresh: servicediscoveryOperationRefreshStatusFunc(conn, *resp.OperationId), | ||
Timeout: 5 * time.Minute, | ||
} | ||
|
||
opresp, err := stateConf.WaitForState() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(*opresp.(*servicediscovery.GetOperationOutput).Operation.Targets["NAMESPACE"]) | ||
return resourceAwsServiceDiscoveryPrivateDnsNamespaceRead(d, meta) | ||
} | ||
|
||
func resourceAwsServiceDiscoveryPrivateDnsNamespaceRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).sdconn | ||
|
||
input := &servicediscovery.GetNamespaceInput{ | ||
Id: aws.String(d.Id()), | ||
} | ||
|
||
resp, err := conn.GetNamespace(input) | ||
if err != nil { | ||
if isAWSErr(err, servicediscovery.ErrCodeNamespaceNotFound, "") { | ||
d.SetId("") | ||
return nil | ||
} | ||
return err | ||
} | ||
|
||
d.Set("description", resp.Namespace.Description) | ||
d.Set("arn", resp.Namespace.Arn) | ||
if resp.Namespace.Properties != nil { | ||
d.Set("hosted_zone", resp.Namespace.Properties.DnsProperties.HostedZoneId) | ||
} | ||
return nil | ||
} | ||
|
||
func resourceAwsServiceDiscoveryPrivateDnsNamespaceDelete(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).sdconn | ||
|
||
input := &servicediscovery.DeleteNamespaceInput{ | ||
Id: aws.String(d.Id()), | ||
} | ||
|
||
resp, err := conn.DeleteNamespace(input) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{servicediscovery.OperationStatusSubmitted, servicediscovery.OperationStatusPending}, | ||
Target: []string{servicediscovery.OperationStatusSuccess}, | ||
Refresh: servicediscoveryOperationRefreshStatusFunc(conn, *resp.OperationId), | ||
Timeout: 5 * time.Minute, | ||
} | ||
|
||
_, err = stateConf.WaitForState() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId("") | ||
return nil | ||
} |
78 changes: 78 additions & 0 deletions
78
aws/resource_aws_service_discovery_private_dns_namespace_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/servicediscovery" | ||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccAwsServiceDiscoveryPrivateDnsNamespace_basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAwsServiceDiscoveryPrivateDnsNamespaceDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccServiceDiscoveryPrivateDnsNamespaceConfig(acctest.RandString(5)), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAwsServiceDiscoveryPrivateDnsNamespaceExists("aws_service_discovery_private_dns_namespace.test"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in your other PR - can we add more checks here? |
||
resource.TestCheckResourceAttrSet("aws_service_discovery_private_dns_namespace.test", "arn"), | ||
resource.TestCheckResourceAttrSet("aws_service_discovery_private_dns_namespace.test", "hosted_zone"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAwsServiceDiscoveryPrivateDnsNamespaceDestroy(s *terraform.State) error { | ||
conn := testAccProvider.Meta().(*AWSClient).sdconn | ||
|
||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "aws_service_discovery_private_dns_namespace" { | ||
continue | ||
} | ||
|
||
input := &servicediscovery.GetNamespaceInput{ | ||
Id: aws.String(rs.Primary.ID), | ||
} | ||
|
||
_, err := conn.GetNamespace(input) | ||
if err != nil { | ||
if isAWSErr(err, servicediscovery.ErrCodeNamespaceNotFound, "") { | ||
return nil | ||
} | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func testAccCheckAwsServiceDiscoveryPrivateDnsNamespaceExists(name string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
_, ok := s.RootModule().Resources[name] | ||
if !ok { | ||
return fmt.Errorf("Not found: %s", name) | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccServiceDiscoveryPrivateDnsNamespaceConfig(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_vpc" "test" { | ||
cidr_block = "10.0.0.0/16" | ||
} | ||
|
||
resource "aws_service_discovery_private_dns_namespace" "test" { | ||
name = "tf-sd-%s.terraform.local" | ||
description = "test" | ||
vpc = "${aws_vpc.test.id}" | ||
} | ||
`, rName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
website/docs/r/service_discovery_private_dns_namespace.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
layout: "aws" | ||
page_title: "AWS: aws_service_discovery_private_dns_namespace" | ||
sidebar_current: "docs-aws-resource-service-discovery-private-dns-namespace" | ||
description: |- | ||
Provides a Service Discovery Private DNS Namespace resource. | ||
--- | ||
|
||
# aws_service_discovery_private_dns_namespace | ||
|
||
Provides a Service Discovery Private DNS Namespace resource. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
resource "aws_vpc" "example" { | ||
cidr_block = "10.0.0.0/16" | ||
} | ||
|
||
resource "aws_service_discovery_private_dns_namespace" "example" { | ||
name = "hoge.example.local" | ||
description = "example" | ||
vpc = "${aws_vpc.example.id}" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) The name of the namespace. | ||
* `vpc` - (Required) The ID of VPC that you want to associate the namespace with. | ||
* `description` - (Optional) The description that you specify for the namespace when you create it. | ||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `id` - The ID of a namespace. | ||
* `arn` - The ARN that Amazon Route 53 assigns to the namespace when you create it. | ||
* `hosted_zone` - The ID for the hosted zone that Amazon Route 53 creates when you create a namespace. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check shouldn't be necessary as we perform refresh prior to destroy and
Read()
would wipe the resource from state if it didn't exist.