Skip to content

Commit

Permalink
Make spaceId required on the provider; make lvs space specific
Browse files Browse the repository at this point in the history
  • Loading branch information
mik-ky committed Oct 4, 2023
1 parent 30a974c commit 52148e2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,5 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/gotestsum v1.10.0 // indirect
)

replace github.com/OctopusDeploy/go-octopusdeploy/v2 => ../go-octopusdeploy/
17 changes: 15 additions & 2 deletions octopusdeploy/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package octopusdeploy

import (
"net/http"
"net/url"

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

Check failure on line 7 in octopusdeploy/config.go

View workflow job for this annotation

GitHub Actions / build

github.com/OctopusDeploy/go-octopusdeploy/[email protected]: replacement directory ../go-octopusdeploy/ does not exist
Expand All @@ -21,7 +22,19 @@ func (c *Config) Client() (*client.Client, diag.Diagnostics) {
return nil, diag.FromErr(err)
}

octopus, err := client.NewClient(nil, apiURL, c.APIKey, "")
// This is intentional on the feature branch - Todo: remove when merging to main branch
proxyStr := "http://127.0.0.1:8866"
proxyURL, err := url.Parse(proxyStr)
if err != nil {
return nil, nil
}

tr := &http.Transport{
Proxy: http.ProxyURL(proxyURL),
}
httpClient := http.Client{Transport: tr}

octopus, err := client.NewClient(&httpClient, apiURL, c.APIKey, "")
if err != nil {
return nil, diag.FromErr(err)
}
Expand All @@ -32,7 +45,7 @@ func (c *Config) Client() (*client.Client, diag.Diagnostics) {
return nil, diag.FromErr(err)
}

octopus, err = client.NewClient(nil, apiURL, c.APIKey, space.GetID())
octopus, err = client.NewClient(&httpClient, apiURL, c.APIKey, space.GetID())
if err != nil {
return nil, diag.FromErr(err)
}
Expand Down
7 changes: 2 additions & 5 deletions octopusdeploy/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func Provider() *schema.Provider {
},
"space_id": {
Description: "The space ID to target",
Optional: true,
Required: true,
Type: schema.TypeString,
},
},
Expand All @@ -123,10 +123,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
config := Config{
Address: d.Get("address").(string),
APIKey: d.Get("api_key").(string),
}

if spaceID, ok := d.GetOk("space_id"); ok {
config.SpaceID = spaceID.(string)
SpaceID: d.Get("space_id").(string),
}

return config.Client()
Expand Down
4 changes: 3 additions & 1 deletion octopusdeploy/resource_library_variable_set.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/libraryvariableset"
"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,8 @@ func resourceLibraryVariableSetCreate(ctx context.Context, d *schema.ResourceDat
log.Printf("[INFO] creating library variable set: %#v", libraryVariableSet)

client := m.(*client.Client)
createdLibraryVariableSet, err := client.LibraryVariableSets.Add(libraryVariableSet)

createdLibraryVariableSet, err := libraryvariableset.Add(client, libraryVariableSet)
if err != nil {
return diag.FromErr(err)
}
Expand Down
4 changes: 4 additions & 0 deletions octopusdeploy/schema_library_variable_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func expandLibraryVariableSet(d *schema.ResourceData) *variables.LibraryVariable
libraryVariableSet.Description = v.(string)
}

if v, ok := d.GetOk("space_id"); ok {
libraryVariableSet.SpaceID = v.(string)
}

if attr, ok := d.GetOk("template"); ok {
tfTemplates := attr.([]interface{})

Expand Down

0 comments on commit 52148e2

Please sign in to comment.