-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,369 additions
and
554 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM golang:1.18 AS builder | ||
FROM golang:1.22 AS builder | ||
COPY . /build | ||
WORKDIR /build | ||
RUN go mod download | ||
|
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,27 @@ | ||
# ecloud_vpn_gateway Data Source | ||
|
||
This resource represents an eCloud VPN gateway | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "ecloud_vpn_gateway" "gateway-1" { | ||
name = "example-gateway" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
- `vpn_gateway_id`: ID of VPN gateway | ||
- `name`: Name of VPN gateway | ||
- `router_id`: ID of router | ||
- `specification_id`: ID of VPN gateway specification | ||
|
||
## Attributes Reference | ||
|
||
`id` is set to VPN gateway ID | ||
|
||
- `name`: Name of VPN gateway | ||
- `router_id`: ID of router | ||
- `specification_id`: ID of VPN gateway specification | ||
- `fqdn`: Fully Qualified Domain Name for the VPN gateway |
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,23 @@ | ||
# ecloud_vpn_gateway_specification Data Source | ||
|
||
This resource represents an eCloud VPN gateway specification | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "ecloud_vpn_gateway_specification" "spec-1" { | ||
name = "Small" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
- `vpn_gateway_specification_id`: ID of VPN gateway specification | ||
- `name`: Name of VPN gateway specification | ||
|
||
## Attributes Reference | ||
|
||
`id` is set to VPN gateway specification ID | ||
|
||
- `name`: Name of VPN gateway specification | ||
- `description`: Description of VPN gateway specification |
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,26 @@ | ||
# ecloud_vpn_gateway_user Data Source | ||
|
||
This resource represents an eCloud VPN gateway user | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "ecloud_vpn_gateway_user" "user-1" { | ||
name = "example-user" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
- `vpn_gateway_user_id`: ID of VPN gateway user | ||
- `name`: Name of VPN gateway user | ||
- `vpn_gateway_id`: ID of VPN gateway | ||
- `username`: Username of VPN gateway user | ||
|
||
## Attributes Reference | ||
|
||
`id` is set to VPN gateway user ID | ||
|
||
- `name`: Name of VPN gateway user | ||
- `vpn_gateway_id`: ID of VPN gateway | ||
- `username`: Username of VPN gateway user |
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,34 @@ | ||
# ecloud_vpn_gateway Resource | ||
|
||
This resource represents an eCloud VPN gateway | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "ecloud_vpn_gateway_specification" "small" { | ||
name = "Small" | ||
} | ||
resource "ecloud_vpn_gateway" "gateway-1" { | ||
router_id = "rt-abcd1234" | ||
name = "example-gateway" | ||
specification_id = data.ecloud_vpn_gateway_specification.small.id | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `router_id` - (Required) ID of router | ||
* `name` - (Optional) Name of VPN gateway | ||
* `specification_id` - (Required) ID of VPN gateway specification | ||
|
||
**Note:** The `router_id` and `specification_id` cannot be changed once the gateway is created | ||
|
||
## Attributes Reference | ||
|
||
`id` is set to VPN gateway ID | ||
|
||
* `name` - Name of VPN gateway | ||
* `router_id` - ID of router | ||
* `specification_id` - ID of VPN gateway specification | ||
* `fqdn` - Fully Qualified Domain Name for the VPN gateway |
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,31 @@ | ||
# ecloud_vpn_gateway_user Resource | ||
|
||
This resource represents an eCloud VPN gateway user | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
resource "ecloud_vpn_gateway_user" "user-1" { | ||
vpn_gateway_id = ecloud_vpn_gateway.gateway-1.id | ||
name = "example-user" | ||
username = "vpnuser1" | ||
password = "Password123!" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `vpn_gateway_id` - (Required) ID of VPN gateway | ||
* `name` - (Required) Friendly name of VPN gateway user | ||
* `username` - (Required) Username for VPN gateway user | ||
* `password` - (Required) Password for VPN gateway user | ||
|
||
**Note:** The `vpn_gateway_id` and `username` cannot be changed once the user is created. | ||
|
||
## Attributes Reference | ||
|
||
`id` is set to VPN gateway user ID | ||
|
||
* `name` - Name of VPN gateway user | ||
* `vpn_gateway_id` - ID of VPN gateway | ||
* `username` - Username of VPN gateway user |
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,79 @@ | ||
package ecloud | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ans-group/sdk-go/pkg/connection" | ||
ecloudservice "github.com/ans-group/sdk-go/pkg/service/ecloud" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceVPNGateway() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceVPNGatewayRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"vpn_gateway_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"router_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"specification_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"fqdn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceVPNGatewayRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
service := meta.(ecloudservice.ECloudService) | ||
|
||
params := connection.APIRequestParameters{} | ||
|
||
if id, ok := d.GetOk("vpn_gateway_id"); ok { | ||
params.WithFilter(*connection.NewAPIRequestFiltering("id", connection.EQOperator, []string{id.(string)})) | ||
} | ||
if name, ok := d.GetOk("name"); ok { | ||
params.WithFilter(*connection.NewAPIRequestFiltering("name", connection.EQOperator, []string{name.(string)})) | ||
} | ||
if routerID, ok := d.GetOk("router_id"); ok { | ||
params.WithFilter(*connection.NewAPIRequestFiltering("router_id", connection.EQOperator, []string{routerID.(string)})) | ||
} | ||
if specificationID, ok := d.GetOk("specification_id"); ok { | ||
params.WithFilter(*connection.NewAPIRequestFiltering("specification_id", connection.EQOperator, []string{specificationID.(string)})) | ||
} | ||
|
||
gateways, err := service.GetVPNGateways(params) | ||
if err != nil { | ||
return diag.Errorf("Error retrieving VPN gateways: %s", err) | ||
} | ||
|
||
if len(gateways) < 1 { | ||
return diag.Errorf("No VPN gateways found with provided arguments") | ||
} | ||
|
||
if len(gateways) > 1 { | ||
return diag.Errorf("More than 1 VPN gateway found with provided arguments") | ||
} | ||
|
||
d.SetId(gateways[0].ID) | ||
d.Set("name", gateways[0].Name) | ||
d.Set("router_id", gateways[0].RouterID) | ||
d.Set("specification_id", gateways[0].SpecificationID) | ||
d.Set("fqdn", gateways[0].FQDN) | ||
|
||
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,63 @@ | ||
package ecloud | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ans-group/sdk-go/pkg/connection" | ||
ecloudservice "github.com/ans-group/sdk-go/pkg/service/ecloud" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceVPNGatewaySpecification() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceVPNGatewaySpecificationRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"vpn_gateway_specification_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceVPNGatewaySpecificationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
service := meta.(ecloudservice.ECloudService) | ||
|
||
params := connection.APIRequestParameters{} | ||
|
||
if id, ok := d.GetOk("vpn_gateway_specification_id"); ok { | ||
params.WithFilter(*connection.NewAPIRequestFiltering("id", connection.EQOperator, []string{id.(string)})) | ||
} | ||
if name, ok := d.GetOk("name"); ok { | ||
params.WithFilter(*connection.NewAPIRequestFiltering("name", connection.EQOperator, []string{name.(string)})) | ||
} | ||
|
||
specs, err := service.GetVPNGatewaySpecifications(params) | ||
if err != nil { | ||
return diag.Errorf("Error retrieving VPN gateway specifications: %s", err) | ||
} | ||
|
||
if len(specs) < 1 { | ||
return diag.Errorf("No VPN gateway specifications found with provided arguments") | ||
} | ||
|
||
if len(specs) > 1 { | ||
return diag.Errorf("More than 1 VPN gateway specification found with provided arguments") | ||
} | ||
|
||
d.SetId(specs[0].ID) | ||
d.Set("name", specs[0].Name) | ||
d.Set("description", specs[0].Description) | ||
|
||
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,34 @@ | ||
package ecloud | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceVPNGatewaySpecification_basic(t *testing.T) { | ||
config := testAccDataSourceVPNGatewaySpecificationConfig_basic("Small") | ||
resourceName := "data.ecloud_vpn_gateway_specification.test-vpngatewayspec" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(resourceName, "name", "Small"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceVPNGatewaySpecificationConfig_basic(specName string) string { | ||
return fmt.Sprintf(` | ||
data "ecloud_vpn_gateway_specification" "test-vpngatewayspec" { | ||
name = "%[1]s" | ||
} | ||
`, specName) | ||
} |
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,66 @@ | ||
package ecloud | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceVPNGateway_basic(t *testing.T) { | ||
vpnGatewayName := acctest.RandomWithPrefix("tftest") | ||
config := testAccDataSourceVPNGatewayConfig_basic(vpnGatewayName) | ||
resourceName := "data.ecloud_vpn_gateway.test-vpngateway" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(resourceName, "name", vpnGatewayName), | ||
resource.TestCheckResourceAttrSet(resourceName, "fqdn"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceVPNGatewayConfig_basic(vpnGatewayName string) string { | ||
return fmt.Sprintf(` | ||
data "ecloud_region" "test-region" { | ||
name = "Manchester" | ||
} | ||
resource "ecloud_vpc" "test-vpc" { | ||
region_id = data.ecloud_region.test-region.id | ||
name = "tftest-vpc" | ||
} | ||
data "ecloud_availability_zone" "test-az" { | ||
name = "Manchester West" | ||
} | ||
resource "ecloud_router" "test-router" { | ||
vpc_id = ecloud_vpc.test-vpc.id | ||
availability_zone_id = data.ecloud_availability_zone.test-az.id | ||
name = "tftest-router" | ||
} | ||
data "ecloud_vpn_gateway_specification" "test-spec" { | ||
name = "Small" | ||
} | ||
resource "ecloud_vpn_gateway" "test-vpngateway" { | ||
router_id = ecloud_router.test-router.id | ||
name = "%[1]s" | ||
specification_id = data.ecloud_vpn_gateway_specification.test-spec.id | ||
} | ||
data "ecloud_vpn_gateway" "test-vpngateway" { | ||
name = "%[1]s" | ||
} | ||
`, vpnGatewayName) | ||
} |
Oops, something went wrong.