diff --git a/octopusdeploy/data_source_certificates.go b/octopusdeploy/data_source_certificates.go index b81b843f9..c907858f0 100644 --- a/octopusdeploy/data_source_certificates.go +++ b/octopusdeploy/data_source_certificates.go @@ -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) } diff --git a/octopusdeploy/resource_certificate.go b/octopusdeploy/resource_certificate.go index 400262ab3..d6098964b 100644 --- a/octopusdeploy/resource_certificate.go +++ b/octopusdeploy/resource_certificate.go @@ -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" @@ -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) } @@ -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) } @@ -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") } @@ -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) } diff --git a/octopusdeploy/schema_certificate.go b/octopusdeploy/schema_certificate.go index 1863f5925..153890be9 100644 --- a/octopusdeploy/schema_certificate.go +++ b/octopusdeploy/schema_certificate.go @@ -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 } @@ -178,6 +182,7 @@ func getCertificateDataSchema() map[string]*schema.Schema { "skip": getQuerySkip(), "take": getQueryTake(), "tenant": getQueryTenant(), + "space_id": getSpaceIDSchema(), } } @@ -296,6 +301,11 @@ func getCertificateSchema() map[string]*schema.Schema { Optional: true, Type: schema.TypeInt, }, + "space_id": { + Optional: true, + Computed: true, + Type: schema.TypeString, + }, } }