From 4aa10f2b3027086c879f82067b28984b0103867f Mon Sep 17 00:00:00 2001 From: Travis Leeden Date: Wed, 10 Jan 2024 14:16:52 +1000 Subject: [PATCH] Fixed file path filters and made git sourcing specific to run script action for the moment --- octopusdeploy/schema_action_run_script.go | 11 +++++ octopusdeploy/schema_deployment_action.go | 15 +----- octopusdeploy/schema_git_dependency.go | 57 +++++------------------ 3 files changed, 23 insertions(+), 60 deletions(-) diff --git a/octopusdeploy/schema_action_run_script.go b/octopusdeploy/schema_action_run_script.go index 16bfdf606..3e6b18c95 100644 --- a/octopusdeploy/schema_action_run_script.go +++ b/octopusdeploy/schema_action_run_script.go @@ -1,6 +1,7 @@ package octopusdeploy import ( + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/gitdependencies" "strconv" "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core" @@ -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 } @@ -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 @@ -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, diff --git a/octopusdeploy/schema_deployment_action.go b/octopusdeploy/schema_deployment_action.go index 844b45b17..62ff296c4 100644 --- a/octopusdeploy/schema_deployment_action.go +++ b/octopusdeploy/schema_deployment_action.go @@ -2,7 +2,6 @@ package octopusdeploy import ( "fmt" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/gitdependencies" "strconv" "strings" @@ -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 } @@ -144,7 +138,6 @@ func getDeploymentActionSchema() *schema.Schema { addWorkerPoolSchema(element) addWorkerPoolVariableSchema(element) addPackagesSchema(element, false) - addGitDependencySchema(element) return actionSchema } @@ -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.", @@ -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) } diff --git a/octopusdeploy/schema_git_dependency.go b/octopusdeploy/schema_git_dependency.go index 646c2741a..eda86e723 100644 --- a/octopusdeploy/schema_git_dependency.go +++ b/octopusdeploy/schema_git_dependency.go @@ -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 { @@ -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 { @@ -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) @@ -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, - //} }