Skip to content

Commit

Permalink
Fixed file path filters and made git sourcing specific to run script …
Browse files Browse the repository at this point in the history
…action for the moment
  • Loading branch information
tleed5 committed Jan 10, 2024
1 parent 611d82b commit 4aa10f2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 60 deletions.
11 changes: 11 additions & 0 deletions octopusdeploy/schema_action_run_script.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package octopusdeploy

import (
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/gitdependencies"

Check failure on line 4 in octopusdeploy/schema_action_run_script.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/gitdependencies; to add it:
"strconv"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
Expand Down Expand Up @@ -88,6 +89,11 @@ func expandRunScriptAction(flattenedAction map[string]interface{}) *deployments.
action.WorkerPoolVariable = v.(string)
}

if v, ok := flattenedAction["git_dependency"]; ok {
action.GitDependencies = []*gitdependencies.GitDependency{expandGitDependency(v.(*schema.Set))}
action.Properties["Octopus.Action.GitRepository.Source"] = core.NewPropertyValue("External", false)
}

return action
}

Expand All @@ -106,6 +112,10 @@ func flattenRunScriptAction(action *deployments.DeploymentAction) map[string]int
flattenedAction["worker_pool_variable"] = action.WorkerPoolVariable
}

if len(action.GitDependencies) > 0 {
flattenedAction["git_dependency"] = flattenGitDependency(action.GitDependencies[0])
}

if v, ok := action.Properties["Octopus.Action.RunOnServer"]; ok {
runOnServer, _ := strconv.ParseBool(v.Value)
flattenedAction["run_on_server"] = runOnServer
Expand Down Expand Up @@ -146,6 +156,7 @@ func getRunScriptActionSchema() *schema.Schema {
addPackagesSchema(element, false)
addWorkerPoolSchema(element)
addWorkerPoolVariableSchema(element)
addGitDependencySchema(element)

element.Schema["script_body"] = &schema.Schema{
Optional: true,
Expand Down
15 changes: 1 addition & 14 deletions octopusdeploy/schema_deployment_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package octopusdeploy

import (
"fmt"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/gitdependencies"
"strconv"
"strings"

Expand Down Expand Up @@ -129,11 +128,6 @@ func flattenAction(action *deployments.DeploymentAction) map[string]interface{}
flattenedAction["package"] = flattenedPackageReferences
}

if len(action.GitDependencies) > 0 {
fmt.Printf("%+v\n", action.GitDependencies)
flattenedAction["git_dependency"] = flattenGitDependency(action.GitDependencies[0])
}

return flattenedAction
}

Expand All @@ -144,7 +138,6 @@ func getDeploymentActionSchema() *schema.Schema {
addWorkerPoolSchema(element)
addWorkerPoolVariableSchema(element)
addPackagesSchema(element, false)
addGitDependencySchema(element)

return actionSchema
}
Expand Down Expand Up @@ -223,8 +216,7 @@ func getActionSchema() (*schema.Schema, *schema.Resource) {
Optional: true,
Type: schema.TypeList,
},
"git_dependency": getGitDependencySchema(false),
"id": getIDSchema(),
"id": getIDSchema(),
"is_disabled": {
Default: false,
Description: "Indicates the disabled status of this deployment action.",
Expand Down Expand Up @@ -432,11 +424,6 @@ func expandAction(flattenedAction map[string]interface{}) *deployments.Deploymen
action.Properties["Octopus.Action.EnabledFeatures"] = core.NewPropertyValue(strings.Join(getSliceFromTerraformTypeList(v), ","), false)
}

if v, ok := flattenedAction["git_dependency"]; ok {
action.GitDependencies = []*gitdependencies.GitDependency{expandGitDependency(v.(*schema.Set))}
action.Properties["Octopus.Action.GitRepository.Source"] = core.NewPropertyValue("External", false)
}

if v, ok := flattenedAction["is_disabled"]; ok {
action.IsDisabled = v.(bool)
}
Expand Down
57 changes: 11 additions & 46 deletions octopusdeploy/schema_git_dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,19 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func flattenGitDependency(gitDependency *gitdependencies.GitDependency) *schema.Set {
//if gitDependency == nil {
// return nil
//}
//fmt.Printf("%+v\n", gitDependency)
//
//return map[string]interface{}{
// "repository_uri": gitDependency.RepositoryUri,
// "default_branch": gitDependency.DefaultBranch,
// "git_credential_type": gitDependency.GitCredentialType,
// "file_path_filters": gitDependency.FilePathFilters,
// "git_credential_id": gitDependency.GitCredentialId,
// "step_package_inputs_reference_id": gitDependency.StepPackageInputsReferenceId,
//}
flattened := new(schema.Set)
flattened.Add(map[string]interface{}{
func flattenGitDependency(gitDependency *gitdependencies.GitDependency) []interface{} {
if gitDependency == nil {
return nil
}

return []interface{}{map[string]interface{}{
"repository_uri": gitDependency.RepositoryUri,
"default_branch": gitDependency.DefaultBranch,
"git_credential_type": gitDependency.GitCredentialType,
"file_path_filters": gitDependency.FilePathFilters,
"file_path_filters": flattenArray(gitDependency.FilePathFilters),
"git_credential_id": gitDependency.GitCredentialId,
"step_package_inputs_reference_id": gitDependency.StepPackageInputsReferenceId,
})
return flattened
}}
}

func expandGitDependency(set *schema.Set) *gitdependencies.GitDependency {
Expand All @@ -39,15 +28,6 @@ func expandGitDependency(set *schema.Set) *gitdependencies.GitDependency {

flattenedMap := set.List()[0].(map[string]interface{})

//if len(flattenedValues) == 0 || flattenedValues[0] == nil {
// return nil
//}
//
//flattenedMap := flattenedValues[0].(map[string]interface{})
//if len(flattenedMap) == 0 {
// return nil
//}

gitDependency := &gitdependencies.GitDependency{}

if repositoryUri := flattenedMap["repository_uri"]; repositoryUri != nil {
Expand All @@ -62,9 +42,9 @@ func expandGitDependency(set *schema.Set) *gitdependencies.GitDependency {
gitDependency.GitCredentialType = gitCredentialType.(string)
}

//if filePathFilters := flattenedMap["file_path_filters"]; filePathFilters != nil {
// gitDependency.FilePathFilters = filePathFilters.([]string)
//}
if filePathFilters := flattenedMap["file_path_filters"]; filePathFilters != nil {
gitDependency.FilePathFilters = expandArray(filePathFilters.([]interface{}))
}

if gitCredentialId := flattenedMap["git_credential_id"]; gitCredentialId != nil {
gitDependency.GitCredentialId = gitCredentialId.(string)
Expand Down Expand Up @@ -128,19 +108,4 @@ func getGitDependencySchema(required bool) *schema.Schema {

func addGitDependencySchema(element *schema.Resource) {
element.Schema["git_dependency"] = getGitDependencySchema(false)
//
//gitDependenciesElementSchema := element.Schema["git_dependencies"].Elem.(*schema.Resource).Schema
//
//gitDependenciesElementSchema["name"] = &schema.Schema{
// Description: "The name of the package",
// Required: true,
// Type: schema.TypeString,
//}
//
//packageElementSchema["extract_during_deployment"] = &schema.Schema{
// Computed: true,
// Description: "Whether to extract the package during deployment",
// Optional: true,
// Type: schema.TypeBool,
//}
}

0 comments on commit 4aa10f2

Please sign in to comment.