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

aws_vpc: Add arn as an attribute for aws_vpc #5300

Merged
merged 1 commit into from
Jul 23, 2018
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
15 changes: 15 additions & 0 deletions aws/data_source_aws_vpc.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/ec2"
"github.com/hashicorp/terraform/helper/schema"
)
Expand Down Expand Up @@ -92,6 +93,11 @@ func dataSourceAwsVpc() *schema.Resource {
Computed: true,
},

"arn": {
Type: schema.TypeString,
Computed: true,
},

"tags": tagsSchemaComputed(),
},
}
Expand Down Expand Up @@ -162,6 +168,15 @@ func dataSourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error {
d.Set("state", vpc.State)
d.Set("tags", tagsToMap(vpc.Tags))

arn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Service: "ec2",
Region: meta.(*AWSClient).region,
AccountID: meta.(*AWSClient).accountid,
Resource: fmt.Sprintf("vpc/%s", d.Id()),
}.String()
d.Set("arn", arn)

cidrAssociations := []interface{}{}
for _, associationSet := range vpc.CidrBlockAssociationSet {
association := map[string]interface{}{
Expand Down
2 changes: 2 additions & 0 deletions aws/data_source_aws_vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func TestAccDataSourceAwsVpc_basic(t *testing.T) {
"data.aws_vpc.by_id", "enable_dns_support", "true"),
resource.TestCheckResourceAttr(
"data.aws_vpc.by_id", "enable_dns_hostnames", "false"),
resource.TestCheckResourceAttrSet(
"data.aws_vpc.by_id", "arn"),
),
},
},
Expand Down
2 changes: 2 additions & 0 deletions aws/resource_aws_default_vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func TestAccAWSDefaultVpc_basic(t *testing.T) {
"aws_default_vpc.foo", "tags.%", "1"),
resource.TestCheckResourceAttr(
"aws_default_vpc.foo", "tags.Name", "Default VPC"),
resource.TestCheckResourceAttrSet(
"aws_default_vpc.foo", "arn"),
resource.TestCheckNoResourceAttr(
"aws_default_vpc.foo", "assign_generated_ipv6_cidr_block"),
resource.TestCheckNoResourceAttr(
Expand Down
16 changes: 16 additions & 0 deletions aws/resource_aws_vpc.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/hashicorp/terraform/helper/resource"
Expand Down Expand Up @@ -107,6 +108,11 @@ func resourceAwsVpc() *schema.Resource {
Computed: true,
},

"arn": {
Type: schema.TypeString,
Computed: true,
},

"tags": tagsSchema(),
},
}
Expand Down Expand Up @@ -177,6 +183,16 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error {
d.Set("dhcp_options_id", vpc.DhcpOptionsId)
d.Set("instance_tenancy", vpc.InstanceTenancy)

// ARN
arn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Service: "ec2",
Region: meta.(*AWSClient).region,
AccountID: meta.(*AWSClient).accountid,
Resource: fmt.Sprintf("vpc/%s", d.Id()),
}.String()
d.Set("arn", arn)

// Tags
d.Set("tags", tagsToMap(vpc.Tags))

Expand Down
2 changes: 2 additions & 0 deletions aws/resource_aws_vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func TestAccAWSVpc_basic(t *testing.T) {
"aws_vpc.foo", "default_route_table_id"),
resource.TestCheckResourceAttr(
"aws_vpc.foo", "enable_dns_support", "true"),
resource.TestCheckResourceAttrSet(
"aws_vpc.foo", "arn"),
),
},
},
Expand Down