Skip to content

Commit

Permalink
feat: spaceID support tenant common variable
Browse files Browse the repository at this point in the history
  • Loading branch information
domenicsim1 committed Oct 16, 2023
1 parent c127083 commit 2b4a5a1
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions octopusdeploy/resource_tenant_common_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/tenants"
"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 @@ -33,6 +34,11 @@ func resourceTenantCommonVariable() *schema.Resource {
Required: true,
Type: schema.TypeString,
},
"space_id": {
Optional: true,
Computed: true,
Type: schema.TypeString,
},
"value": {
Default: "",
Optional: true,
Expand All @@ -51,14 +57,15 @@ func resourceTenantCommonVariableCreate(ctx context.Context, d *schema.ResourceD
libraryVariableSetID := d.Get("library_variable_set_id").(string)
tenantID := d.Get("tenant_id").(string)
templateID := d.Get("template_id").(string)
spaceID := d.Get("space_id").(string)
value := d.Get("value").(string)

id := tenantID + ":" + libraryVariableSetID + ":" + templateID

log.Printf("[INFO] creating tenant common variable (%s)", id)

client := m.(*client.Client)
tenant, err := client.Tenants.GetByID(tenantID)
tenant, err := tenants.GetByID(client, spaceID, tenantID)
if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -94,14 +101,15 @@ func resourceTenantCommonVariableDelete(ctx context.Context, d *schema.ResourceD

libraryVariableSetID := d.Get("library_variable_set_id").(string)
tenantID := d.Get("tenant_id").(string)
spaceID := d.Get("space_id").(string)
templateID := d.Get("template_id").(string)

id := tenantID + ":" + libraryVariableSetID + ":" + templateID

log.Printf("[INFO] deleting tenant common variable (%s)", id)

client := m.(*client.Client)
tenant, err := client.Tenants.GetByID(tenantID)
tenant, err := tenants.GetByID(client, spaceID, tenantID)
if err != nil {
if apiError, ok := err.(*core.APIError); ok {
if apiError.StatusCode == 404 {
Expand Down Expand Up @@ -167,14 +175,15 @@ func resourceTenantCommonVariableRead(ctx context.Context, d *schema.ResourceDat

libraryVariableSetID := d.Get("library_variable_set_id").(string)
tenantID := d.Get("tenant_id").(string)
spaceID := d.Get("space_id").(string)
templateID := d.Get("template_id").(string)

id := tenantID + ":" + libraryVariableSetID + ":" + templateID

log.Printf("[INFO] reading tenant common variable (%s)", id)

client := m.(*client.Client)
tenant, err := client.Tenants.GetByID(tenantID)
tenant, err := tenants.GetByID(client, spaceID, tenantID)
if err != nil {
if apiError, ok := err.(*core.APIError); ok {
if apiError.StatusCode == 404 {
Expand Down Expand Up @@ -219,6 +228,7 @@ func resourceTenantCommonVariableUpdate(ctx context.Context, d *schema.ResourceD

libraryVariableSetID := d.Get("library_variable_set_id").(string)
tenantID := d.Get("tenant_id").(string)
spaceID := d.Get("space_id").(string)
templateID := d.Get("template_id").(string)
value := d.Get("value").(string)

Expand All @@ -227,7 +237,7 @@ func resourceTenantCommonVariableUpdate(ctx context.Context, d *schema.ResourceD
log.Printf("[INFO] updating tenant common variable (%s)", id)

client := m.(*client.Client)
tenant, err := client.Tenants.GetByID(tenantID)
tenant, err := tenants.GetByID(client, spaceID, tenantID)
if err != nil {
return diag.FromErr(err)
}
Expand Down

0 comments on commit 2b4a5a1

Please sign in to comment.