-
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 Data Source: aws_efs_mount_target #1255
Merged
grubernaut
merged 1 commit into
hashicorp:master
from
stack72:f-aws-data-source-efs-mount-1207
Jul 28, 2017
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/efs" | ||
"github.com/hashicorp/errwrap" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func dataSourceAwsEfsMountTarget() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsEfsMountTargetRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"mount_target_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"file_system_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"ip_address": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"security_groups": { | ||
Type: schema.TypeSet, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Set: schema.HashString, | ||
Computed: true, | ||
}, | ||
"subnet_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"network_interface_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"dns_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsEfsMountTargetRead(d *schema.ResourceData, meta interface{}) error { | ||
efsconn := meta.(*AWSClient).efsconn | ||
|
||
describeEfsOpts := &efs.DescribeMountTargetsInput{ | ||
MountTargetId: aws.String(d.Get("mount_target_id").(string)), | ||
} | ||
|
||
resp, err := efsconn.DescribeMountTargets(describeEfsOpts) | ||
if err != nil { | ||
return errwrap.Wrapf("Error retrieving EFS Mount Target: {{err}}", err) | ||
} | ||
if len(resp.MountTargets) != 1 { | ||
return fmt.Errorf("Search returned %d results, please revise so only one is returned", len(resp.MountTargets)) | ||
} | ||
|
||
mt := resp.MountTargets[0] | ||
|
||
log.Printf("[DEBUG] Found EFS mount target: %#v", mt) | ||
|
||
d.SetId(*mt.MountTargetId) | ||
d.Set("file_system_id", mt.FileSystemId) | ||
d.Set("ip_address", mt.IpAddress) | ||
d.Set("subnet_id", mt.SubnetId) | ||
d.Set("network_interface_id", mt.NetworkInterfaceId) | ||
|
||
sgResp, err := efsconn.DescribeMountTargetSecurityGroups(&efs.DescribeMountTargetSecurityGroupsInput{ | ||
MountTargetId: aws.String(d.Id()), | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
err = d.Set("security_groups", schema.NewSet(schema.HashString, flattenStringList(sgResp.SecurityGroups))) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := d.Set("dns_name", resourceAwsEfsMountTargetDnsName(*mt.FileSystemId, meta.(*AWSClient).region)); err != nil { | ||
return fmt.Errorf("[DEBUG] Error setting dns_name error: %#v", err) | ||
} | ||
|
||
return nil | ||
} |
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,59 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAwsEfsMountTargetByMountTargetId(t *testing.T) { | ||
rName := acctest.RandString(10) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAwsEfsMountTargetConfigByMountTargetId(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet("data.aws_efs_mount_target.by_mount_target_id", "file_system_id"), | ||
resource.TestCheckResourceAttrSet("data.aws_efs_mount_target.by_mount_target_id", "ip_address"), | ||
resource.TestCheckResourceAttrSet("data.aws_efs_mount_target.by_mount_target_id", "subnet_id"), | ||
resource.TestCheckResourceAttrSet("data.aws_efs_mount_target.by_mount_target_id", "network_interface_id"), | ||
resource.TestCheckResourceAttrSet("data.aws_efs_mount_target.by_mount_target_id", "dns_name"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccAwsEfsMountTargetConfigByMountTargetId(ct string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_efs_file_system" "foo" { | ||
creation_token = "%s" | ||
} | ||
|
||
resource "aws_efs_mount_target" "alpha" { | ||
file_system_id = "${aws_efs_file_system.foo.id}" | ||
subnet_id = "${aws_subnet.alpha.id}" | ||
} | ||
|
||
resource "aws_vpc" "foo" { | ||
cidr_block = "10.0.0.0/16" | ||
tags { | ||
Name = "testAccAWSEFSMountTargetConfig" | ||
} | ||
} | ||
|
||
resource "aws_subnet" "alpha" { | ||
vpc_id = "${aws_vpc.foo.id}" | ||
availability_zone = "us-west-2a" | ||
cidr_block = "10.0.1.0/24" | ||
} | ||
|
||
data "aws_efs_mount_target" "by_mount_target_id" { | ||
mount_target_id = "${aws_efs_mount_target.alpha.id}" | ||
} | ||
`, ct) | ||
} |
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
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
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
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,42 @@ | ||
--- | ||
layout: "aws" | ||
page_title: "AWS: efs_file_system" | ||
sidebar_current: "docs-aws-datasource-efs-file-system" | ||
description: |- | ||
Provides an Elastic File System Mount Target (EFS) data source. | ||
--- | ||
|
||
# aws_efs_file_system | ||
|
||
Provides information about an Elastic File System Mount Target (EFS). | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
variable "mount_target_id" { | ||
type = "string" | ||
default = "" | ||
} | ||
|
||
data "aws_efs_mount_target" "by_id" { | ||
mount_target_id = "${var.mount_target_id}" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `mount_target_id` - (Required) ID of the mount target that you want to have described | ||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `file_system_id` - ID of the file system for which the mount target is intended. | ||
* `subnet_id` - ID of the mount target's subnet. | ||
* `ip_address` - Address at which the file system may be mounted via the mount target. | ||
* `security_groups` - List of VPC security group IDs attached to the mount target. | ||
* `dns_name` - The DNS name for the given subnet/AZ per [documented convention](http://docs.aws.amazon.com/efs/latest/ug/mounting-fs-mount-cmd-dns-name.html). | ||
* `network_interface_id` - The ID of the network interface that Amazon EFS created when it created the mount target. | ||
|
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.
nit: use the
\
escape prior to the skids here