Skip to content

Commit

Permalink
Merge pull request #33 from OpenVPN/feature/CAPI-237-connector-token-…
Browse files Browse the repository at this point in the history
…retrieval

Implemented connector token retrieval
  • Loading branch information
sahaqaa authored Jul 30, 2024
2 parents 7db7c31 + b5d7d85 commit c8b4373
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cloudconnexa/data_source_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func dataSourceConnector() *schema.Resource {
Computed: true,
Description: "OpenVPN profile",
},
"token": {
Type: schema.TypeString,
Computed: true,
Description: "Connector token",
},
},
}
}
Expand All @@ -71,6 +76,10 @@ func dataSourceConnectorRead(ctx context.Context, d *schema.ResourceData, m inte
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)
Expand All @@ -80,6 +89,8 @@ func dataSourceConnectorRead(ctx context.Context, d *schema.ResourceData, m inte
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)...)
Expand Down
16 changes: 16 additions & 0 deletions cloudconnexa/resource_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ func resourceConnector() *schema.Resource {
Computed: true,
Description: "OpenVPN profile of the connector.",
},
"token": {
Type: schema.TypeString,
Computed: true,
Description: "Connector token.",
},
},
}
}
Expand Down Expand Up @@ -111,6 +116,11 @@ func resourceConnectorCreate(ctx context.Context, d *schema.ResourceData, m inte
return append(diags, diag.FromErr(err)...)
}
d.Set("profile", profile)
token, err := c.Connectors.GetToken(conn.Id)
if err != nil {
return append(diags, diag.FromErr(err)...)
}
d.Set("token", token)
return append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "Connector needs to be set up manually",
Expand All @@ -125,6 +135,11 @@ func resourceConnectorRead(ctx context.Context, d *schema.ResourceData, m interf
if err != nil {
return append(diags, diag.FromErr(err)...)
}
token, err := c.Connectors.GetToken(connector.Id)
if err != nil {
return append(diags, diag.FromErr(err)...)
}

if connector == nil {
d.SetId("")
} else {
Expand All @@ -135,6 +150,7 @@ func resourceConnectorRead(ctx context.Context, d *schema.ResourceData, m interf
d.Set("network_item_id", connector.NetworkItemId)
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)...)
Expand Down

0 comments on commit c8b4373

Please sign in to comment.