diff --git a/cloudconnexa/data_source_application.go b/cloudconnexa/data_source_application.go index 3614589..691cc97 100644 --- a/cloudconnexa/data_source_application.go +++ b/cloudconnexa/data_source_application.go @@ -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, diff --git a/cloudconnexa/data_source_connector.go b/cloudconnexa/data_source_connector.go index c7f9307..717faaa 100644 --- a/cloudconnexa/data_source_connector.go +++ b/cloudconnexa/data_source_connector.go @@ -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" @@ -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, @@ -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) @@ -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 } diff --git a/cloudconnexa/data_source_host.go b/cloudconnexa/data_source_host.go index 33efb41..c8180b5 100644 --- a/cloudconnexa/data_source_host.go +++ b/cloudconnexa/data_source_host.go @@ -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" @@ -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.", @@ -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 } diff --git a/cloudconnexa/data_source_network.go b/cloudconnexa/data_source_network.go index 1a68382..d833e26 100644 --- a/cloudconnexa/data_source_network.go +++ b/cloudconnexa/data_source_network.go @@ -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" @@ -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.", @@ -132,7 +129,7 @@ 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) @@ -140,7 +137,6 @@ func dataSourceNetworkRead(ctx context.Context, d *schema.ResourceData, m interf 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 } diff --git a/cloudconnexa/data_source_network_routes.go b/cloudconnexa/data_source_network_routes.go index 557c57a..727d1d2 100644 --- a/cloudconnexa/data_source_network_routes.go +++ b/cloudconnexa/data_source_network_routes.go @@ -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" @@ -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.", @@ -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 } diff --git a/cloudconnexa/data_source_user.go b/cloudconnexa/data_source_user.go index d327f44..c5f1a97 100644 --- a/cloudconnexa/data_source_user.go +++ b/cloudconnexa/data_source_user.go @@ -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" @@ -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.", @@ -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) @@ -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 } diff --git a/cloudconnexa/data_source_user_group.go b/cloudconnexa/data_source_user_group.go index 43a0763..35b6fb1 100644 --- a/cloudconnexa/data_source_user_group.go +++ b/cloudconnexa/data_source_user_group.go @@ -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" @@ -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.", @@ -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 } diff --git a/cloudconnexa/data_source_vpn_region.go b/cloudconnexa/data_source_vpn_region.go index 3bab8f0..550a265 100644 --- a/cloudconnexa/data_source_vpn_region.go +++ b/cloudconnexa/data_source_vpn_region.go @@ -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" @@ -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.", @@ -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 } diff --git a/example/applications.tf b/example/applications.tf index ea4bf03..d314a78 100644 --- a/example/applications.tf +++ b/example/applications.tf @@ -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 @@ -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" @@ -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"] } diff --git a/example/connectors.tf b/example/connectors.tf index a345ff9..eda31da 100644 --- a/example/connectors.tf +++ b/example/connectors.tf @@ -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 } diff --git a/example/services.tf b/example/services.tf index 764eb22..30d6d21 100644 --- a/example/services.tf +++ b/example/services.tf @@ -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"]