-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
wireguard_preshared_key
resource (#7)
Closes #6.
- Loading branch information
Showing
8 changed files
with
110 additions
and
2 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
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,37 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "wireguard_preshared_key Resource - terraform-provider-wireguard" | ||
subcategory: "" | ||
description: |- | ||
Provides a WireGuard key resource. This can be used to create, read, and delete WireGuard preshared keys in terraform state. | ||
--- | ||
|
||
# wireguard_preshared_key (Resource) | ||
|
||
Provides a WireGuard key resource. This can be used to create, read, and delete WireGuard preshared keys in terraform state. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "wireguard_preshared_key" "example" { | ||
} | ||
output "wg_preshared_key" { | ||
description = "Example's preshared WireGuard key" | ||
value = wireguard_preshared_key.example.key | ||
sensitive = true | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Optional | ||
|
||
- **id** (String) The ID of this resource. | ||
|
||
### Read-Only | ||
|
||
- **key** (String, Sensitive) Additional layer of symmetric-key cryptography to be mixed into the already existing public-key cryptography, for post-quantum resistance. | ||
|
||
|
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
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,8 @@ | ||
resource "wireguard_preshared_key" "example" { | ||
} | ||
|
||
output "wg_preshared_key" { | ||
description = "Example's preshared WireGuard key" | ||
value = wireguard_preshared_key.example.key | ||
sensitive = true | ||
} |
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,7 @@ | ||
terraform { | ||
required_providers { | ||
wireguard = { | ||
source = "OJFord/wireguard" | ||
} | ||
} | ||
} |
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,51 @@ | ||
package provider | ||
|
||
import ( | ||
"crypto/sha256" | ||
"encoding/hex" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes" | ||
) | ||
|
||
func resourceWireguardPresharedKey() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Provides a WireGuard key resource. This can be used to create, read, and delete WireGuard preshared keys in terraform state.", | ||
|
||
Create: resourceWireguardPresharedKeyCreate, | ||
Read: resourceWireguardPresharedKeyRead, | ||
Delete: resourceWireguardPresharedKeyDelete, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"key": { | ||
Description: "Additional layer of symmetric-key cryptography to be mixed into the already existing public-key cryptography, for post-quantum resistance.", | ||
Computed: true, | ||
Sensitive: true, | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceWireguardPresharedKeyCreate(d *schema.ResourceData, m interface{}) error { | ||
var key wgtypes.Key | ||
var err error | ||
|
||
key, err = wgtypes.GenerateKey() | ||
err = d.Set("key", key.String()) | ||
if err != nil { | ||
return err | ||
} | ||
hash := sha256.Sum256([]byte(key.String())) | ||
d.SetId(hex.EncodeToString(hash[:])) | ||
|
||
return nil | ||
} | ||
|
||
func resourceWireguardPresharedKeyRead(d *schema.ResourceData, m interface{}) error { | ||
return nil | ||
} | ||
|
||
func resourceWireguardPresharedKeyDelete(d *schema.ResourceData, m interface{}) error { | ||
d.SetId("") | ||
return nil | ||
} |