Skip to content

Commit

Permalink
feat: spaceID support certificates (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
tothegills authored Oct 16, 2023
1 parent 30085c4 commit ca4c8bc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion octopusdeploy/data_source_certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ func dataSourceCertificatesRead(ctx context.Context, d *schema.ResourceData, m i
Tenant: d.Get("tenant").(string),
}

spaceID := d.Get("space_id").(string)
client := m.(*client.Client)
existingCertificates, err := client.Certificates.Get(query)
existingCertificates, err := certificates.Get(client, spaceID, query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
11 changes: 7 additions & 4 deletions octopusdeploy/resource_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"log"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/certificates"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand All @@ -28,7 +29,7 @@ func resourceCertificateCreate(ctx context.Context, d *schema.ResourceData, m in
log.Printf("[INFO] creating certificate: %#v", certificate)

client := m.(*client.Client)
createdCertificate, err := client.Certificates.Add(certificate)
createdCertificate, err := certificates.Add(client, certificate)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -46,8 +47,9 @@ func resourceCertificateCreate(ctx context.Context, d *schema.ResourceData, m in
func resourceCertificateDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Printf("[INFO] deleting certificate (%s)", d.Id())

spaceID := d.Get("space_id").(string)
client := m.(*client.Client)
if err := client.Certificates.DeleteByID(d.Id()); err != nil {
if err := certificates.DeleteByID(client, spaceID, d.Id()); err != nil {
return diag.FromErr(err)
}

Expand All @@ -60,8 +62,9 @@ func resourceCertificateDelete(ctx context.Context, d *schema.ResourceData, m in
func resourceCertificateRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Printf("[INFO] reading certificate (%s)", d.Id())

spaceID := d.Get("space_id").(string)
client := m.(*client.Client)
certificate, err := client.Certificates.GetByID(d.Id())
certificate, err := certificates.GetByID(client, spaceID, d.Id())
if err != nil {
return errors.ProcessApiError(ctx, d, err, "certificate")
}
Expand All @@ -79,7 +82,7 @@ func resourceCertificateUpdate(ctx context.Context, d *schema.ResourceData, m in

certificate := expandCertificate(d)
client := m.(*client.Client)
updatedCertificate, err := client.Certificates.Update(*certificate)
updatedCertificate, err := certificates.Update(client, certificate)
if err != nil {
return diag.FromErr(err)
}
Expand Down
10 changes: 10 additions & 0 deletions octopusdeploy/schema_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ func expandCertificate(d *schema.ResourceData) *certificates.CertificateResource
certificate.Version = v.(int)
}

if v, ok := d.GetOk("space_id"); ok {
certificate.SpaceID = v.(string)
}

return certificate
}

Expand Down Expand Up @@ -178,6 +182,7 @@ func getCertificateDataSchema() map[string]*schema.Schema {
"skip": getQuerySkip(),
"take": getQueryTake(),
"tenant": getQueryTenant(),
"space_id": getSpaceIDSchema(),
}
}

Expand Down Expand Up @@ -296,6 +301,11 @@ func getCertificateSchema() map[string]*schema.Schema {
Optional: true,
Type: schema.TypeInt,
},
"space_id": {
Optional: true,
Computed: true,
Type: schema.TypeString,
},
}
}

Expand Down

0 comments on commit ca4c8bc

Please sign in to comment.