Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/goreleaser/gorelea…
Browse files Browse the repository at this point in the history
…ser-action-6.0.0
  • Loading branch information
arslanbekov authored Aug 29, 2024
2 parents 2dc87b6 + 774da22 commit 18dda96
Show file tree
Hide file tree
Showing 33 changed files with 424 additions and 321 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ jobs:
cache: true

- name: golangci-lint
uses: golangci/golangci-lint-action@v6.0.1
uses: golangci/golangci-lint-action@v6.1.0
with:
version: v1.55.2
104 changes: 0 additions & 104 deletions client/client_test.go

This file was deleted.

4 changes: 4 additions & 0 deletions cloudconnexa/data_source_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ func dataSourceApplication() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceApplicationRead,
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
Expand Down
27 changes: 22 additions & 5 deletions cloudconnexa/data_source_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package cloudconnexa

import (
"context"
"strconv"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa"
Expand All @@ -15,6 +12,10 @@ func dataSourceConnector() *schema.Resource {
Description: "Use an `cloudconnexa_connector` data source to read an existing CloudConnexa connector.",
ReadContext: dataSourceConnectorRead,
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -55,29 +56,45 @@ func dataSourceConnector() *schema.Resource {
Computed: true,
Description: "OpenVPN profile",
},
"token": {
Type: schema.TypeString,
Computed: true,
Description: "Connector token",
},
},
}
}

func dataSourceConnectorRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*cloudconnexa.Client)
var diags diag.Diagnostics
connector, err := c.Connectors.GetByName(d.Get("name").(string))
name := d.Get("name").(string)
connector, err := c.Connectors.GetByName(name)
if err != nil {
return append(diags, diag.FromErr(err)...)
}
if connector == nil {
return append(diags, diag.Errorf("Connector with name %s was not found", name)...)
}
token, err := c.Connectors.GetToken(connector.Id)
if err != nil {
return append(diags, diag.FromErr(err)...)
}

d.SetId(connector.Id)
d.Set("name", connector.Name)
d.Set("description", connector.Description)
d.Set("network_item_id", connector.NetworkItemId)
d.Set("network_item_type", connector.NetworkItemType)
d.Set("vpn_region_id", connector.VpnRegionId)
d.Set("ip_v4_address", connector.IPv4Address)
d.Set("ip_v6_address", connector.IPv6Address)
d.Set("token", token)

profile, err := c.Connectors.GetProfile(connector.Id)
if err != nil {
return append(diags, diag.FromErr(err)...)
}
d.Set("profile", profile)
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
return diags
}
32 changes: 25 additions & 7 deletions cloudconnexa/data_source_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package cloudconnexa

import (
"context"
"strconv"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa"
Expand All @@ -15,7 +12,7 @@ func dataSourceHost() *schema.Resource {
Description: "Use an `cloudconnexa_host` data source to read an existing CloudConnexa connector.",
ReadContext: dataSourceHostRead,
Schema: map[string]*schema.Schema{
"host_id": {
"id": {
Type: schema.TypeString,
Computed: true,
Description: "The host ID.",
Expand All @@ -25,6 +22,16 @@ func dataSourceHost() *schema.Resource {
Required: true,
Description: "The name of the host.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "The description of the host.",
},
"domain": {
Type: schema.TypeString,
Computed: true,
Description: "The host domain.",
},
"internet_access": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -54,6 +61,11 @@ func dataSourceHost() *schema.Resource {
Computed: true,
Description: "The connector name.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "The connector description.",
},
"network_item_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -89,16 +101,22 @@ func dataSourceHost() *schema.Resource {
func dataSourceHostRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*cloudconnexa.Client)
var diags diag.Diagnostics
host, err := c.Hosts.GetByName(d.Get("name").(string))
name := d.Get("name").(string)
host, err := c.Hosts.GetByName(name)
if err != nil {
return append(diags, diag.FromErr(err)...)
}
d.Set("host_id", host.Id)
if host == nil {
return append(diags, diag.Errorf("Host with name %s was not found", name)...)
}

d.SetId(host.Id)
d.Set("name", host.Name)
d.Set("description", host.Description)
d.Set("domain", host.Domain)
d.Set("internet_access", host.InternetAccess)
d.Set("system_subnets", host.SystemSubnets)
d.Set("connectors", getConnectorsSliceByConnectors(&host.Connectors))
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
return diags
}

Expand Down
19 changes: 13 additions & 6 deletions cloudconnexa/data_source_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package cloudconnexa

import (
"context"
"strconv"
"time"

"github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand All @@ -16,7 +13,7 @@ func dataSourceNetwork() *schema.Resource {
Description: "Use a `cloudconnexa_network` data source to read an CloudConnexa network.",
ReadContext: dataSourceNetworkRead,
Schema: map[string]*schema.Schema{
"network_id": {
"id": {
Type: schema.TypeString,
Computed: true,
Description: "The network ID.",
Expand All @@ -26,6 +23,11 @@ func dataSourceNetwork() *schema.Resource {
Required: true,
Description: "The network name.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "The description of the network.",
},
"egress": {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -65,6 +67,11 @@ func dataSourceNetwork() *schema.Resource {
Computed: true,
Description: "The value of the route, either an IPV4 address, an IPV6 address, or a DNS hostname.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "The description of the route.",
},
},
},
},
Expand Down Expand Up @@ -132,15 +139,14 @@ func dataSourceNetworkRead(ctx context.Context, d *schema.ResourceData, m interf
if network == nil {
return append(diags, diag.Errorf("Network with name %s was not found", networkName)...)
}
d.Set("network_id", network.Id)
d.SetId(network.Id)
d.Set("name", network.Name)
d.Set("description", network.Description)
d.Set("egress", network.Egress)
d.Set("internet_access", network.InternetAccess)
d.Set("system_subnets", network.SystemSubnets)
d.Set("routes", getRoutesSlice(&network.Routes))
d.Set("connectors", getConnectorsSliceByNetworkConnectors(&network.Connectors))
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
return diags
}

Expand All @@ -151,6 +157,7 @@ func getRoutesSlice(networkRoutes *[]cloudconnexa.Route) []interface{} {
route["id"] = r.Id
route["subnet"] = r.Subnet
route["type"] = r.Type
route["description"] = r.Description
routes[i] = route
}
return routes
Expand Down
7 changes: 2 additions & 5 deletions cloudconnexa/data_source_network_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package cloudconnexa

import (
"context"
"strconv"
"time"

"github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand All @@ -16,7 +13,7 @@ func dataSourceNetworkRoutes() *schema.Resource {
Description: "Use an `cloudconnexa_network_routes` data source to read all the routes associated with an CloudConnexa network.",
ReadContext: dataSourceNetworkRoutesRead,
Schema: map[string]*schema.Schema{
"network_item_id": {
"id": {
Type: schema.TypeString,
Required: true,
Description: "The id of the CloudConnexa network of the routes to be discovered.",
Expand Down Expand Up @@ -77,7 +74,7 @@ func dataSourceNetworkRoutesRead(ctx context.Context, d *schema.ResourceData, m
if err := d.Set("routes", configRoutes); err != nil {
return append(diags, diag.FromErr(err)...)
}
d.SetId(networkId)

d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
return diags
}
Loading

0 comments on commit 18dda96

Please sign in to comment.