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

add outpost_arn field to data_source_aws_ebs_volume & resource_aws_ebs_volume #12439

Merged
merged 5 commits into from
Apr 29, 2020
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
5 changes: 5 additions & 0 deletions aws/data_source_aws_ebs_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func dataSourceAwsEbsVolume() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"outpost_arn": {
Type: schema.TypeString,
Computed: true,
},
"volume_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -141,6 +145,7 @@ func volumeDescriptionAttributes(d *schema.ResourceData, client *AWSClient, volu
d.Set("size", volume.Size)
d.Set("snapshot_id", volume.SnapshotId)
d.Set("volume_type", volume.VolumeType)
d.Set("outpost_arn", volume.OutpostArn)

if err := d.Set("tags", keyvaluetags.Ec2KeyValueTags(volume.Tags).IgnoreAws().Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
Expand Down
1 change: 1 addition & 0 deletions aws/data_source_aws_ebs_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestAccAWSEbsVolumeDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttr("data.aws_ebs_volume.ebs_volume", "size", "40"),
resource.TestCheckResourceAttr("data.aws_ebs_volume.ebs_volume", "tags.%", "1"),
resource.TestCheckResourceAttr("data.aws_ebs_volume.ebs_volume", "tags.Name", "External Volume"),
resource.TestCheckResourceAttr("data.aws_ebs_volume.ebs_volume", "outpost_arn", ""),
),
},
},
Expand Down
10 changes: 10 additions & 0 deletions aws/resource_aws_ebs_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ func resourceAwsEbsVolume() *schema.Resource {
Computed: true,
ForceNew: true,
},
"outpost_arn": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validateArn,
},
"type": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -96,6 +102,9 @@ func resourceAwsEbsVolumeCreate(d *schema.ResourceData, meta interface{}) error
if value, ok := d.GetOk("snapshot_id"); ok {
request.SnapshotId = aws.String(value.(string))
}
if value, ok := d.GetOk("outpost_arn"); ok {
request.OutpostArn = aws.String(value.(string))
}

// IOPs are only valid, and required for, storage type io1. The current minimu
// is 100. Instead of a hard validation we we only apply the IOPs to the
Expand Down Expand Up @@ -264,6 +273,7 @@ func resourceAwsEbsVolumeRead(d *schema.ResourceData, meta interface{}) error {
d.Set("kms_key_id", aws.StringValue(volume.KmsKeyId))
d.Set("size", aws.Int64Value(volume.Size))
d.Set("snapshot_id", aws.StringValue(volume.SnapshotId))
d.Set("outpost_arn", aws.StringValue(volume.OutpostArn))

if err := d.Set("tags", keyvaluetags.Ec2KeyValueTags(volume.Tags).IgnoreAws().Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
Expand Down
51 changes: 51 additions & 0 deletions aws/resource_aws_ebs_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"fmt"
"log"
"os"
"regexp"
"testing"

Expand Down Expand Up @@ -87,6 +88,7 @@ func TestAccAWSEBSVolume_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "size", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "type", "gp2"),
resource.TestCheckResourceAttr(resourceName, "outpost_arn", ""),
),
},
{
Expand Down Expand Up @@ -311,6 +313,40 @@ func TestAccAWSEBSVolume_withTags(t *testing.T) {
})
}

func TestAccAWSEBSVolume_outpost(t *testing.T) {
var v ec2.Volume
resourceName := "aws_ebs_volume.test"

outpostArn := os.Getenv("AWS_OUTPOST_ARN")
if outpostArn == "" {
t.Skip(
"Environment variable AWS_OUTPOST_ARN is not set. " +
"This environment variable must be set to the ARN of " +
"a deployed Outpost to enable this test.")
}

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: resourceName,
Providers: testAccProviders,
CheckDestroy: testAccCheckVolumeDestroy,
Steps: []resource.TestStep{
{
Config: testAccAwsEbsVolumeConfigOutpost(outpostArn),
Check: resource.ComposeTestCheckFunc(
testAccCheckVolumeExists(resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "outpost_arn", outpostArn),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckVolumeDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn

Expand Down Expand Up @@ -608,3 +644,18 @@ resource "aws_ebs_volume" "test" {
}
}
`

func testAccAwsEbsVolumeConfigOutpost(outpostArn string) string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {}

resource "aws_ebs_volume" "test" {
availability_zone = "${data.aws_availability_zones.available.names[0]}"
size = 1
outpost_arn = "%s"
tags = {
Name = "tf-acc-volume-outpost"
}
}
`, outpostArn)
}
1 change: 1 addition & 0 deletions website/docs/d/ebs_volume.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ In addition to all arguments above, the following attributes are exported:
* `iops` - The amount of IOPS for the disk.
* `size` - The size of the drive in GiBs.
* `snapshot_id` - The snapshot_id the EBS volume is based off.
* `outpost_arn` - The Amazon Resource Name (ARN) of the Outpost.
* `volume_type` - The type of EBS volume.
* `kms_key_id` - The ARN for the KMS encryption key.
* `tags` - A mapping of tags for the resource.
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/ebs_volume.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The following arguments are supported:
* `iops` - (Optional) The amount of IOPS to provision for the disk.
* `size` - (Optional) The size of the drive in GiBs.
* `snapshot_id` (Optional) A snapshot to base the EBS volume off of.
* `outpost_arn` - (Optional) The Amazon Resource Name (ARN) of the Outpost.
* `type` - (Optional) The type of EBS volume. Can be "standard", "gp2", "io1", "sc1" or "st1" (Default: "gp2").
* `kms_key_id` - (Optional) The ARN for the KMS encryption key. When specifying `kms_key_id`, `encrypted` needs to be set to true.
* `tags` - (Optional) A mapping of tags to assign to the resource.
Expand Down