|
| 1 | +/* |
| 2 | +Provides a resource to create a vpc vpn_customer_gateway_configuration_download |
| 3 | +
|
| 4 | +Example Usage |
| 5 | +
|
| 6 | +```hcl |
| 7 | +resource "tencentcloud_vpn_customer_gateway_configuration_download" "vpn_customer_gateway_configuration_download" { |
| 8 | + vpn_gateway_id = "vpngw-gt8bianl" |
| 9 | + vpn_connection_id = "vpnx-kme2tx8m" |
| 10 | + customer_gateway_vendor { |
| 11 | + platform = "comware" |
| 12 | + software_version = "V1.0" |
| 13 | + vendor_name = "h3c" |
| 14 | + } |
| 15 | + interface_name = "test" |
| 16 | +} |
| 17 | +``` |
| 18 | +*/ |
| 19 | +package tencentcloud |
| 20 | + |
| 21 | +import ( |
| 22 | + "log" |
| 23 | + |
| 24 | + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" |
| 25 | + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" |
| 26 | + vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312" |
| 27 | + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" |
| 28 | +) |
| 29 | + |
| 30 | +func resourceTencentCloudVpnCustomerGatewayConfigurationDownload() *schema.Resource { |
| 31 | + return &schema.Resource{ |
| 32 | + Create: resourceTencentCloudVpnCustomerGatewayConfigurationDownloadCreate, |
| 33 | + Read: resourceTencentCloudVpnCustomerGatewayConfigurationDownloadRead, |
| 34 | + Delete: resourceTencentCloudVpnCustomerGatewayConfigurationDownloadDelete, |
| 35 | + Importer: &schema.ResourceImporter{ |
| 36 | + State: schema.ImportStatePassthrough, |
| 37 | + }, |
| 38 | + Schema: map[string]*schema.Schema{ |
| 39 | + "vpn_gateway_id": { |
| 40 | + Required: true, |
| 41 | + ForceNew: true, |
| 42 | + Type: schema.TypeString, |
| 43 | + Description: "VPN Gateway Instance ID.", |
| 44 | + }, |
| 45 | + |
| 46 | + "vpn_connection_id": { |
| 47 | + Required: true, |
| 48 | + ForceNew: true, |
| 49 | + Type: schema.TypeString, |
| 50 | + Description: "VPN Connection Instance id.", |
| 51 | + }, |
| 52 | + |
| 53 | + "customer_gateway_vendor": { |
| 54 | + Required: true, |
| 55 | + ForceNew: true, |
| 56 | + Type: schema.TypeList, |
| 57 | + MaxItems: 1, |
| 58 | + Description: "Customer Gateway Vendor Info.", |
| 59 | + Elem: &schema.Resource{ |
| 60 | + Schema: map[string]*schema.Schema{ |
| 61 | + "platform": { |
| 62 | + Type: schema.TypeString, |
| 63 | + Required: true, |
| 64 | + Description: "Platform.", |
| 65 | + }, |
| 66 | + "software_version": { |
| 67 | + Type: schema.TypeString, |
| 68 | + Required: true, |
| 69 | + Description: "SoftwareVersion.", |
| 70 | + }, |
| 71 | + "vendor_name": { |
| 72 | + Type: schema.TypeString, |
| 73 | + Required: true, |
| 74 | + Description: "VendorName.", |
| 75 | + }, |
| 76 | + }, |
| 77 | + }, |
| 78 | + }, |
| 79 | + |
| 80 | + "interface_name": { |
| 81 | + Required: true, |
| 82 | + ForceNew: true, |
| 83 | + Type: schema.TypeString, |
| 84 | + Description: "VPN connection access device physical interface name.", |
| 85 | + }, |
| 86 | + |
| 87 | + "customer_gateway_configuration": { |
| 88 | + Computed: true, |
| 89 | + Type: schema.TypeString, |
| 90 | + Description: "xml configuration.", |
| 91 | + }, |
| 92 | + }, |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +func resourceTencentCloudVpnCustomerGatewayConfigurationDownloadCreate(d *schema.ResourceData, meta interface{}) error { |
| 97 | + defer logElapsed("data_source.tencentcloud_vpn_customer_gateway_configuration_download.read")() |
| 98 | + defer inconsistentCheck(d, meta)() |
| 99 | + |
| 100 | + logId := getLogId(contextNil) |
| 101 | + |
| 102 | + var ( |
| 103 | + request = vpc.NewDownloadCustomerGatewayConfigurationRequest() |
| 104 | + response = vpc.NewDownloadCustomerGatewayConfigurationResponse() |
| 105 | + vpnGatewayId string |
| 106 | + vpnConnectionId string |
| 107 | + ) |
| 108 | + if v, ok := d.GetOk("vpn_gateway_id"); ok { |
| 109 | + vpnGatewayId = v.(string) |
| 110 | + request.VpnGatewayId = helper.String(v.(string)) |
| 111 | + } |
| 112 | + |
| 113 | + if v, ok := d.GetOk("vpn_connection_id"); ok { |
| 114 | + vpnConnectionId = v.(string) |
| 115 | + request.VpnConnectionId = helper.String(v.(string)) |
| 116 | + } |
| 117 | + |
| 118 | + if dMap, ok := helper.InterfacesHeadMap(d, "customer_gateway_vendor"); ok { |
| 119 | + customerGatewayVendor := vpc.CustomerGatewayVendor{} |
| 120 | + if v, ok := dMap["platform"]; ok { |
| 121 | + customerGatewayVendor.Platform = helper.String(v.(string)) |
| 122 | + } |
| 123 | + if v, ok := dMap["software_version"]; ok { |
| 124 | + customerGatewayVendor.SoftwareVersion = helper.String(v.(string)) |
| 125 | + } |
| 126 | + if v, ok := dMap["vendor_name"]; ok { |
| 127 | + customerGatewayVendor.VendorName = helper.String(v.(string)) |
| 128 | + } |
| 129 | + request.CustomerGatewayVendor = &customerGatewayVendor |
| 130 | + } |
| 131 | + |
| 132 | + if v, ok := d.GetOk("interface_name"); ok { |
| 133 | + request.InterfaceName = helper.String(v.(string)) |
| 134 | + } |
| 135 | + |
| 136 | + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { |
| 137 | + result, e := meta.(*TencentCloudClient).apiV3Conn.UseVpcClient().DownloadCustomerGatewayConfiguration(request) |
| 138 | + if e != nil { |
| 139 | + return retryError(e) |
| 140 | + } else { |
| 141 | + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) |
| 142 | + } |
| 143 | + response = result |
| 144 | + return nil |
| 145 | + }) |
| 146 | + if err != nil { |
| 147 | + log.Printf("[CRITAL]%s operate vpc vpnCustomerGatewayConfigurationDownload failed, reason:%+v", logId, err) |
| 148 | + return nil |
| 149 | + } |
| 150 | + |
| 151 | + d.SetId(vpnGatewayId + FILED_SP + vpnConnectionId) |
| 152 | + |
| 153 | + d.Set("customer_gateway_configuration", response.Response.CustomerGatewayConfiguration) |
| 154 | + |
| 155 | + return resourceTencentCloudVpnCustomerGatewayConfigurationDownloadRead(d, meta) |
| 156 | +} |
| 157 | + |
| 158 | +func resourceTencentCloudVpnCustomerGatewayConfigurationDownloadRead(d *schema.ResourceData, meta interface{}) error { |
| 159 | + defer logElapsed("resource.tencentcloud_vpn_customer_gateway_configuration_download.read")() |
| 160 | + defer inconsistentCheck(d, meta)() |
| 161 | + |
| 162 | + return nil |
| 163 | +} |
| 164 | + |
| 165 | +func resourceTencentCloudVpnCustomerGatewayConfigurationDownloadDelete(d *schema.ResourceData, meta interface{}) error { |
| 166 | + defer logElapsed("resource.tencentcloud_vpn_customer_gateway_configuration_download.delete")() |
| 167 | + defer inconsistentCheck(d, meta)() |
| 168 | + |
| 169 | + return nil |
| 170 | +} |
0 commit comments