Skip to content

Commit

Permalink
Merge pull request #134 from yunify/add-vpn-cert
Browse files Browse the repository at this point in the history
Add datasource vpn cert
  • Loading branch information
runzexia authored Jan 10, 2018
2 parents 1c9c9dd + b579d6f commit 401930e
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
86 changes: 86 additions & 0 deletions qingcloud/data_source_qingcloud_vpn_cert.go
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
}
3 changes: 3 additions & 0 deletions qingcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func Provider() terraform.ResourceProvider {
Description: descriptions["endpoint"],
},
},
DataSourcesMap: map[string]*schema.Resource{
"qingcloud_vpn_cert": dataSourceQingcloudVpnCert(),
},
ResourcesMap: map[string]*schema.Resource{
"qingcloud_eip": resourceQingcloudEip(),
"qingcloud_keypair": resourceQingcloudKeypair(),
Expand Down
40 changes: 40 additions & 0 deletions website/docs/d/vpn_cert.html.markdown
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.

0 comments on commit 401930e

Please sign in to comment.