Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into isaac/tenant-datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacCalligeros95 committed Aug 8, 2024
2 parents b930ac6 + 3a8a027 commit b4a8969
Show file tree
Hide file tree
Showing 31 changed files with 228 additions and 34 deletions.
1 change: 1 addition & 0 deletions octopusdeploy/schema_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func getAccountResourceDataSchema() map[string]*schema.Schema {
Description: "A list of accounts that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Type: schema.TypeList,
Optional: false,
},
"id": getDataSchemaID(),
"space_id": getQuerySpaceID(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func getAzureCloudServiceDeploymentTargetDataSchema() map[string]*schema.Schema
Computed: true,
Description: "A list of Azure cloud service deployment targets that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func getAzureServiceFabricClusterDeploymentTargetDataSchema() map[string]*schema
Computed: true,
Description: "A list of Azure service fabric cluster deployment targets that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
}

Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy/schema_azure_web_app_deployment_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func getAzureWebAppDeploymentTargetDataSchema() map[string]*schema.Schema {
Computed: true,
Description: "A list of Azure web app deployment targets that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
}

Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy/schema_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func getCertificateDataSchema() map[string]*schema.Schema {
Computed: true,
Description: "A list of certificates that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
},
"first_result": getQueryFirstResult(),
Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy/schema_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func getChannelDataSchema() map[string]*schema.Schema {
Computed: true,
Description: "A channel that matches the specified filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
},
"ids": getQueryIDs(),
Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy/schema_cloud_region_deployment_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func getCloudRegionDeploymentTargetDataSchema() map[string]*schema.Schema {
Computed: true,
Description: "A list of cloud region deployment targets that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
}

Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy/schema_deployment_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func getDeploymentTargetDataSchema() map[string]*schema.Schema {
Computed: true,
Description: "A list of deployment targets that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
},
"environments": getQueryEnvironments(),
Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy/schema_kubernetes_agent_deployment_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func getKubernetesAgentDeploymentTargetDataSchema() map[string]*schema.Schema {
Computed: true,
Description: "A list of kubernetes agent deployment targets that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func getKubernetesClusterDeploymentTargetDataSchema() map[string]*schema.Schema
Computed: true,
Description: "A list of Kubernetes cluster deployment targets that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func getListeningTentacleDeploymentTargetDataSchema() map[string]*schema.Schema
Computed: true,
Description: "A list of listening tentacle deployment targets that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
}

Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy/schema_machine_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func getMachinePolicyDataSchema() map[string]*schema.Schema {
Computed: true,
Description: "A list of machine policies that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
},
"partial_name": getQueryPartialName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func getOfflinePackageDropDeploymentTargetDataSchema() map[string]*schema.Schema
Computed: true,
Description: "A list of offline package drop deployment targets that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
}

Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy/schema_polling_tentacle_deployment_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func getPollingTentacleDeploymentTargetDataSchema() map[string]*schema.Schema {
Computed: true,
Description: "A list of polling tentacle deployment targets that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
}

Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy/schema_script_modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func getScriptModuleDataSchema() map[string]*schema.Schema {
Computed: true,
Description: "A list of script modules that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
},
"partial_name": getQueryPartialName(),
Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy/schema_ssh_connection_deployment_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func getSSHConnectionDeploymentTargetDataSchema() map[string]*schema.Schema {
Computed: true,
Description: "A list of SSH connection deployment targets that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
}

Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy/schema_tag_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func getTagSetDataSchema() map[string]*schema.Schema {
Computed: true,
Description: "A list of tag sets that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
},
"take": getQueryTake(),
Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy/schema_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func getTeamDataSchema() map[string]*schema.Schema {
Computed: true,
Description: "A list of teams that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
},
}
Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy/schema_tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func getTenantDataSchema() map[string]*schema.Schema {
Computed: true,
Description: "A list of tenants that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
},
"take": getQueryTake(),
Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy/schema_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func getUserDataSchema() map[string]*schema.Schema {
Computed: true,
Description: "A list of users that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
},
}
Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy/schema_user_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func getUserRoleDataSchema() map[string]*schema.Schema {
Computed: true,
Description: "A list of user roles that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
},
}
Expand Down
2 changes: 1 addition & 1 deletion octopusdeploy/schema_worker_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func getWorkerPoolDataSchema() map[string]*schema.Schema {
Computed: true,
Description: "A list of worker pools that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Optional: false,
Type: schema.TypeList,
},
}
Expand Down
5 changes: 5 additions & 0 deletions octopusdeploy/testing_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func TestMain(m *testing.M) {
log.Printf("Failed to create client: (%s)", err.Error())
panic(m)
}

octoContainer = &test.OctopusContainer{
Container: nil,
URI: url,
}
}
code := m.Run()
os.Exit(code)
Expand Down
63 changes: 63 additions & 0 deletions octopusdeploy_framework/datasource_lifecycle_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package octopusdeploy_framework

import (
"fmt"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestAccDataSourceLifecycles(t *testing.T) {
spaceName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
lifecycleName := "Default Lifecycle"
resourceName := "data.octopusdeploy_lifecycles.lifecycle_default_lifecycle"

resource.Test(t, resource.TestCase{
PreCheck: func() { TestAccPreCheck(t) },
ProtoV6ProviderFactories: ProtoV6ProviderFactories(),
Steps: []resource.TestStep{
{
Config: testAccDataSourceLifecyclesConfig(spaceName, lifecycleName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "space_id"),
resource.TestCheckResourceAttr(resourceName, "partial_name", lifecycleName),
resource.TestCheckResourceAttr(resourceName, "lifecycles.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "lifecycles.0.id"),
resource.TestCheckResourceAttr(resourceName, "lifecycles.0.name", lifecycleName),
testAccCheckOutputExists("octopus_space_id"),
testAccCheckOutputExists("octopus_lifecycle_id"),
),
},
},
})
}

func testAccDataSourceLifecyclesConfig(spaceName, lifecycleName string) string {
return fmt.Sprintf(`
resource "octopusdeploy_space" "octopus_project_space_test" {
name = "%s"
is_default = false
is_task_queue_stopped = false
description = "Test space for lifecycles datasource"
space_managers_teams = ["teams-administrators"]
}
data "octopusdeploy_lifecycles" "lifecycle_default_lifecycle" {
ids = null
partial_name = "%s"
space_id = octopusdeploy_space.octopus_project_space_test.id
skip = 0
take = 1
depends_on = [octopusdeploy_space.octopus_project_space_test]
}
output "octopus_space_id" {
value = octopusdeploy_space.octopus_project_space_test.id
}
output "octopus_lifecycle_id" {
value = data.octopusdeploy_lifecycles.lifecycle_default_lifecycle.lifecycles[0].id
}
`, spaceName, lifecycleName)
}
58 changes: 58 additions & 0 deletions octopusdeploy_framework/datasource_spaces_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package octopusdeploy_framework

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

func TestAccDataSourceSpaces(t *testing.T) {
spaceID := "Spaces-1"
resourceName := "data.octopusdeploy_spaces.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { TestAccPreCheck(t) },
ProtoV6ProviderFactories: ProtoV6ProviderFactories(),
Steps: []resource.TestStep{
{
Config: testAccDataSourceSpacesConfig(spaceID),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "ids.#", "1"),
resource.TestCheckResourceAttr(resourceName, "ids.0", spaceID),
resource.TestCheckResourceAttr(resourceName, "skip", "0"),
resource.TestCheckResourceAttr(resourceName, "take", "1"),
resource.TestCheckResourceAttrSet(resourceName, "spaces.0.id"),
testAccCheckOutputExists("octopus_space_id"),
resource.TestCheckOutput("octopus_space_id", spaceID),
),
},
},
})
}

func testAccDataSourceSpacesConfig(spaceID string) string {
tfConfig := fmt.Sprintf(`
data "octopusdeploy_spaces" "test" {
ids = ["%s"]
skip = 0
take = 1
}
output "octopus_space_id" {
value = data.octopusdeploy_spaces.test.spaces[0].id
}
`, spaceID)
return tfConfig
}

func testAccCheckOutputExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
_, ok := s.RootModule().Outputs[name]
if !ok {
return fmt.Errorf("output %s not found", name)
}
return nil
}
}
15 changes: 14 additions & 1 deletion octopusdeploy_framework/resource_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package octopusdeploy_framework
import (
"fmt"
"path/filepath"
"strings"
"testing"
"time"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/variables"
internalTest "github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/test"
Expand Down Expand Up @@ -320,14 +322,25 @@ func TestVariableResource(t *testing.T) {
// Assert
client, err := octoclient.CreateClient(octoContainer.URI, newSpaceId, test.ApiKey)
project, err := client.Projects.GetByName("Test")

// Add a short delay before querying the API
time.Sleep(5 * time.Second)
variableSet, err := client.Variables.GetAll(project.ID)

if err != nil {
t.Fatal(err.Error())
}

if len(variableSet.Variables) != 7 {
t.Fatalf("Expected 7 variables to be created.")
var report strings.Builder
report.WriteString(fmt.Sprintf("Expected 7 variables, but found %d.\nReturned variables:\n", len(variableSet.Variables)))

for _, v := range variableSet.Variables {
report.WriteString(fmt.Sprintf("- Name: %s\n Type: %s\n Value: %s\n Scope: %+v\n\n",
v.Name, v.Type, v.Value, v.Scope))
}

t.Fatalf(report.String())
}

for _, variable := range variableSet.Variables {
Expand Down
1 change: 1 addition & 0 deletions octopusdeploy_framework/schemas/gitCredential.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func GetGitCredentialDataSourceSchema() map[string]datasourceSchema.Attribute {
"take": util.GetQueryTakeDatasourceSchema(),
"git_credentials": datasourceSchema.ListNestedAttribute{
Computed: true,
Optional: false,
Description: "A list of Git Credentials that match the filter(s).",
NestedObject: datasourceSchema.NestedAttributeObject{
Attributes: GetGitCredentialAttributes(),
Expand Down
1 change: 1 addition & 0 deletions octopusdeploy_framework/schemas/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func GetDatasourceLifecycleSchema() datasourceSchema.Schema {
"take": util.GetQueryTakeDatasourceSchema(),
"lifecycles": datasourceSchema.ListNestedAttribute{
Computed: true,
Optional: false,
NestedObject: datasourceSchema.NestedAttributeObject{
Attributes: map[string]datasourceSchema.Attribute{
"id": GetIdDatasourceSchema(true),
Expand Down
1 change: 1 addition & 0 deletions octopusdeploy_framework/schemas/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ func getProjectsDataSourceAttribute() datasourceSchema.ListNestedAttribute {
return datasourceSchema.ListNestedAttribute{
Description: "A list of projects that match the filter(s).",
Computed: true,
Optional: false,
NestedObject: datasourceSchema.NestedAttributeObject{
Attributes: map[string]datasourceSchema.Attribute{
"allow_deployments_to_no_targets": util.DataSourceBool().Computed().Deprecated("Allow deployments to be created when there are no targets.").Build(),
Expand Down
Loading

0 comments on commit b4a8969

Please sign in to comment.