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

provider/aws: Export internal tunnel addresses + document #14835

Merged
merged 1 commit into from
May 31, 2017
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
56 changes: 45 additions & 11 deletions builtin/providers/aws/resource_aws_vpn_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ type XmlVpnConnectionConfig struct {
}

type XmlIpsecTunnel struct {
OutsideAddress string `xml:"vpn_gateway>tunnel_outside_address>ip_address"`
PreSharedKey string `xml:"ike>pre_shared_key"`
OutsideAddress string `xml:"vpn_gateway>tunnel_outside_address>ip_address"`
PreSharedKey string `xml:"ike>pre_shared_key"`
CgwInsideAddress string `xml:"customer_gateway>tunnel_inside_address>ip_address"`
VgwInsideAddress string `xml:"vpn_gateway>tunnel_inside_address>ip_address"`
}

type TunnelInfo struct {
Tunnel1Address string
Tunnel1PreSharedKey string
Tunnel2Address string
Tunnel2PreSharedKey string
Tunnel1Address string
Tunnel1CgwInsideAddress string
Tunnel1VgwInsideAddress string
Tunnel1PreSharedKey string
Tunnel2Address string
Tunnel2CgwInsideAddress string
Tunnel2VgwInsideAddress string
Tunnel2PreSharedKey string
}

func (slice XmlVpnConnectionConfig) Len() int {
Expand Down Expand Up @@ -96,6 +102,16 @@ func resourceAwsVpnConnection() *schema.Resource {
Computed: true,
},

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

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

"tunnel1_preshared_key": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -106,6 +122,16 @@ func resourceAwsVpnConnection() *schema.Resource {
Computed: true,
},

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

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

"tunnel2_preshared_key": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -323,9 +349,13 @@ func resourceAwsVpnConnectionRead(d *schema.ResourceData, meta interface{}) erro
log.Printf("[ERR] Error unmarshaling XML configuration for (%s): %s", d.Id(), err)
} else {
d.Set("tunnel1_address", tunnelInfo.Tunnel1Address)
d.Set("tunnel1_cgw_inside_address", tunnelInfo.Tunnel1CgwInsideAddress)
d.Set("tunnel1_vgw_inside_address", tunnelInfo.Tunnel1VgwInsideAddress)
d.Set("tunnel1_preshared_key", tunnelInfo.Tunnel1PreSharedKey)
d.Set("tunnel2_address", tunnelInfo.Tunnel2Address)
d.Set("tunnel2_preshared_key", tunnelInfo.Tunnel2PreSharedKey)
d.Set("tunnel2_cgw_inside_address", tunnelInfo.Tunnel2CgwInsideAddress)
d.Set("tunnel2_vgw_inside_address", tunnelInfo.Tunnel2VgwInsideAddress)
}
}

Expand Down Expand Up @@ -439,11 +469,15 @@ func xmlConfigToTunnelInfo(xmlConfig string) (*TunnelInfo, error) {
sort.Sort(vpnConfig)

tunnelInfo := TunnelInfo{
Tunnel1Address: vpnConfig.Tunnels[0].OutsideAddress,
Tunnel1PreSharedKey: vpnConfig.Tunnels[0].PreSharedKey,

Tunnel2Address: vpnConfig.Tunnels[1].OutsideAddress,
Tunnel2PreSharedKey: vpnConfig.Tunnels[1].PreSharedKey,
Tunnel1Address: vpnConfig.Tunnels[0].OutsideAddress,
Tunnel1PreSharedKey: vpnConfig.Tunnels[0].PreSharedKey,
Tunnel1CgwInsideAddress: vpnConfig.Tunnels[0].CgwInsideAddress,
Tunnel1VgwInsideAddress: vpnConfig.Tunnels[0].VgwInsideAddress,

Tunnel2Address: vpnConfig.Tunnels[1].OutsideAddress,
Tunnel2PreSharedKey: vpnConfig.Tunnels[1].PreSharedKey,
Tunnel2CgwInsideAddress: vpnConfig.Tunnels[1].CgwInsideAddress,
Tunnel2VgwInsideAddress: vpnConfig.Tunnels[1].VgwInsideAddress,
}

return &tunnelInfo, nil
Expand Down
46 changes: 46 additions & 0 deletions builtin/providers/aws/resource_aws_vpn_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,28 @@ func TestAWSVpnConnection_xmlconfig(t *testing.T) {
if tunnelInfo.Tunnel1Address != "FIRST_ADDRESS" {
t.Fatalf("First address from tunnel XML was incorrect.")
}
if tunnelInfo.Tunnel1CgwInsideAddress != "FIRST_CGW_INSIDE_ADDRESS" {
t.Fatalf("First Customer Gateway inside address from tunnel" +
" XML was incorrect.")
}
if tunnelInfo.Tunnel1VgwInsideAddress != "FIRST_VGW_INSIDE_ADDRESS" {
t.Fatalf("First VPN Gateway inside address from tunnel " +
" XML was incorrect.")
}
if tunnelInfo.Tunnel1PreSharedKey != "FIRST_KEY" {
t.Fatalf("First key from tunnel XML was incorrect.")
}
if tunnelInfo.Tunnel2Address != "SECOND_ADDRESS" {
t.Fatalf("Second address from tunnel XML was incorrect.")
}
if tunnelInfo.Tunnel2CgwInsideAddress != "SECOND_CGW_INSIDE_ADDRESS" {
t.Fatalf("Second Customer Gateway inside address from tunnel" +
" XML was incorrect.")
}
if tunnelInfo.Tunnel2VgwInsideAddress != "SECOND_VGW_INSIDE_ADDRESS" {
t.Fatalf("Second VPN Gateway inside address from tunnel " +
" XML was incorrect.")
}
if tunnelInfo.Tunnel2PreSharedKey != "SECOND_KEY" {
t.Fatalf("Second key from tunnel XML was incorrect.")
}
Expand Down Expand Up @@ -301,20 +317,50 @@ func testAccAwsVpnConnectionConfigUpdate(rInt, rBgpAsn int) string {
const testAccAwsVpnTunnelInfoXML = `
<vpn_connection id="vpn-abc123">
<ipsec_tunnel>
<customer_gateway>
<tunnel_outside_address>
<ip_address>123.123.123.123</ip_address>
</tunnel_outside_address>
<tunnel_inside_address>
<ip_address>SECOND_CGW_INSIDE_ADDRESS</ip_address>
<network_mask>255.255.255.252</network_mask>
<network_cidr>30</network_cidr>
</tunnel_inside_address>
</customer_gateway>
<vpn_gateway>
<tunnel_outside_address>
<ip_address>SECOND_ADDRESS</ip_address>
</tunnel_outside_address>
<tunnel_inside_address>
<ip_address>SECOND_VGW_INSIDE_ADDRESS</ip_address>
<network_mask>255.255.255.252</network_mask>
<network_cidr>30</network_cidr>
</tunnel_inside_address>
</vpn_gateway>
<ike>
<pre_shared_key>SECOND_KEY</pre_shared_key>
</ike>
</ipsec_tunnel>
<ipsec_tunnel>
<customer_gateway>
<tunnel_outside_address>
<ip_address>123.123.123.123</ip_address>
</tunnel_outside_address>
<tunnel_inside_address>
<ip_address>FIRST_CGW_INSIDE_ADDRESS</ip_address>
<network_mask>255.255.255.252</network_mask>
<network_cidr>30</network_cidr>
</tunnel_inside_address>
</customer_gateway>
<vpn_gateway>
<tunnel_outside_address>
<ip_address>FIRST_ADDRESS</ip_address>
</tunnel_outside_address>
<tunnel_inside_address>
<ip_address>FIRST_VGW_INSIDE_ADDRESS</ip_address>
<network_mask>255.255.255.252</network_mask>
<network_cidr>30</network_cidr>
</tunnel_inside_address>
</vpn_gateway>
<ike>
<pre_shared_key>FIRST_KEY</pre_shared_key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ The following attributes are exported:
* `static_routes_only` - Whether the VPN connection uses static routes exclusively.
* `tags` - Tags applied to the connection.
* `tunnel1_address` - The public IP address of the first VPN tunnel.
* `tunnel1_cgw_inside_address` - The RFC 6890 link-local address of the first VPN tunnel (Customer Gateway Side).
* `tunnel1_vgw_inside_address` - The RFC 6890 link-local address of the first VPN tunnel (VPN Gateway Side).
* `tunnel1_preshared_key` - The preshared key of the first VPN tunnel.
* `tunnel2_address` - The public IP address of the second VPN tunnel.
* `tunnel2_cgw_inside_address` - The RFC 6890 link-local address of the second VPN tunnel (Customer Gateway Side).
* `tunnel2_vgw_inside_address` - The RFC 6890 link-local address of the second VPN tunnel (VPN Gateway Side).
* `tunnel2_preshared_key` - The preshared key of the second VPN tunnel.
* `type` - The type of VPN connection.
* `vpn_gateway_id` - The ID of the virtual private gateway to which the connection is attached.
Expand Down