Skip to content

Commit

Permalink
feat: spaceID support environment (#551)
Browse files Browse the repository at this point in the history
* feat: spaceID support environment
  • Loading branch information
tothegills authored and domenicsim1 committed Oct 23, 2023
1 parent e86fde0 commit a8f216d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion octopusdeploy/data_source_environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func dataSourceEnvironmentsRead(ctx context.Context, d *schema.ResourceData, m i
}

client := m.(*client.Client)
existingEnvironments, err := client.Environments.Get(query)
existingEnvironments, err := environments.Get(client, d.Get("space_id").(string), query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
9 changes: 5 additions & 4 deletions octopusdeploy/resource_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"

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

client := m.(*client.Client)
createdEnvironment, err := client.Environments.Add(environment)
createdEnvironment, err := environments.Add(client, environment)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -47,7 +48,7 @@ func resourceEnvironmentDelete(ctx context.Context, d *schema.ResourceData, m in
log.Printf("[INFO] deleting environment (%s)", d.Id())

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

Expand All @@ -60,7 +61,7 @@ func resourceEnvironmentRead(ctx context.Context, d *schema.ResourceData, m inte
log.Printf("[INFO] reading environment (%s)", d.Id())

client := m.(*client.Client)
environment, err := client.Environments.GetByID(d.Id())
environment, err := environments.GetByID(client, d.Get("space_id").(string), d.Id())
if err != nil {
return errors.ProcessApiError(ctx, d, err, "environment")
}
Expand All @@ -78,7 +79,7 @@ func resourceEnvironmentUpdate(ctx context.Context, d *schema.ResourceData, m in

environment := expandEnvironment(d)
client := m.(*client.Client)
updatedEnvironment, err := client.Environments.Update(environment)
updatedEnvironment, err := environments.Update(client, d.Get("space_id").(string), environment)
if err != nil {
return diag.FromErr(err)
}
Expand Down
1 change: 1 addition & 0 deletions octopusdeploy/schema_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func getEnvironmentDataSchema() map[string]*schema.Schema {
"partial_name": getQueryPartialName(),
"skip": getQuerySkip(),
"take": getQueryTake(),
"space_id": getSpaceIDSchema(),
}
}

Expand Down

0 comments on commit a8f216d

Please sign in to comment.