-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from yunify/add-vpn-cert
Add datasource vpn cert
- Loading branch information
Showing
3 changed files
with
129 additions
and
0 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,86 @@ | ||
package qingcloud | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
qc "github.com/yunify/qingcloud-sdk-go/service" | ||
) | ||
|
||
const ( | ||
resourceVPNCertRouterId = "router_id" | ||
resourceVPNCertPlatform = "platform" | ||
resourceVPNCertClientCrt = "client_crt" | ||
resourceVPNCertClientKey = "client_key" | ||
resourceVPNCertStaticKey = "static_key" | ||
resourceVPNCertCaCert = "ca_cert" | ||
resourceVPNCertConfSample = "conf_sample" | ||
) | ||
|
||
func dataSourceQingcloudVpnCert() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceVpnCertRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
resourceVPNCertRouterId: &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
resourceVPNCertPlatform: &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "linux", | ||
ValidateFunc: withinArrayString("linux", "windows", "mac"), | ||
}, | ||
resourceVPNCertClientCrt: &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
resourceVPNCertClientKey: &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
resourceVPNCertStaticKey: &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
resourceVPNCertCaCert: &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
resourceVPNCertConfSample: &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceVpnCertRead(d *schema.ResourceData, meta interface{}) error { | ||
clt := meta.(*QingCloudClient).router | ||
input := new(qc.GetVPNCertsInput) | ||
input.Router = getSetStringPointer(d, resourceVPNCertRouterId) | ||
input.Platform = getSetStringPointer(d, resourceVPNCertPlatform) | ||
var output *qc.GetVPNCertsOutput | ||
var err error | ||
simpleRetry(func() error { | ||
output, err = clt.GetVPNCerts(input) | ||
return isServerBusy(err) | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
d.Set(resourceVPNCertClientCrt, qc.StringValue(output.ClientCrt)) | ||
d.Set(resourceVPNCertClientKey, qc.StringValue(output.ClientKey)) | ||
d.Set(resourceVPNCertStaticKey, qc.StringValue(output.StaticKey)) | ||
d.Set(resourceVPNCertCaCert, qc.StringValue(output.CaCert)) | ||
if d.Get(resourceVPNCertPlatform) == "linux" { | ||
d.Set(resourceVPNCertConfSample, qc.StringValue(output.LinuxConfSample)) | ||
} else if d.Get(resourceVPNCertPlatform) == "mac" { | ||
d.Set(resourceVPNCertConfSample, qc.StringValue(output.MacConfSample)) | ||
} else { | ||
d.Set(resourceVPNCertConfSample, qc.StringValue(output.WindowsConfSample)) | ||
} | ||
d.SetId(time.Now().UTC().String()) | ||
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
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,40 @@ | ||
--- | ||
layout: "qingcloud" | ||
page_title: "Qingcloud: qingcloud_vpn_cert" | ||
sidebar_current: "docs-qingcloud-datasource-vpn-cert" | ||
description: |- | ||
Provides vpn cert of vpc/router.. | ||
--- | ||
|
||
# qingcloud\_vpn\_cert | ||
|
||
The vpn cert data source get the certs info of vpc/router | ||
|
||
## Example Usage | ||
|
||
``` | ||
data "qingcloud_vpn_cert" "test"{ | ||
router_id = "xxx" | ||
platform = "linux" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `router_id` - (Required) vpc/router id. | ||
* `platform` - (Optional, Default:linux)Validate value:"linux","mac","windows" VPN's conf sample's platform. | ||
|
||
## Attributes Reference | ||
|
||
|
||
* `router_id` - vpc/router id. | ||
* `platform` - Validate value:"linux","mac","windows" VPN's conf sample's platform. | ||
* `client_crt` - Client certificate content. | ||
* `client_key` - The client certificate private key content. | ||
* `static_key` - vpn encrypt private key content. | ||
* `ca_cert` - vpn trust certificate content. | ||
* `conf_sample` - Sample configuration file content. |