forked from CiscoDevNet/terraform-provider-aci
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[minor_change] Add aci_cloud_ipsec_tunnel_subnet_pool, aci_cloud_exte…
…rnal_network and aci_cloud_external_network_vpn_network resources and datasources for Cloud APIC (CiscoDevNet#948)
- Loading branch information
1 parent
0150c5a
commit b1ca47f
Showing
26 changed files
with
2,531 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package aci | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/ciscoecosystem/aci-go-client/v2/client" | ||
"github.com/ciscoecosystem/aci-go-client/v2/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" | ||
) | ||
|
||
func dataSourceAciCloudTemplateforExternalNetwork() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceAciCloudTemplateforExternalNetworkRead, | ||
SchemaVersion: 1, | ||
Schema: AppendBaseAttrSchema(AppendNameAliasAttrSchema(map[string]*schema.Schema{ | ||
"hub_network_name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"vrf_dn": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"regions": { | ||
Type: schema.TypeList, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"cloud_vendor": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
"aws", | ||
"azure", | ||
"gcp", | ||
}, false), | ||
}, | ||
"router_type": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
"c8kv", | ||
"tgw", | ||
}, false), | ||
}, | ||
})), | ||
} | ||
} | ||
|
||
func dataSourceAciCloudTemplateforExternalNetworkRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
aciClient := m.(*client.Client) | ||
name := d.Get("name").(string) | ||
rn := fmt.Sprintf(models.RncloudtemplateExtNetwork, name) | ||
dn := fmt.Sprintf("%s/%s", models.CloudInfraNetworkDefaultTemplateDn, rn) | ||
log.Printf("[DEBUG] %s: Data Source - Beginning Read", dn) | ||
|
||
cloudtemplateExtNetwork, err := getRemoteCloudTemplateforExternalNetwork(aciClient, dn) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.SetId(dn) | ||
|
||
_, err = setCloudTemplateforExternalNetworkAttributes(cloudtemplateExtNetwork, d) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
log.Printf("[DEBUG] : Data Source - Begining Read of cloud Regions attributes.") | ||
regionsData, err := aciClient.ListCloudProviderandRegionNames(cloudtemplateExtNetwork.DistinguishedName) | ||
if err != nil { | ||
log.Printf("[DEBUG] : Data Source - Error while reading cloud Regions attributes %v", err) | ||
} | ||
|
||
regionsList := make([]string, 0, 1) | ||
for _, regionValue := range regionsData { | ||
|
||
regionsMap, err := setCloudProviderandRegionNamesAttributes(regionValue, make(map[string]string)) | ||
if err != nil { | ||
d.SetId("") | ||
return nil | ||
} | ||
regionsList = append(regionsList, regionsMap["region"]) | ||
d.Set("cloud_vendor", regionsMap["cloud_vendor"]) | ||
if regionsMap["cloud_vendor"] != "aws" { | ||
d.Set("router_type", "") | ||
} | ||
} | ||
log.Printf("[DEBUG] : Data Source - Read cloud regions finished successfully") | ||
d.Set("regions", regionsList) | ||
|
||
log.Printf("[DEBUG] %s: Data Source - Read finished successfully", dn) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package aci | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ciscoecosystem/aci-go-client/v2/client" | ||
"github.com/ciscoecosystem/aci-go-client/v2/models" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceAciSubnetPoolforIpSecTunnels() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceAciSubnetPoolforIpSecTunnelsRead, | ||
SchemaVersion: 1, | ||
Schema: AppendBaseAttrSchema(AppendNameAliasAttrSchema(map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"subnet_pool": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
})), | ||
} | ||
} | ||
|
||
func dataSourceAciSubnetPoolforIpSecTunnelsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
aciClient := m.(*client.Client) | ||
subnetpool := d.Get("subnet_pool").(string) | ||
rn := fmt.Sprintf(models.RncloudtemplateIpSecTunnelSubnetPool, subnetpool) | ||
dn := fmt.Sprintf("%s/%s", models.CloudInfraNetworkDefaultTemplateDn, rn) | ||
|
||
cloudtemplateIpSecTunnelSubnetPool, err := getRemoteSubnetPoolforIpSecTunnels(aciClient, dn) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.SetId(dn) | ||
|
||
_, err = setSubnetPoolforIpSecTunnelsAttributes(cloudtemplateIpSecTunnelSubnetPool, d) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package aci | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/ciscoecosystem/aci-go-client/v2/client" | ||
"github.com/ciscoecosystem/aci-go-client/v2/models" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceAciCloudTemplateforVPNNetwork() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceAciCloudTemplateforVPNNetworkRead, | ||
SchemaVersion: 1, | ||
Schema: AppendBaseAttrSchema(AppendNameAliasAttrSchema(map[string]*schema.Schema{ | ||
"aci_cloud_external_network_dn": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"remote_site_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"remote_site_name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"ipsec_tunnel": { | ||
Type: schema.TypeSet, | ||
Optional: true, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"ike_version": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"public_ip_address": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"subnet_pool_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"pre_shared_key": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"bgp_peer_asn": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"source_interfaces": { | ||
Type: schema.TypeList, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
})), | ||
} | ||
} | ||
|
||
func dataSourceAciCloudTemplateforVPNNetworkRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
aciClient := m.(*client.Client) | ||
name := d.Get("name").(string) | ||
TemplateforExternalNetworkDn := d.Get("aci_cloud_external_network_dn").(string) | ||
rn := fmt.Sprintf(models.RncloudtemplateVpnNetwork, name) | ||
dn := fmt.Sprintf("%s/%s", TemplateforExternalNetworkDn, rn) | ||
log.Printf("[DEBUG] %s: Data Source - Beginning Read", dn) | ||
|
||
cloudtemplateVpnNetwork, err := getRemoteTemplateforVPNNetwork(aciClient, dn) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.SetId(dn) | ||
|
||
_, err = setTemplateforVPNNetworkAttributes(cloudtemplateVpnNetwork, d) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
log.Printf("[DEBUG] Data Source - Begining Read of cloud IPsec Tunnel attributes.") | ||
cloudtemplateIpSecTunnelData, err := aciClient.ListCloudTemplateforIpSectunnel(dn) | ||
if err != nil { | ||
log.Printf("[DEBUG] Data Source - Error while reading cloud IPsec Tunnel attributes %v", err) | ||
} | ||
|
||
cloudtemplateIpSecTunnelSet := make([]map[string]interface{}, 0, 1) | ||
for _, cloudtemplateIpSecTunnel := range cloudtemplateIpSecTunnelData { | ||
|
||
cloudIpSecTunnelAttMap, cloudtemplateIpSecTunnelDn, err := setCloudTemplateforIpSecTunnelAttributes(cloudtemplateIpSecTunnel, make(map[string]interface{})) | ||
if err != nil { | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
log.Printf("[DEBUG] Data Source - Begining Read of cloud BGP IPV4 Peer attributes.") | ||
bgpIPv4PeerData, err := aciClient.ListCloudTemplateBGPIPv4Peer(cloudtemplateIpSecTunnelDn) | ||
if err != nil { | ||
log.Printf("[DEBUG] Data Source - Error while reading cloud BGP IPV4 Peer attributes %v", err) | ||
} | ||
for _, bgpIPv4Peer := range bgpIPv4PeerData { | ||
bgpPeerAsnAtt, err := getASNfromBGPTPV4Peer(bgpIPv4Peer, make(map[string]string)) | ||
if err != nil { | ||
d.SetId("") | ||
return nil | ||
} | ||
cloudIpSecTunnelAttMap["bgp_peer_asn"] = bgpPeerAsnAtt["bgp_peer_asn_att"] | ||
} | ||
log.Printf("[DEBUG] Data Source - Read cloud BGP IPV4 Peer finished successfully.") | ||
|
||
log.Printf("[DEBUG] Data Source - Begining Read of cloud IPsec Tunnel Source Interface attributes.") | ||
ipSectunnelSourceInterfaceData, err := aciClient.ListCloudTemplateforIpSectunnelSourceInterface(cloudtemplateIpSecTunnelDn) | ||
if err != nil { | ||
log.Printf("[DEBUG] Data Source - Error while reading cloud IPsec Tunnel Source Interface attributes %v", err) | ||
} | ||
|
||
ipSectunnelSourceInterfaceList := make([]string, 0, 1) | ||
for _, ipSecTunnelSourceInterfaceValue := range ipSectunnelSourceInterfaceData { | ||
ipSectunnelSourceInterfaceName, err := formatTemplateforIpSectunnelAttributes(ipSecTunnelSourceInterfaceValue) | ||
if err != nil { | ||
d.SetId("") | ||
return nil | ||
} | ||
ipSectunnelSourceInterfaceList = append(ipSectunnelSourceInterfaceList, ipSectunnelSourceInterfaceName) | ||
} | ||
cloudIpSecTunnelAttMap["source_interfaces"] = ipSectunnelSourceInterfaceList | ||
log.Printf("[DEBUG] : Data Source - Read cloud IPsec Tunnel Source Interface finished successfully") | ||
|
||
cloudtemplateIpSecTunnelSet = append(cloudtemplateIpSecTunnelSet, cloudIpSecTunnelAttMap) | ||
} | ||
d.Set("ipsec_tunnel", cloudtemplateIpSecTunnelSet) | ||
log.Printf("[DEBUG] Data Source - Read cloud IPsec Tunnel finished successfully.") | ||
|
||
log.Printf("[DEBUG] %s: Data Source - Read finished successfully", dn) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.