Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Deployment process migration #741

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bd37c7a
wip
benPearce1 Jul 18, 2024
e0fb641
wip
benPearce1 Jul 26, 2024
7cd15a1
wip
benPearce1 Jul 29, 2024
b8c7c9e
Merge branch 'main' into bp/deployment-process-migration
benPearce1 Jul 31, 2024
3218bdd
progress
benPearce1 Aug 4, 2024
2263c83
tweaks
benPearce1 Aug 6, 2024
bdd667b
it sort of works
benPearce1 Aug 6, 2024
8c1a537
Merge branch 'main' into bp/deployment-process-migration
benPearce1 Aug 6, 2024
e011162
some extra mapping, just run the tests please
benPearce1 Aug 7, 2024
5e7d88a
mapped a few more actions
benPearce1 Aug 7, 2024
6c3eb29
commiting current state
benPearce1 Aug 7, 2024
60d454f
refactored each action mapper to own mapper implementation
benPearce1 Aug 7, 2024
ee447df
renamed package name for action mappers
benPearce1 Aug 7, 2024
30455cb
Merge branch 'main' into bp/deployment-process-migration
benPearce1 Aug 7, 2024
ba2fbe5
merge issue from main
benPearce1 Aug 7, 2024
2f68fb9
wrong resource type name
benPearce1 Aug 7, 2024
abf7c35
small fixes
benPearce1 Aug 7, 2024
3aab479
wip
benPearce1 Aug 12, 2024
56cb810
Merge branch 'main' into bp/deployment-process-migration
benPearce1 Aug 13, 2024
d42f532
fix import
benPearce1 Aug 13, 2024
614c2d7
restored previous implementation
benPearce1 Aug 13, 2024
a6594fe
added validation for Extract property to package schema
benPearce1 Aug 13, 2024
e4f0e5c
updated test
benPearce1 Aug 13, 2024
3708cae
Merge branch 'main' into huy/deployment-process-migration
HuyPhanNguyen Aug 15, 2024
3fab218
Fix issue included_library_variable_sets: was cty.ListValEmpty(cty.St…
HuyPhanNguyen Aug 15, 2024
22a69ff
try trigger build
HuyPhanNguyen Aug 15, 2024
43bc189
Revert "Fix issue included_library_variable_sets: was cty.ListValEmpt…
HuyPhanNguyen Aug 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion octopusdeploy/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func Provider() *schema.Provider {
"octopusdeploy_certificate": resourceCertificate(),
"octopusdeploy_channel": resourceChannel(),
"octopusdeploy_cloud_region_deployment_target": resourceCloudRegionDeploymentTarget(),
"octopusdeploy_deployment_process": resourceDeploymentProcess(),
"octopusdeploy_dynamic_worker_pool": resourceDynamicWorkerPool(),
"octopusdeploy_gcp_account": resourceGoogleCloudPlatformAccount(),
"octopusdeploy_kubernetes_agent_deployment_target": resourceKubernetesAgentDeploymentTarget(),
Expand Down
47 changes: 33 additions & 14 deletions octopusdeploy/resource_deployment_process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func TestAccOctopusDeployDeploymentProcessWithImpliedPrimaryPackage(t *testing.T
resource.TestCheckResourceAttr(resourceName, "step.0.start_trigger", "StartAfterPrevious"),
resource.TestCheckResourceAttr(resourceName, "step.0.action.#", "1"),
resource.TestCheckResourceAttr(resourceName, "step.0.action.0.action_type", "Octopus.TransferPackage"),
resource.TestCheckResourceAttr(resourceName, "step.0.action.0.container.#", "1"),
resource.TestCheckResourceAttr(resourceName, "step.0.action.0.container.#", "0"),
resource.TestCheckNoResourceAttr(resourceName, "step.0.action.0.channels.0"),
resource.TestCheckResourceAttr(resourceName, "step.0.action.0.condition", "Success"),
resource.TestCheckResourceAttr(resourceName, "step.0.action.0.environments.#", "0"),
Expand Down Expand Up @@ -206,9 +206,9 @@ func testAccDeploymentProcessBasic(localName string) string {
window_size = "5"

run_script_action {
// channels = ["Channels-1"]
// environments = ["Environments-1"]
// excluded_environments = ["Environments-2"]
//channels = ["Channels-1"]
//environments = ["Environments-1"]
//excluded_environments = ["Environments-2"]
is_disabled = false
is_required = true
name = "Test"
Expand All @@ -217,11 +217,18 @@ func testAccDeploymentProcessBasic(localName string) string {
script_source = "Package"
tenant_tags = ["tag/tag"]
sort_order = 1
container {
feed_id = "Feeds-123"
image = "blah"
}

primary_package {
acquisition_location = "Server"
feed_id = "feeds-builtin"
package_id = "MyPackage"
properties = {
"Extract" = "true"
}
}

package {
Expand All @@ -230,6 +237,9 @@ func testAccDeploymentProcessBasic(localName string) string {
feed_id = "feeds-builtin"
name = "ThePackage"
package_id = "MyPackage"
properties = {
"Extract" = "true"
}
}

package {
Expand All @@ -238,21 +248,29 @@ func testAccDeploymentProcessBasic(localName string) string {
feed_id = "feeds-builtin"
name = "ThePackage2"
package_id = "MyPackage2"
properties = {
"Extract" = "true"
}
}

action_template {
id = "actiontemplates-1"
version = "1.2.3"
}
}
}

step {
name = "Step2"
start_trigger = "StartWithPrevious"
target_roles = ["WebServer"]

run_script_action {
name = "Step2"
sort_order = 1
run_on_server = true
script_body = "Write-Host 'hi'"
}
name = "Step2"
start_trigger = "StartWithPrevious"
target_roles = ["WebServer"]
run_script_action {
name = "Step2"
sort_order = 1
run_on_server = true
script_body = "Write-Host 'hi'"
}
}
}`, localName, projectLocalName)
}
Expand Down Expand Up @@ -298,6 +316,7 @@ func testAccProcessWithImpliedPrimaryPackage(spaceID string, localName string) s

properties = {
"SelectionMode" = "immediate"
"Extract" = "true"
}
}

Expand Down
3 changes: 3 additions & 0 deletions octopusdeploy/schema_action_run_kubectl_script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ func testAccRunKubectlScriptAction() string {
primary_package {
package_id = "MyPackage"
feed_id = "feeds-builtin"
properties = {
"Extract" = "true"
}
}

script_file_name = "Test.ps1"
Expand Down
1 change: 1 addition & 0 deletions octopusdeploy/schema_deployment_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func flattenDeploymentSteps(deploymentSteps []*deployments.DeploymentStep) []map
}

action := fp(deploymentStep.Actions[i])

action["sort_order"] = i + 1
flattenedDeploymentStep[step_type_name] = append(flattenedDeploymentStep[step_type_name].([]map[string]interface{}), action)
}
Expand Down
1 change: 1 addition & 0 deletions octopusdeploy_framework/framework_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (p *octopusDeployFrameworkProvider) Resources(ctx context.Context) []func()
NewEnvironmentResource,
NewGitCredentialResource,
NewHelmFeedResource,
NewDeploymentProcessResource,
NewArtifactoryGenericFeedResource,
NewGitHubRepositoryFeedResource,
NewAwsElasticContainerRegistryFeedResource,
Expand Down
32 changes: 32 additions & 0 deletions octopusdeploy_framework/mappers/actions/action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package actions

import (
"context"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/deployments"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
)

type Action struct{}

func (a Action) ToState(ctx context.Context, action *deployments.DeploymentAction, newAction map[string]attr.Value) diag.Diagnostics {
diags := mapBaseDeploymentActionToState(ctx, action, newAction)
if diags.HasError() {
return diags
}

newAction["action_type"] = types.StringValue(action.ActionType)
mapPropertyToStateBool(action, newAction, "Octopus.Action.RunOnServer", "run_on_server", false)
newAction["worker_pool_id"] = types.StringValue(action.WorkerPool)
newAction["worker_pool_variable"] = types.StringValue(action.WorkerPoolVariable)
return nil
}

func (a Action) ToDeploymentAction(actionAttribute attr.Value) *deployments.DeploymentAction {

return GetBaseAction(actionAttribute)

}

var _ MappableAction = &Action{}
13 changes: 13 additions & 0 deletions octopusdeploy_framework/mappers/actions/action_mapper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package actions

import (
"context"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/deployments"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
)

type MappableAction interface {
ToState(ctx context.Context, action *deployments.DeploymentAction, newAction map[string]attr.Value) diag.Diagnostics
ToDeploymentAction(actionAttribute attr.Value) *deployments.DeploymentAction
}
39 changes: 39 additions & 0 deletions octopusdeploy_framework/mappers/actions/kubectl_script.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package actions

import (
"context"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/deployments"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
)

type KubectlScriptActionMapper struct{}

func (k KubectlScriptActionMapper) ToState(ctx context.Context, action *deployments.DeploymentAction, newAction map[string]attr.Value) diag.Diagnostics {
diag := mapBaseDeploymentActionToState(ctx, action, newAction)
if diag.HasError() {
return diag
}

mapPropertyToStateString(action, newAction, "Octopus.Action.KubernetesContainers.Namespace", "namespace")

return nil
}

func (k KubectlScriptActionMapper) ToDeploymentAction(actionAttribute attr.Value) *deployments.DeploymentAction {
actionAttrs := GetActionAttributes(actionAttribute)
if actionAttrs == nil {
return nil
}

runscriptMapper := RunScriptActionMapper{}
action := runscriptMapper.ToDeploymentAction(actionAttribute)
if action == nil {
return nil
}
action.ActionType = "Octopus.KubernetesRunScript"
mapAttributeToProperty(action, actionAttrs, "namespace", "Octopus.Action.KubernetesContainers.Namespace")
return action
}

var _ MappableAction = &KubectlScriptActionMapper{}
73 changes: 73 additions & 0 deletions octopusdeploy_framework/mappers/actions/kubernetes_secret.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package actions

import (
"context"
"encoding/json"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/deployments"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
)

type KubernetesSecretActionMapper struct{}

var _ MappableAction = &KubernetesSecretActionMapper{}

func (k KubernetesSecretActionMapper) ToState(ctx context.Context, action *deployments.DeploymentAction, newAction map[string]attr.Value) diag.Diagnostics {
diag := mapBaseDeploymentActionToState(ctx, action, newAction)
if diag.HasError() {
return diag
}

mapPropertyToStateBool(action, newAction, "Octopus.Action.RunOnServer", "run_on_server", false)
mapPropertyToStateString(action, newAction, "Octopus.Action.KubernetesContainers.SecretName", "secret_name")
mapPropertyToStateBool(action, newAction, "Octopus.Action.Kubernetes.ResourceStatusCheck", "kubernetes_object_status_check_enabled", false)
newAction["worker_pool_id"] = types.StringValue(action.WorkerPool)
newAction["worker_pool_variable"] = types.StringValue(action.WorkerPoolVariable)

if v, ok := action.Properties["Octopus.Action.KubernetesContainers.SecretValues"]; ok {
var secretKeyValues map[string]string
json.Unmarshal([]byte(v.Value), &secretKeyValues)
mappedSecrets := make(map[string]attr.Value)
for key, value := range secretKeyValues {
mappedSecrets[key] = types.StringValue(value)
}
newAction["secret_values"], diag = types.MapValue(types.StringType, mappedSecrets)
if diag.HasError() {
return diag
}
} else {
newAction["secret_values"] = types.MapNull(types.StringType)
}

return nil
}

func (k KubernetesSecretActionMapper) ToDeploymentAction(actionAttribute attr.Value) *deployments.DeploymentAction {
actionAttrs := GetActionAttributes(actionAttribute)
if actionAttrs == nil {
return nil
}

action := GetBaseAction(actionAttribute)
if action == nil {
return nil
}

mapAttributeToProperty(action, actionAttrs, "secret_name", "Octopus.Action.KubernetesContainers.SecretName")
mapAttributeToProperty(action, actionAttrs, "kubernetes_object_status_check_enabled", "Octopus.Action.Kubernetes.ResourceStatusCheck")

if attrValue, ok := actionAttrs["secret_values"]; ok {
secretValues := attrValue.(types.Map)
mappedValues := make(map[string]string)
for key, value := range secretValues.Elements() {
mappedValues[key] = value.String()
}

j, _ := json.Marshal(secretValues)
action.Properties["Octopus.Action.KubernetesContainers.SecretValues"] = core.NewPropertyValue(string(j), false)
}

return action
}
41 changes: 41 additions & 0 deletions octopusdeploy_framework/mappers/actions/manual_intervention.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package actions

import (
"context"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/deployments"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
)

type ManualInterventionActionMapper struct{}

var _ MappableAction = &ManualInterventionActionMapper{}

func (m *ManualInterventionActionMapper) ToState(ctx context.Context, action *deployments.DeploymentAction, newAction map[string]attr.Value) diag.Diagnostics {
diag := mapBaseDeploymentActionToState(ctx, action, newAction)
if diag.HasError() {
return diag
}

mapPropertyToStateString(action, newAction, "Octopus.Action.Manual.Instructions", "instructions")
mapPropertyToStateString(action, newAction, "Octopus.Action.Manual.ResponsibleTeamIds", "responsible_teams")

return nil
}

func (m *ManualInterventionActionMapper) ToDeploymentAction(actionAttribute attr.Value) *deployments.DeploymentAction {
actionAttrs := GetActionAttributes(actionAttribute)
if actionAttrs == nil {
return nil
}

action := GetBaseAction(actionAttribute)
if action == nil {
return nil
}

mapAttributeToProperty(action, actionAttrs, "instructions", "Octopus.Action.Manual.Instructions")
mapAttributeToProperty(action, actionAttrs, "responsible_teams", "Octopus.Action.Manual.ResponsibleTeamIds")

return action
}
59 changes: 59 additions & 0 deletions octopusdeploy_framework/mappers/actions/package.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package actions

import (
"context"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/deployments"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"strings"
)

type PackageActionMapper struct{}

func (p PackageActionMapper) ToState(ctx context.Context, action *deployments.DeploymentAction, newAction map[string]attr.Value) diag.Diagnostics {
diag := mapBaseDeploymentActionToState(ctx, action, newAction)
if diag.HasError() {
return diag
}

if v, ok := action.Properties["Octopus.Action.EnabledFeatures"]; ok {
if strings.Contains(v.Value, "Octopus.Features.WindowsService") {
attrs := make(map[string]attr.Value)
mapWindowsServicePropertiesToState(action, attrs)
list := make([]attr.Value, 1)
list[0] = types.ObjectValueMust(getWindowsServiceAttrTypes(), attrs)
newAction["windows_service"] = types.ListValueMust(types.ObjectType{AttrTypes: getWindowsServiceAttrTypes()}, list)
} else {
newAction["windows_service"] = types.ListNull(types.ObjectType{AttrTypes: getWindowsServiceAttrTypes()})
}
}

return nil
}

func (p PackageActionMapper) ToDeploymentAction(actionAttribute attr.Value) *deployments.DeploymentAction {
actionAttrs := GetActionAttributes(actionAttribute)
if actionAttrs == nil {
return nil
}

action := GetBaseAction(actionAttribute)
if action == nil {
return nil
}

action.ActionType = "Octopus.TentaclePackage"

if v, ok := actionAttrs["windows_service"]; ok {
list := v.(types.List).Elements()
for _, item := range list {
mapWindowsServiceProperties(action, item.(types.Object).Attributes())
return action
}
}

return action
}

var _ MappableAction = &PackageActionMapper{}
Loading
Loading