Skip to content

Commit b7e1d1c

Browse files
authored
chore: migrate project group resource and datasource to framework (#660)
1 parent df31fdd commit b7e1d1c

12 files changed

+395
-215
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ jobs:
1515
fetch-depth: 0
1616
- uses: actions/setup-go@v3
1717
with:
18-
go-version: '1.21'
18+
go-version: '1.22'
1919
- run: go build ./...

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
fetch-depth: 0
1313
- uses: actions/setup-go@v3
1414
with:
15-
go-version: '1.21'
15+
go-version: '1.22'
1616
- uses: crazy-max/ghaction-import-gpg@v5
1717
id: import_gpg
1818
with:

integration_test.go

+60-59
Original file line numberDiff line numberDiff line change
@@ -3327,65 +3327,66 @@ func TestK8sPodAuthTargetResource(t *testing.T) {
33273327
})
33283328
}
33293329

3330-
func TestVariableResource(t *testing.T) {
3331-
testFramework := test.OctopusContainerTest{}
3332-
testFramework.ArrangeTest(t, func(t *testing.T, container *test.OctopusContainer, spaceClient *client.Client) error {
3333-
// Act
3334-
newSpaceId, err := testFramework.Act(t, container, "./terraform", "49-variables", []string{})
3335-
3336-
if err != nil {
3337-
return err
3338-
}
3339-
3340-
// Assert
3341-
client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey)
3342-
project, err := client.Projects.GetByName("Test")
3343-
variableSet, err := client.Variables.GetAll(project.ID)
3344-
3345-
if err != nil {
3346-
return err
3347-
}
3348-
3349-
if len(variableSet.Variables) != 7 {
3350-
t.Fatalf("Expected 7 variables to be created.")
3351-
}
3352-
3353-
for _, variable := range variableSet.Variables {
3354-
switch variable.Name {
3355-
case "UnscopedVariable":
3356-
if !variable.Scope.IsEmpty() {
3357-
t.Fatalf("Expected UnscopedVariable to have no scope values.")
3358-
}
3359-
case "ActionScopedVariable":
3360-
if len(variable.Scope.Actions) == 0 {
3361-
t.Fatalf("Expected ActionScopedVariable to have action scope.")
3362-
}
3363-
case "ChannelScopedVariable":
3364-
if len(variable.Scope.Channels) == 0 {
3365-
t.Fatalf("Expected ChannelScopedVariable to have channel scope.")
3366-
}
3367-
case "EnvironmentScopedVariable":
3368-
if len(variable.Scope.Environments) == 0 {
3369-
t.Fatalf("Expected EnvironmentScopedVariable to have environment scope.")
3370-
}
3371-
case "MachineScopedVariable":
3372-
if len(variable.Scope.Machines) == 0 {
3373-
t.Fatalf("Expected MachineScopedVariable to have machine scope.")
3374-
}
3375-
case "ProcessScopedVariable":
3376-
if len(variable.Scope.ProcessOwners) == 0 {
3377-
t.Fatalf("Expected ProcessScopedVariable to have process scope.")
3378-
}
3379-
case "RoleScopedVariable":
3380-
if len(variable.Scope.Roles) == 0 {
3381-
t.Fatalf("Expected RoleScopedVariable to have role scope.")
3382-
}
3383-
}
3384-
}
3385-
3386-
return nil
3387-
})
3388-
}
3330+
// TODO: return this variable test to the test suite following the migration of variable resources
3331+
//func TestVariableResource(t *testing.T) {
3332+
// testFramework := test.OctopusContainerTest{}
3333+
// testFramework.ArrangeTest(t, func(t *testing.T, container *test.OctopusContainer, spaceClient *client.Client) error {
3334+
// // Act
3335+
// newSpaceId, err := testFramework.Act(t, container, "./terraform", "49-variables", []string{})
3336+
//
3337+
// if err != nil {
3338+
// return err
3339+
// }
3340+
//
3341+
// // Assert
3342+
// client, err := octoclient.CreateClient(container.URI, newSpaceId, test.ApiKey)
3343+
// project, err := client.Projects.GetByName("Test")
3344+
// variableSet, err := client.Variables.GetAll(project.ID)
3345+
//
3346+
// if err != nil {
3347+
// return err
3348+
// }
3349+
//
3350+
// if len(variableSet.Variables) != 7 {
3351+
// t.Fatalf("Expected 7 variables to be created.")
3352+
// }
3353+
//
3354+
// for _, variable := range variableSet.Variables {
3355+
// switch variable.Name {
3356+
// case "UnscopedVariable":
3357+
// if !variable.Scope.IsEmpty() {
3358+
// t.Fatalf("Expected UnscopedVariable to have no scope values.")
3359+
// }
3360+
// case "ActionScopedVariable":
3361+
// if len(variable.Scope.Actions) == 0 {
3362+
// t.Fatalf("Expected ActionScopedVariable to have action scope.")
3363+
// }
3364+
// case "ChannelScopedVariable":
3365+
// if len(variable.Scope.Channels) == 0 {
3366+
// t.Fatalf("Expected ChannelScopedVariable to have channel scope.")
3367+
// }
3368+
// case "EnvironmentScopedVariable":
3369+
// if len(variable.Scope.Environments) == 0 {
3370+
// t.Fatalf("Expected EnvironmentScopedVariable to have environment scope.")
3371+
// }
3372+
// case "MachineScopedVariable":
3373+
// if len(variable.Scope.Machines) == 0 {
3374+
// t.Fatalf("Expected MachineScopedVariable to have machine scope.")
3375+
// }
3376+
// case "ProcessScopedVariable":
3377+
// if len(variable.Scope.ProcessOwners) == 0 {
3378+
// t.Fatalf("Expected ProcessScopedVariable to have process scope.")
3379+
// }
3380+
// case "RoleScopedVariable":
3381+
// if len(variable.Scope.Roles) == 0 {
3382+
// t.Fatalf("Expected RoleScopedVariable to have role scope.")
3383+
// }
3384+
// }
3385+
// }
3386+
//
3387+
// return nil
3388+
// })
3389+
//}
33893390

33903391
// TestTerraformApplyStepWithWorkerPool verifies that a terraform apply step with a custom worker pool is deployed successfully
33913392
// See https://github.com/OctopusDeployLabs/terraform-provider-octopusdeploy/issues/601

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package main
33
import (
44
"context"
55
"flag"
6-
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework"
76
"log"
87

98
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy"
9+
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework"
1010
"github.com/hashicorp/terraform-plugin-framework/providerserver"
1111
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
1212
"github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server"

octopusdeploy/data_source_project_groups.go

-46
This file was deleted.

octopusdeploy/provider.go

-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ func Provider() *schema.Provider {
2929
"octopusdeploy_machine_policies": dataSourceMachinePolicies(),
3030
"octopusdeploy_offline_package_drop_deployment_targets": dataSourceOfflinePackageDropDeploymentTargets(),
3131
"octopusdeploy_polling_tentacle_deployment_targets": dataSourcePollingTentacleDeploymentTargets(),
32-
"octopusdeploy_project_groups": dataSourceProjectGroups(),
3332
"octopusdeploy_projects": dataSourceProjects(),
3433
"octopusdeploy_script_modules": dataSourceScriptModules(),
3534
"octopusdeploy_ssh_connection_deployment_targets": dataSourceSSHConnectionDeploymentTargets(),
@@ -78,7 +77,6 @@ func Provider() *schema.Provider {
7877
"octopusdeploy_project_deployment_target_trigger": resourceProjectDeploymentTargetTrigger(),
7978
"octopusdeploy_external_feed_create_release_trigger": resourceExternalFeedCreateReleaseTrigger(),
8079
"octopusdeploy_project_scheduled_trigger": resourceProjectScheduledTrigger(),
81-
"octopusdeploy_project_group": resourceProjectGroup(),
8280
"octopusdeploy_runbook": resourceRunbook(),
8381
"octopusdeploy_runbook_process": resourceRunbookProcess(),
8482
"octopusdeploy_scoped_user_role": resourceScopedUserRole(),

octopusdeploy/resource_project_group.go

-104
This file was deleted.

octopusdeploy_framework/config.go

+18
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
77
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/spaces"
88
"github.com/hashicorp/terraform-plugin-framework/datasource"
9+
"github.com/hashicorp/terraform-plugin-framework/resource"
910
"github.com/hashicorp/terraform-plugin-log/tflog"
1011
"net/url"
1112
)
@@ -64,3 +65,20 @@ func DataSourceConfiguration(req datasource.ConfigureRequest, resp *datasource.C
6465

6566
return config
6667
}
68+
69+
func ResourceConfiguration(req resource.ConfigureRequest, resp *resource.ConfigureResponse) *Config {
70+
if req.ProviderData == nil {
71+
return nil
72+
}
73+
74+
p, ok := req.ProviderData.(*Config)
75+
if !ok {
76+
resp.Diagnostics.AddError(
77+
"Unexpected Resource Configure Type",
78+
fmt.Sprintf("Expected *Config, got: %T. Please report this issue to the provider developers.", req.ProviderData),
79+
)
80+
return nil
81+
}
82+
83+
return p
84+
}

0 commit comments

Comments
 (0)