Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tothegills/certificate #552

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion octopusdeploy/data_source_certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"context"
"time"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/certificates"

Check failure on line 7 in octopusdeploy/data_source_certificates.go

View workflow job for this annotation

GitHub Actions / build

github.com/OctopusDeploy/go-octopusdeploy/v2@v2.30.1: replacement directory ../go-octopusdeploy/ does not exist
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -31,8 +31,9 @@
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
Loading