Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed id referencing in datasources #26

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 5 additions & 4 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 @@ -66,6 +67,7 @@ func dataSourceConnectorRead(ctx context.Context, d *schema.ResourceData, m inte
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)
Expand All @@ -78,6 +80,5 @@ func dataSourceConnectorRead(ctx context.Context, d *schema.ResourceData, m inte
return append(diags, diag.FromErr(err)...)
}
d.Set("profile", profile)
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
return diags
}
8 changes: 2 additions & 6 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 Down Expand Up @@ -108,14 +105,13 @@ func dataSourceHostRead(ctx context.Context, d *schema.ResourceData, m interface
if err != nil {
return append(diags, diag.FromErr(err)...)
}
d.Set("host_id", host.Id)
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
8 changes: 2 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 Down Expand Up @@ -132,15 +129,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 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
}
8 changes: 2 additions & 6 deletions cloudconnexa/data_source_user.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 dataSourceUser() *schema.Resource {
Description: "Use a `cloudconnexa_user` data source to read a specific CloudConnexa user.",
ReadContext: dataSourceUserRead,
Schema: map[string]*schema.Schema{
"user_id": {
"id": {
Type: schema.TypeString,
Computed: true,
Description: "The ID of this resource.",
Expand Down Expand Up @@ -111,7 +108,7 @@ func dataSourceUserRead(ctx context.Context, d *schema.ResourceData, m interface
return append(diags, diag.Errorf("User with name %s was not found", userName)...)
}

d.Set("user_id", user.Id)
d.SetId(user.Id)
d.Set("username", user.Username)
d.Set("role", user.Role)
d.Set("email", user.Email)
Expand All @@ -121,7 +118,6 @@ func dataSourceUserRead(ctx context.Context, d *schema.ResourceData, m interface
d.Set("group_id", user.GroupId)
d.Set("status", user.Status)
d.Set("devices", getUserDevicesSlice(&user.Devices))
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
return diags
}

Expand Down
8 changes: 2 additions & 6 deletions cloudconnexa/data_source_user_group.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 dataSourceUserGroup() *schema.Resource {
Description: "Use an `cloudconnexa_user_group` data source to read an CloudConnexa user group.",
ReadContext: dataSourceUserGroupRead,
Schema: map[string]*schema.Schema{
"user_group_id": {
"id": {
Type: schema.TypeString,
Computed: true,
Description: "The user group ID.",
Expand Down Expand Up @@ -67,12 +64,11 @@ func dataSourceUserGroupRead(ctx context.Context, d *schema.ResourceData, m inte
if userGroup == nil {
return append(diags, diag.Errorf("User group with name %s was not found", userGroupName)...)
}
d.Set("user_group_id", userGroup.ID)
d.SetId(userGroup.ID)
d.Set("name", userGroup.Name)
d.Set("vpn_region_ids", userGroup.VpnRegionIds)
d.Set("internet_access", userGroup.InternetAccess)
d.Set("max_device", userGroup.MaxDevice)
d.Set("system_subnets", userGroup.SystemSubnets)
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
return diags
}
8 changes: 2 additions & 6 deletions cloudconnexa/data_source_vpn_region.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 dataSourceVpnRegion() *schema.Resource {
Description: "Use a `cloudconnexa_vpn_region` data source to read an CloudConnexa VPN region.",
ReadContext: dataSourceVpnRegionRead,
Schema: map[string]*schema.Schema{
"region_id": {
"id": {
Type: schema.TypeString,
Required: true,
Description: "The id of the region.",
Expand Down Expand Up @@ -56,11 +53,10 @@ func dataSourceVpnRegionRead(ctx context.Context, d *schema.ResourceData, m inte
if vpnRegion == nil {
return append(diags, diag.Errorf("VPN region with id %s was not found", vpnRegionId)...)
}
d.Set("region_id", vpnRegion.Id)
d.SetId(vpnRegion.Id)
d.Set("continent", vpnRegion.Continent)
d.Set("country", vpnRegion.Country)
d.Set("country_iso", vpnRegion.CountryISO)
d.Set("region_name", vpnRegion.RegionName)
d.SetId(strconv.FormatInt(time.Now().Unix(), 10))
return diags
}
6 changes: 3 additions & 3 deletions example/applications.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ data "cloudconnexa_network" "test-net" {
resource "cloudconnexa_application" "application_full_access" {
name = "example-application-1"
network_item_type = "NETWORK"
network_item_id = data.cloudconnexa_network.test-net.network_id
network_item_id = data.cloudconnexa_network.test-net.id
routes {
domain = "example-application-1.com"
allow_embedded_ip = false
Expand All @@ -19,7 +19,7 @@ resource "cloudconnexa_application" "application_full_access" {
resource "cloudconnexa_application" "application_custom_access" {
name = "example-application-2"
network_item_type = "NETWORK"
network_item_id = data.cloudconnexa_network.test-net.network_id
network_item_id = data.cloudconnexa_network.test-net.id

routes {
domain = "example-application-2.com"
Expand Down Expand Up @@ -72,7 +72,7 @@ resource "cloudconnexa_application" "application_custom_access_advanced" {
name = each.key
description = try(each.value.description, local.created_by)
network_item_type = "NETWORK"
network_item_id = data.cloudconnexa_network.test-net.network_id
network_item_id = data.cloudconnexa_network.test-net.id
config {
service_types = ["ANY"]
}
Expand Down
2 changes: 1 addition & 1 deletion example/connectors.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ resource "cloudconnexa_connector" "test-connector" {
name = "test-connector"
vpn_region_id = "eu-central-1"
network_item_type = "NETWORK"
network_item_id = data.cloudconnexa_network.test-net.network_id
network_item_id = data.cloudconnexa_network.test-net.id
}
2 changes: 1 addition & 1 deletion example/services.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ resource "cloudconnexa_ip_service" "test-service" {
description = "test-description"
routes = ["10.0.0.2/32"]
network_item_type = "NETWORK"
network_item_id = data.cloudconnexa_network.test-net.network_id
network_item_id = data.cloudconnexa_network.test-net.id

config {
service_types = ["ANY"]
Expand Down