Skip to content

Commit

Permalink
Merge pull request #6371 from terraform-providers/f-efs-file-system-arn
Browse files Browse the repository at this point in the history
service/efs: Add File System ARN attributes
  • Loading branch information
bflad authored Nov 6, 2018
2 parents 1040c9f + c558397 commit 8a3ff81
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 1 deletion.
15 changes: 15 additions & 0 deletions aws/data_source_aws_efs_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/efs"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
Expand All @@ -15,6 +16,10 @@ func dataSourceAwsEfsFileSystem() *schema.Resource {
Read: dataSourceAwsEfsFileSystemRead,

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"creation_token": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -120,6 +125,16 @@ func dataSourceAwsEfsFileSystemRead(d *schema.ResourceData, meta interface{}) er

d.Set("creation_token", fs.CreationToken)
d.Set("performance_mode", fs.PerformanceMode)

fsARN := arn.ARN{
AccountID: meta.(*AWSClient).accountid,
Partition: meta.(*AWSClient).partition,
Region: meta.(*AWSClient).region,
Resource: fmt.Sprintf("file-system/%s", aws.StringValue(fs.FileSystemId)),
Service: "elasticfilesystem",
}.String()

d.Set("arn", fsARN)
d.Set("file_system_id", fs.FileSystemId)
d.Set("encrypted", fs.Encrypted)
d.Set("kms_key_id", fs.KmsKeyId)
Expand Down
1 change: 1 addition & 0 deletions aws/data_source_aws_efs_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func TestAccDataSourceAwsEfsFileSystem(t *testing.T) {
{
Config: testAccDataSourceAwsEfsFileSystemConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair("data.aws_efs_file_system.by_id", "arn", "aws_efs_file_system.test", "arn"),
testAccDataSourceAwsEfsFileSystemCheck("data.aws_efs_file_system.by_creation_token"),
testAccDataSourceAwsEfsFileSystemCheck("data.aws_efs_file_system.by_id"),
resource.TestMatchResourceAttr("data.aws_efs_file_system.by_creation_token", "dns_name", regexp.MustCompile("^[^.]+.efs.([a-z]{2}-(gov-)?[a-z]+-\\d{1})?.amazonaws.com$")),
Expand Down
16 changes: 15 additions & 1 deletion aws/data_source_aws_efs_mount_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/efs"
"github.com/hashicorp/terraform/helper/schema"
)
Expand All @@ -19,7 +20,10 @@ func dataSourceAwsEfsMountTarget() *schema.Resource {
Required: true,
ForceNew: true,
},

"file_system_arn": {
Type: schema.TypeString,
Computed: true,
},
"file_system_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -71,6 +75,16 @@ func dataSourceAwsEfsMountTargetRead(d *schema.ResourceData, meta interface{}) e
log.Printf("[DEBUG] Found EFS mount target: %#v", mt)

d.SetId(*mt.MountTargetId)

fsARN := arn.ARN{
AccountID: meta.(*AWSClient).accountid,
Partition: meta.(*AWSClient).partition,
Region: meta.(*AWSClient).region,
Resource: fmt.Sprintf("file-system/%s", aws.StringValue(mt.FileSystemId)),
Service: "elasticfilesystem",
}.String()

d.Set("file_system_arn", fsARN)
d.Set("file_system_id", mt.FileSystemId)
d.Set("ip_address", mt.IpAddress)
d.Set("subnet_id", mt.SubnetId)
Expand Down
1 change: 1 addition & 0 deletions aws/data_source_aws_efs_mount_target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func TestAccDataSourceAwsEfsMountTargetByMountTargetId(t *testing.T) {
{
Config: testAccAwsEfsMountTargetConfigByMountTargetId(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair("data.aws_efs_mount_target.by_mount_target_id", "file_system_arn", "aws_efs_mount_target.alpha", "file_system_arn"),
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"),
Expand Down
14 changes: 14 additions & 0 deletions aws/resource_aws_efs_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/efs"
"github.com/hashicorp/terraform/helper/resource"
Expand All @@ -26,6 +27,10 @@ func resourceAwsEfsFileSystem() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"creation_token": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -279,6 +284,15 @@ func resourceAwsEfsFileSystemRead(d *schema.ResourceData, meta interface{}) erro
return nil
}

fsARN := arn.ARN{
AccountID: meta.(*AWSClient).accountid,
Partition: meta.(*AWSClient).partition,
Region: meta.(*AWSClient).region,
Resource: fmt.Sprintf("file-system/%s", aws.StringValue(fs.FileSystemId)),
Service: "elasticfilesystem",
}.String()

d.Set("arn", fsARN)
d.Set("creation_token", fs.CreationToken)
d.Set("encrypted", fs.Encrypted)
d.Set("kms_key_id", fs.KmsKeyId)
Expand Down
1 change: 1 addition & 0 deletions aws/resource_aws_efs_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func TestAccAWSEFSFileSystem_basic(t *testing.T) {
{
Config: testAccAWSEFSFileSystemConfig,
Check: resource.ComposeTestCheckFunc(
testAccMatchResourceAttrRegionalARN("aws_efs_file_system.foo", "arn", "elasticfilesystem", regexp.MustCompile(`file-system/fs-.+`)),
resource.TestCheckResourceAttr(
"aws_efs_file_system.foo",
"performance_mode",
Expand Down
15 changes: 15 additions & 0 deletions aws/resource_aws_efs_mount_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/efs"
Expand All @@ -25,6 +26,10 @@ func resourceAwsEfsMountTarget() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"file_system_arn": {
Type: schema.TypeString,
Computed: true,
},
"file_system_id": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -182,6 +187,16 @@ func resourceAwsEfsMountTargetRead(d *schema.ResourceData, meta interface{}) err
log.Printf("[DEBUG] Found EFS mount target: %#v", mt)

d.SetId(*mt.MountTargetId)

fsARN := arn.ARN{
AccountID: meta.(*AWSClient).accountid,
Partition: meta.(*AWSClient).partition,
Region: meta.(*AWSClient).region,
Resource: fmt.Sprintf("file-system/%s", aws.StringValue(mt.FileSystemId)),
Service: "elasticfilesystem",
}.String()

d.Set("file_system_arn", fsARN)
d.Set("file_system_id", mt.FileSystemId)
d.Set("ip_address", mt.IpAddress)
d.Set("subnet_id", mt.SubnetId)
Expand Down
1 change: 1 addition & 0 deletions aws/resource_aws_efs_mount_target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestAccAWSEFSMountTarget_basic(t *testing.T) {
{
Config: testAccAWSEFSMountTargetConfig(ct),
Check: resource.ComposeTestCheckFunc(
testAccMatchResourceAttrRegionalARN("aws_efs_mount_target.alpha", "file_system_arn", "elasticfilesystem", regexp.MustCompile(`file-system/fs-.+`)),
testAccCheckEfsMountTarget(
"aws_efs_mount_target.alpha",
&mount,
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/efs_file_system.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The following arguments are supported:

In addition to all arguments above, the following attributes are exported:

* `arn` - Amazon Resource Name of the file system.
* `performance_mode` - The PerformanceMode of the file system.
* `tags` - The list of tags assigned to the file system.
* `encrypted` - Whether EFS is encrypted.
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/efs_mount_target.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The following arguments are supported:

In addition to all arguments above, the following attributes are exported:

* `file_system_arn` - Amazon Resource Name of the file system for which the mount target is intended.
* `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.
Expand Down
4 changes: 4 additions & 0 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ In addition to [generic `provider` arguments](https://www.terraform.io/docs/conf
- [`aws_ebs_volume` data source](/docs/providers/aws/d/ebs_volume.html)
- [`aws_ecs_cluster` resource (import)](/docs/providers/aws/r/ecs_cluster.html)
- [`aws_ecs_service` resource (import)](/docs/providers/aws/r/ecs_service.html)
- [`aws_efs_file_system` data source](/docs/providers/aws/d/efs_file_system.html)
- [`aws_efs_file_system` resource](/docs/providers/aws/r/efs_file_system.html)
- [`aws_efs_mount_target` data source](/docs/providers/aws/d/efs_mount_target.html)
- [`aws_efs_mount_target` resource](/docs/providers/aws/r/efs_mount_target.html)
- [`aws_elasticache_cluster` data source](/docs/providers/aws/d/elasticache_cluster.html)
- [`aws_elasticache_cluster` resource](/docs/providers/aws/r/elasticache_cluster.html)
- [`aws_elb` resource](/docs/providers/aws/r/elb.html)
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/efs_file_system.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ default generated by Terraform.

In addition to all arguments above, the following attributes are exported:

* `arn` - Amazon Resource Name of the file system.
* `id` - The ID that identifies the file system (e.g. fs-ccfc0d65).
* `dns_name` - The DNS name for the filesystem per [documented convention](http://docs.aws.amazon.com/efs/latest/ug/mounting-fs-mount-cmd-dns-name.html).

Expand Down
1 change: 1 addition & 0 deletions website/docs/r/efs_mount_target.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ In addition to all arguments above, the following attributes are exported:

* `id` - The ID of 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).
* `file_system_arn` - Amazon Resource Name of the file system.
* `network_interface_id` - The ID of the network interface that Amazon EFS created when it created the mount target.

## Import
Expand Down

0 comments on commit 8a3ff81

Please sign in to comment.