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

Add applications support #17

Merged
merged 9 commits into from
Jul 25, 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
58 changes: 58 additions & 0 deletions cloudconnexa/data_source_application.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package cloudconnexa

import (
"context"
"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"
)

func dataSourceApplication() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceApplicationRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"routes": {
Type: schema.TypeList,
Computed: true,
Elem: resourceApplicationRoute(),
},
"config": {
Type: schema.TypeList,
Computed: true,
Elem: resourceApplicationConfig(),
},
"network_item_type": {
Type: schema.TypeString,
Computed: true,
},
"network_item_id": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceApplicationRead(ctx context.Context, data *schema.ResourceData, i interface{}) diag.Diagnostics {
c := i.(*cloudconnexa.Client)
var diags diag.Diagnostics
var name = data.Get("name").(string)
application, err := c.Applications.GetByName(name)

if err != nil {
return diag.FromErr(err)
}
if application == nil {
return append(diags, diag.Errorf("Application with name %s was not found", name)...)
}
setApplicationData(data, application)
return nil
}
6 changes: 6 additions & 0 deletions cloudconnexa/data_source_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ 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": {
Type: schema.TypeString,
Computed: true,
Description: "The host ID.",
},
"name": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -88,6 +93,7 @@ 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.Set("name", host.Name)
d.Set("internet_access", host.InternetAccess)
d.Set("system_subnets", host.SystemSubnets)
Expand Down
18 changes: 10 additions & 8 deletions cloudconnexa/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ func Provider() *schema.Provider {
},
},
ResourcesMap: map[string]*schema.Resource{
"cloudconnexa_network": resourceNetwork(),
"cloudconnexa_connector": resourceConnector(),
"cloudconnexa_route": resourceRoute(),
"cloudconnexa_dns_record": resourceDnsRecord(),
"cloudconnexa_user": resourceUser(),
"cloudconnexa_host": resourceHost(),
"cloudconnexa_user_group": resourceUserGroup(),
"cloudconnexa_ip_service": resourceIPService(),
"cloudconnexa_network": resourceNetwork(),
"cloudconnexa_connector": resourceConnector(),
"cloudconnexa_route": resourceRoute(),
"cloudconnexa_dns_record": resourceDnsRecord(),
"cloudconnexa_user": resourceUser(),
"cloudconnexa_host": resourceHost(),
"cloudconnexa_user_group": resourceUserGroup(),
"cloudconnexa_ip_service": resourceIPService(),
"cloudconnexa_application": resourceApplication(),
},

DataSourcesMap: map[string]*schema.Resource{
Expand All @@ -64,6 +65,7 @@ func Provider() *schema.Provider {
"cloudconnexa_network_routes": dataSourceNetworkRoutes(),
"cloudconnexa_host": dataSourceHost(),
"cloudconnexa_ip_service": dataSourceIPService(),
"cloudconnexa_application": dataSourceApplication(),
},
ConfigureContextFunc: providerConfigure,
}
Expand Down
Loading