Skip to content

Commit

Permalink
feat: spaceID support new client
Browse files Browse the repository at this point in the history
  • Loading branch information
domenicsim1 committed Oct 16, 2023
1 parent 0b4a5ea commit c127083
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion octopusdeploy/data_source_git_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ func dataSourceGitCredentialsRead(ctx context.Context, d *schema.ResourceData, m
Skip: d.Get("skip").(int),
Take: d.Get("take").(int),
}
spaceID := d.Get("space_id").(string)

client := m.(*client.Client)
existingGitCredentials, err := client.GitCredentials.Get(query)
existingGitCredentials, err := credentials.Get(client, spaceID, query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
11 changes: 6 additions & 5 deletions octopusdeploy/resource_git_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/credentials"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand All @@ -29,12 +30,12 @@ func resourceGitCredentialCreate(ctx context.Context, d *schema.ResourceData, m
tflog.Info(ctx, fmt.Sprintf("creating Git credential, %s", resource.Name))

client := m.(*client.Client)
createdResource, err := client.GitCredentials.Add(resource)
createdResource, err := credentials.Add(client, resource)
if err != nil {
return diag.FromErr(err)
}

createdResource, err = client.GitCredentials.GetByID(createdResource.GetID())
createdResource, err = credentials.GetByID(client, d.Get("space_id").(string), createdResource.GetID())
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -53,7 +54,7 @@ func resourceGitCredentialDelete(ctx context.Context, d *schema.ResourceData, m
tflog.Info(ctx, fmt.Sprintf("deleting Git credential (%s)", d.Id()))

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

Expand All @@ -67,7 +68,7 @@ func resourceGitCredentialRead(ctx context.Context, d *schema.ResourceData, m in
tflog.Info(ctx, fmt.Sprintf("reading Git credential (%s)", d.Id()))

client := m.(*client.Client)
resource, err := client.GitCredentials.GetByID(d.Id())
resource, err := credentials.GetByID(client, d.Get("space_id").(string), d.Id())
if err != nil {
return errors.ProcessApiError(ctx, d, err, "Git credential")
}
Expand All @@ -86,7 +87,7 @@ func resourceGitCredentialUpdate(ctx context.Context, d *schema.ResourceData, m
tflog.Info(ctx, fmt.Sprintf("updating Git credential (%s)", resource.GetID()))

client := m.(*client.Client)
updatedResource, err := client.GitCredentials.Update(resource)
updatedResource, err := credentials.Update(client, resource)
if err != nil {
return diag.FromErr(err)
}
Expand Down
7 changes: 4 additions & 3 deletions octopusdeploy/schema_git_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ func getGitCredentialDataSchema() map[string]*schema.Schema {
Optional: true,
Type: schema.TypeList,
},
"name": getQueryName(),
"skip": getQuerySkip(),
"take": getQueryTake(),
"name": getQueryName(),
"skip": getQuerySkip(),
"take": getQueryTake(),
"space_id": getSpaceIDSchema(),
}
}

Expand Down

0 comments on commit c127083

Please sign in to comment.