Skip to content

Commit

Permalink
feat: Space ID support (#558)
Browse files Browse the repository at this point in the history
  • Loading branch information
domenicsim1 authored Oct 23, 2023
1 parent faf3715 commit 440321f
Show file tree
Hide file tree
Showing 110 changed files with 543 additions and 367 deletions.
11 changes: 3 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module github.com/OctopusDeploy/terraform-provider-octopusdeploy
go 1.20

require (
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.30.1
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.33.3
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20230705105638-f5ef7c07973b
github.com/google/uuid v1.3.0
github.com/gruntwork-io/terratest v0.41.11
github.com/hashicorp/go-cty v1.4.1-0.20200723130312-85980079f637
Expand All @@ -28,7 +29,6 @@ require (
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20230705105638-f5ef7c07973b // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
Expand All @@ -44,13 +44,11 @@ require (
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dghubble/sling v1.4.1 // indirect
github.com/dnephin/pflag v1.0.7 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v23.0.5+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.11.2 // indirect
Expand All @@ -59,7 +57,6 @@ require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.7.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
Expand Down Expand Up @@ -129,9 +126,7 @@ require (
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/tools v0.6.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.110.0 // indirect
Expand All @@ -140,5 +135,5 @@ require (
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/gotestsum v1.10.0 // indirect
gotest.tools/v3 v3.3.0 // indirect
)
63 changes: 3 additions & 60 deletions go.sum

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ func main() {
flag.Parse()

opts := &plugin.ServeOpts{
ProviderFunc: octopusdeploy.Provider}
ProviderFunc: octopusdeploy.Provider,
}

if debugMode {
opts.Debug = true
Expand Down
3 changes: 2 additions & 1 deletion octopusdeploy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net/url"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/spaces"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
)

Expand All @@ -27,7 +28,7 @@ func (c *Config) Client() (*client.Client, diag.Diagnostics) {
}

if len(c.SpaceID) > 0 {
space, err := octopus.Spaces.GetByID(c.SpaceID)
space, err := spaces.GetByID(octopus, c.SpaceID)
if err != nil {
return nil, diag.FromErr(err)
}
Expand Down
3 changes: 2 additions & 1 deletion octopusdeploy/data_source_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ func dataSourceAccountsRead(ctx context.Context, d *schema.ResourceData, m inter
Skip: d.Get("skip").(int),
Take: d.Get("take").(int),
}
spaceID := d.Get("space_id").(string)

client := m.(*client.Client)
existingAccounts, err := client.Accounts.Get(query)
existingAccounts, err := accounts.Get(client, spaceID, &query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func dataSourceAzureCloudServiceDeploymentTargetsRead(ctx context.Context, d *sc
}

client := m.(*client.Client)
existingDeploymentTargets, err := client.Machines.Get(query)
existingDeploymentTargets, err := machines.Get(client, d.Get("space_id").(string), query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func dataSourceAzureServiceFabricClusterDeploymentTargetsRead(ctx context.Contex
}

client := m.(*client.Client)
existingDeploymentTargets, err := client.Machines.Get(query)
existingDeploymentTargets, err := machines.Get(client, d.Get("space_id").(string), query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func dataSourceAzureWebAppDeploymentTargetsRead(ctx context.Context, d *schema.R
}

client := m.(*client.Client)
existingDeploymentTargets, err := client.Machines.Get(query)
existingDeploymentTargets, err := machines.Get(client, d.Get("space_id").(string), query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
3 changes: 2 additions & 1 deletion octopusdeploy/data_source_certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ func dataSourceCertificatesRead(ctx context.Context, d *schema.ResourceData, m i
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
3 changes: 2 additions & 1 deletion octopusdeploy/data_source_channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ func dataSourceChannelsRead(ctx context.Context, d *schema.ResourceData, m inter
Skip: d.Get("skip").(int),
Take: d.Get("take").(int),
}
spaceID := d.Get("space_id").(string)

client := m.(*client.Client)
existingChannels, err := client.Channels.Get(query)
existingChannels, err := channels.Get(client, spaceID, query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func dataSourceCloudRegionDeploymentTargetsRead(ctx context.Context, d *schema.R
}

client := m.(*client.Client)
existingDeploymentTargets, err := client.Machines.Get(query)
existingDeploymentTargets, err := machines.Get(client, d.Get("space_id").(string), query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
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
3 changes: 2 additions & 1 deletion octopusdeploy/data_source_feeds.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ func dataSourceFeedsRead(ctx context.Context, d *schema.ResourceData, m interfac
Skip: d.Get("skip").(int),
Take: d.Get("take").(int),
}
spaceID := d.Get("space_id").(string)

client := m.(*client.Client)
existingFeeds, err := client.Feeds.Get(query)
existingFeeds, err := feeds.Get(client, spaceID, query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func dataSourceKubernetesClusterDeploymentTargetsRead(ctx context.Context, d *sc
}

client := m.(*client.Client)
existingDeploymentTargets, err := client.Machines.Get(query)
existingDeploymentTargets, err := machines.Get(client, d.Get("space_id").(string), query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
5 changes: 4 additions & 1 deletion octopusdeploy/data_source_library_variable_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/libraryvariablesets"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/variables"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -27,8 +28,10 @@ func dataSourceLibraryVariableSetReadByName(ctx context.Context, d *schema.Resou
Take: d.Get("take").(int),
}

spaceID := d.Get("space_id").(string)

client := m.(*client.Client)
existingLibraryVariableSets, err := client.LibraryVariableSets.Get(query)
existingLibraryVariableSets, err := libraryvariablesets.Get(client, spaceID, query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
3 changes: 2 additions & 1 deletion octopusdeploy/data_source_lifecycles.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ func dataSourceLifecyclesRead(ctx context.Context, d *schema.ResourceData, m int
Skip: d.Get("skip").(int),
Take: d.Get("take").(int),
}
spaceID := d.Get("space_id").(string)

client := m.(*client.Client)
existingLifecycles, err := client.Lifecycles.Get(query)
existingLifecycles, err := lifecycles.Get(client, spaceID, query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func dataSourceListeningTentacleDeploymentTargetsRead(ctx context.Context, d *sc
}

client := m.(*client.Client)
existingDeploymentTargets, err := client.Machines.Get(query)
existingDeploymentTargets, err := machines.Get(client, d.Get("space_id").(string), query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
7 changes: 4 additions & 3 deletions octopusdeploy/data_source_machine_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"time"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machinepolicies"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand All @@ -19,15 +19,16 @@ func dataSourceMachinePolicies() *schema.Resource {
}

func dataSourceMachinePoliciesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
query := machines.MachinePoliciesQuery{
query := machinepolicies.MachinePoliciesQuery{
IDs: expandArray(d.Get("ids").([]interface{})),
PartialName: d.Get("partial_name").(string),
Skip: d.Get("skip").(int),
Take: d.Get("take").(int),
}

spaceID := d.Get("space_id").(string)
client := m.(*client.Client)
existingMachinePolicies, err := client.MachinePolicies.Get(query)
existingMachinePolicies, err := machinepolicies.Get(client, spaceID, query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func dataSourceOfflinePackageDropDeploymentTargetsRead(ctx context.Context, d *s
}

client := m.(*client.Client)
existingDeploymentTargets, err := client.Machines.Get(query)
existingDeploymentTargets, err := machines.Get(client, d.Get("space_id").(string), query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func dataSourcePollingTentacleDeploymentTargetsRead(ctx context.Context, d *sche
}

client := m.(*client.Client)
existingDeploymentTargets, err := client.Machines.Get(query)
existingDeploymentTargets, err := machines.Get(client, d.Get("space_id").(string), query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
4 changes: 3 additions & 1 deletion octopusdeploy/data_source_project_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ func dataSourceProjectGroupsRead(ctx context.Context, d *schema.ResourceData, m
Take: d.Get("take").(int),
}

spaceID := d.Get("space_id").(string)

client := m.(*client.Client)
existingProjectGroups, err := client.ProjectGroups.Get(query)
existingProjectGroups, err := projectgroups.Get(client, spaceID, query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
4 changes: 3 additions & 1 deletion octopusdeploy/data_source_projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ func dataSourceProjectsRead(ctx context.Context, d *schema.ResourceData, m inter
Take: d.Get("take").(int),
}

spaceID := d.Get("space_id").(string)

client := m.(*client.Client)
existingProjects, err := client.Projects.Get(query)
existingProjects, err := projects.Get(client, spaceID, query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
5 changes: 4 additions & 1 deletion octopusdeploy/data_source_script_modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/scriptmodules"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/variables"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand All @@ -27,8 +28,10 @@ func dataSourceScriptModulesRead(ctx context.Context, d *schema.ResourceData, m
Take: d.Get("take").(int),
}

spaceID := d.Get("space_id").(string)

client := m.(*client.Client)
existingScriptModules, err := client.ScriptModules.Get(query)
existingScriptModules, err := scriptmodules.Get(client, spaceID, query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy/data_source_spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func dataSourceSpacesRead(ctx context.Context, d *schema.ResourceData, m interfa
Take: d.Get("take").(int),
}

existingSpaces, err := client.Spaces.Get(query)
existingSpaces, err := spaces.Get(client, query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func dataSourceSSHConnectionDeploymentTargetsRead(ctx context.Context, d *schema
}

client := m.(*client.Client)
existingDeploymentTargets, err := client.Machines.Get(query)
existingDeploymentTargets, err := machines.Get(client, d.Get("space_id").(string), query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
3 changes: 2 additions & 1 deletion octopusdeploy/data_source_tag_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ func dataSourceTagSetsRead(ctx context.Context, d *schema.ResourceData, m interf
Skip: d.Get("skip").(int),
Take: d.Get("take").(int),
}
spaceID := d.Get("space_id").(string)

octopus := m.(*client.Client)
existingTagSets, err := octopus.TagSets.Get(query)
existingTagSets, err := tagsets.Get(octopus, spaceID, query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
4 changes: 3 additions & 1 deletion octopusdeploy/data_source_user_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ func dataSourceUserRolesRead(ctx context.Context, d *schema.ResourceData, meta i
Take: d.Get("take").(int),
}

spaceID := d.Get("space_id").(string)

client := meta.(*client.Client)
existingUserRoles, err := client.UserRoles.Get(query)
existingUserRoles, err := userroles.Get(client, spaceID, query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
4 changes: 3 additions & 1 deletion octopusdeploy/data_source_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ func dataSourceUsersRead(ctx context.Context, d *schema.ResourceData, meta inter
Take: d.Get("take").(int),
}

spaceID := d.Get("space_id").(string)

client := meta.(*client.Client)
existingUsers, err := client.Users.Get(query)
existingUsers, err := users.Get(client, spaceID, query)
if err != nil {
return diag.FromErr(err)
}
Expand Down
7 changes: 6 additions & 1 deletion octopusdeploy/data_source_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ func dataSourceVariableReadByName(ctx context.Context, d *schema.ResourceData, m
scope = expandVariableScope(v)
}

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

client := m.(*client.Client)
variables, err := client.Variables.GetByName(ownerID.(string), name.(string), &scope)
variables, err := variables.GetByName(client, spaceID, ownerID.(string), name.(string), &scope)
if err != nil {
return diag.Errorf("error reading variable with owner ID %s with name %s: %s", ownerID, name, err.Error())
}
Expand Down
Loading

0 comments on commit 440321f

Please sign in to comment.