Skip to content

Commit

Permalink
HCCP-138 removed cidrs from tgw-attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
smaant committed May 21, 2021
1 parent 42e683b commit 9929b0a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 38 deletions.
1 change: 0 additions & 1 deletion docs/data-sources/aws_transit_gateway_attachment.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ data "hcp_aws_transit_gateway_attachment" "test" {
### Read-Only

- **created_at** (String) The time that the transit gateway attachment was created.
- **destination_cidrs** (List of String) The list of associated CIDR ranges. Traffic from these CIDRs will be allowed for all resources in the HVN. Traffic to these CIDRs will be routed into this transit gateway attachment.
- **expires_at** (String) The time after which the transit gateway attachment will be considered expired if it hasn't transitioned into `ACCEPTED` or `ACTIVE` state.
- **organization_id** (String) The ID of the HCP organization where the transit gateway attachment is located. Always matches the HVN's organization.
- **project_id** (String) The ID of the HCP project where the transit gateway attachment is located. Always matches the HVN's project.
Expand Down
9 changes: 7 additions & 2 deletions docs/resources/aws_transit_gateway_attachment.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ resource "hcp_aws_transit_gateway_attachment" "example" {
transit_gateway_attachment_id = "example-tgw-attachment"
transit_gateway_id = aws_ec2_transit_gateway.example.id
resource_share_arn = aws_ram_resource_share.example.arn
destination_cidrs = [aws_vpc.example.cidr_block]
}
resource "hcp_hvn_route" "route" {
hvn_link = hcp_hvn.main.self_link
hvn_route_id = "hvn-to-tgw-attachment"
destination_cidr = aws_vpc.example.cidr_block
target_link = hcp_aws_transit_gateway_attachment.example.self_link
}
resource "aws_ec2_transit_gateway_vpc_attachment_accepter" "example" {
Expand All @@ -75,7 +81,6 @@ resource "aws_ec2_transit_gateway_vpc_attachment_accepter" "example" {

### Required

- **destination_cidrs** (List of String) The list of associated CIDR ranges. Traffic from these CIDRs will be allowed for all resources in the HVN. Traffic to these CIDRs will be routed into this transit gateway attachment.
- **hvn_id** (String) The ID of the HashiCorp Virtual Network (HVN).
- **resource_share_arn** (String, Sensitive) The Amazon Resource Name (ARN) of the Resource Share that is needed to grant HCP access to the transit gateway in AWS. The Resource Share should be associated with the HCP AWS account principal (see [aws_ram_principal_association](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ram_principal_association)) and the transit gateway resource (see [aws_ram_resource_association](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ram_resource_association))
- **transit_gateway_attachment_id** (String) The user-settable name of the transit gateway attachment in HCP.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ resource "hcp_aws_transit_gateway_attachment" "example" {
transit_gateway_attachment_id = "example-tgw-attachment"
transit_gateway_id = aws_ec2_transit_gateway.example.id
resource_share_arn = aws_ram_resource_share.example.arn
destination_cidrs = [aws_vpc.example.cidr_block]
}

resource "hcp_hvn_route" "route" {
hvn_link = hcp_hvn.main.self_link
hvn_route_id = "hvn-to-tgw-attachment"
destination_cidr = aws_vpc.example.cidr_block
target_link = hcp_aws_transit_gateway_attachment.example.self_link
}

resource "aws_ec2_transit_gateway_vpc_attachment_accepter" "example" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ func dataSourceAwsTransitGatewayAttachment() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"destination_cidrs": {
Description: "The list of associated CIDR ranges. Traffic from these CIDRs will be allowed for all resources in the HVN. Traffic to these CIDRs will be routed into this transit gateway attachment.",
Type: schema.TypeList,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Computed: true,
},
"provider_transit_gateway_attachment_id": {
Description: "The transit gateway attachment ID used by AWS.",
Type: schema.TypeString,
Expand Down
27 changes: 1 addition & 26 deletions internal/provider/resource_aws_transit_gateway_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

"github.com/hashicorp/terraform-provider-hcp/internal/clients"
)

Expand Down Expand Up @@ -65,17 +65,6 @@ func resourceAwsTransitGatewayAttachment() *schema.Resource {
Sensitive: true,
ForceNew: true,
},
"destination_cidrs": {
Description: "The list of associated CIDR ranges. Traffic from these CIDRs will be allowed for all resources in the HVN. Traffic to these CIDRs will be routed into this transit gateway attachment.",
Type: schema.TypeList,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.IsCIDR,
},
Required: true,
MinItems: 1,
ForceNew: true,
},
// Computed outputs
"organization_id": {
Description: "The ID of the HCP organization where the transit gateway attachment is located. Always matches the HVN's organization.",
Expand Down Expand Up @@ -123,16 +112,6 @@ func resourceAwsTransitGatewayAttachmentCreate(ctx context.Context, d *schema.Re
tgwAttachmentID := d.Get("transit_gateway_attachment_id").(string)
tgwID := d.Get("transit_gateway_id").(string)
resourceShareARN := d.Get("resource_share_arn").(string)
rawCIDRs := d.Get("destination_cidrs").([]interface{})

destinationCIDRs := make([]string, len(rawCIDRs))
for i, cidr := range rawCIDRs {
strCidr, ok := cidr.(string)
if !ok {
return diag.Errorf("unable to convert cidr: %v to string", cidr)
}
destinationCIDRs[i] = strCidr
}

loc := &sharedmodels.HashicorpCloudLocationLocation{
OrganizationID: client.Config.OrganizationID,
Expand Down Expand Up @@ -169,7 +148,6 @@ func resourceAwsTransitGatewayAttachmentCreate(ctx context.Context, d *schema.Re
createTGWAttachmentParams.HvnLocationOrganizationID = loc.OrganizationID
createTGWAttachmentParams.HvnLocationProjectID = loc.ProjectID
createTGWAttachmentParams.Body = &networkmodels.HashicorpCloudNetwork20200907CreateTGWAttachmentRequest{
Cidrs: destinationCIDRs,
Hvn: &sharedmodels.HashicorpCloudLocationLink{
ID: hvnID,
Location: loc,
Expand Down Expand Up @@ -310,9 +288,6 @@ func setTransitGatewayAttachmentResourceData(d *schema.ResourceData, tgwAtt *net
if err := d.Set("transit_gateway_id", tgwAtt.ProviderData.AwsData.TgwID); err != nil {
return err
}
if err := d.Set("destination_cidrs", tgwAtt.Cidrs); err != nil {
return err
}
if err := d.Set("organization_id", tgwAtt.Location.OrganizationID); err != nil {
return err
}
Expand Down

0 comments on commit 9929b0a

Please sign in to comment.