Skip to content

Commit

Permalink
CDI-908: fix CDN SSL cert import and allow change name (#162)
Browse files Browse the repository at this point in the history
* CDI-908: fix the resourceCDNCertRead function to store cert name to state

* CDI-908: upd gcorelabscdn-go version

* CDI-908: allow update cdn_sslcert name
  • Loading branch information
andrei-lukyanchyk authored Dec 5, 2024
1 parent 6c0392a commit 11d1583
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
25 changes: 24 additions & 1 deletion gcore/resource_gcore_cdn_sslcerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func resourceCDNCert() *schema.Resource {
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Name of the SSL certificate. Must be unique.",
},
"cert": {
Expand Down Expand Up @@ -51,6 +50,7 @@ func resourceCDNCert() *schema.Resource {
},
CreateContext: resourceCDNCertCreate,
ReadContext: resourceCDNCertRead,
UpdateContext: resourceCDNCertUpdate,
DeleteContext: resourceCDNCertDelete,
}
}
Expand Down Expand Up @@ -97,13 +97,36 @@ func resourceCDNCertRead(ctx context.Context, d *schema.ResourceData, m interfac
return diag.FromErr(err)
}

d.Set("name", result.Name)
d.Set("has_related_resources", result.HasRelatedResources)
d.Set("automated", result.Automated)

log.Println("[DEBUG] Finish CDN Cert reading")
return nil
}

func resourceCDNCertUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
certID := d.Id()
log.Printf("[DEBUG] Start CDN Cert updating (id=%s)\n", certID)
config := m.(*Config)
client := config.CDNClient

id, err := strconv.ParseInt(certID, 10, 64)
if err != nil {
return diag.FromErr(err)
}

var req sslcerts.UpdateRequest
req.Name = d.Get("name").(string)

if _, err := client.SSLCerts().Update(ctx, id, &req); err != nil {
return diag.FromErr(err)
}

log.Println("[DEBUG] Finish CDN Cert updating")
return resourceCDNCertRead(ctx, d, m)
}

func resourceCDNCertDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
certID := d.Id()
log.Printf("[DEBUG] Start CDN Cert deleting (id=%s)\n", certID)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/AlekSi/pointer v1.2.0
github.com/G-Core/gcore-dns-sdk-go v0.2.9
github.com/G-Core/gcore-storage-sdk-go v0.1.34
github.com/G-Core/gcorelabscdn-go v1.0.19
github.com/G-Core/gcorelabscdn-go v1.0.21
github.com/G-Core/gcorelabscloud-go v0.8.13
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.27.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ github.com/G-Core/gcorelabscdn-go v1.0.17 h1:g5i53mzPpg513qcXzxuEdL1v/rK3yiAd8LO
github.com/G-Core/gcorelabscdn-go v1.0.17/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
github.com/G-Core/gcorelabscdn-go v1.0.19 h1:P4qYP+cnO+0DrVftGnL1gt7En8/RYsl20zw4wud9Krs=
github.com/G-Core/gcorelabscdn-go v1.0.19/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
github.com/G-Core/gcorelabscdn-go v1.0.21 h1:ROkbuFy2uyZbnDMaUFrYvjSYqk45GygwU3byOsNIs38=
github.com/G-Core/gcorelabscdn-go v1.0.21/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
github.com/G-Core/gcorelabscloud-go v0.8.12 h1:qT8rrtSCXT+ol1g4zrl5JzWG+8IicHWCn7+U96tdlj4=
github.com/G-Core/gcorelabscloud-go v0.8.12/go.mod h1:13Z1USxlxPbDFuYQyWqfNexlk4kUvOYTXbnvV/Z1lZo=
github.com/G-Core/gcorelabscloud-go v0.8.13 h1:MpaT3owpIfbLP3EPZW+NDuxQfezN7FK6b+4VV0WILP8=
Expand Down

0 comments on commit 11d1583

Please sign in to comment.