-
Notifications
You must be signed in to change notification settings - Fork 3
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
vladhanzha
committed
Jul 24, 2024
1 parent
15debd6
commit d43abf1
Showing
9 changed files
with
541 additions
and
11 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 |
---|---|---|
@@ -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 | ||
} |
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
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
Oops, something went wrong.