Skip to content

Commit

Permalink
Merge pull request #16 from OctopusDeploy/drift
Browse files Browse the repository at this point in the history
Upstream changes from private octopus branch.
  • Loading branch information
jeff-french authored Apr 24, 2019
2 parents 60380e5 + f4b26b3 commit e4f5484
Show file tree
Hide file tree
Showing 40 changed files with 2,110 additions and 75 deletions.
6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
module github.com/OctopusDeploy/terraform-provider-octopusdeploy

require (
github.com/OctopusDeploy/go-octopusdeploy v0.0.0-20190101071024-032701337fa6
github.com/OctopusDeploy/go-octopusdeploy v1.0.0
github.com/apparentlymart/go-cidr v1.0.0 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/aws/aws-sdk-go v1.15.53 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/dghubble/sling v1.1.0 // indirect
github.com/go-ini/ini v1.38.3 // indirect
github.com/go-playground/locales v0.12.1 // indirect
github.com/go-playground/universal-translator v0.16.0 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.0 // indirect
github.com/hashicorp/go-getter v0.0.0-20180809191950-4bda8fa99001 // indirect
Expand Down Expand Up @@ -39,7 +36,6 @@ require (
github.com/zclconf/go-cty v0.0.0-20181011210859-1f835aab79c2 // indirect
google.golang.org/genproto v0.0.0-20181004005441-af9cb2a35e7f // indirect
google.golang.org/grpc v1.15.0 // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/go-playground/validator.v9 v9.21.0 // indirect
gopkg.in/ini.v1 v1.42.0 // indirect
)
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/DHowett/go-plist v0.0.0-20180609054337-500bd5b9081b/go.mod h1:5paT5ZDrOm8eAJPem2Bd+q3FTi3Gxm/U4tb2tH8YIUQ=
github.com/OctopusDeploy/go-octopusdeploy v0.0.0-20190101071024-032701337fa6 h1:KZHt2zDW22EbhfTvsZLzWRzn/5Kb8Jhnnk27wJQr/lY=
github.com/OctopusDeploy/go-octopusdeploy v0.0.0-20190101071024-032701337fa6/go.mod h1:MLm+0h6BI+oIU1ucONLo9AiN3YklMo6dzc7aAH2bgYo=
github.com/OctopusDeploy/go-octopusdeploy v1.0.0 h1:JweXaa6zTIv8NOpLDLomzceVGV+v4L/zrOHN5DOZykc=
github.com/OctopusDeploy/go-octopusdeploy v1.0.0/go.mod h1:WyBvcyhFPMULbZwFFWOmt6/irqrfZ/WqCy7ufa8/CGE=
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/apparentlymart/go-cidr v1.0.0 h1:lGDvXx8Lv9QHjrAVP7jyzleG4F9+FkRhJcEsDFxeb8w=
Expand All @@ -22,6 +22,7 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dghubble/sling v1.1.0 h1:DLu20Bq2qsB9cI5Hldaxj+TMPEaPpPE8IR2kvD22Atg=
Expand All @@ -45,6 +46,7 @@ github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
Expand Down Expand Up @@ -125,6 +127,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/posener/complete v1.1.2 h1:fS9GkqLN9DIpHg9j3fAPHdj5P3LhzxuoSybQd1v26IE=
github.com/posener/complete v1.1.2/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
Expand Down Expand Up @@ -170,6 +173,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
gopkg.in/go-playground/validator.v9 v9.19.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=
gopkg.in/go-playground/validator.v9 v9.21.0 h1:wSDJGBpQBYC1wLpVnGHLmshm2JicoSNdrb38Zj+8yHI=
gopkg.in/go-playground/validator.v9 v9.21.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=
gopkg.in/ini.v1 v1.42.0 h1:7N3gPTt50s8GuLortA00n8AqRTk75qOP98+mTPpgzRk=
Expand Down
34 changes: 34 additions & 0 deletions octopusdeploy/apply_terraform_action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package octopusdeploy

import (
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform/helper/schema"
)

func getApplyTerraformActionSchema() *schema.Schema {

actionSchema, element := getCommonDeploymentActionSchema()
addExecutionLocationSchema(element)
addPrimaryPackageSchema(element, false)

element.Schema["additional_init_params"] = &schema.Schema{
Type: schema.TypeString,
Description: "Additional parameters passed to the init command",
Optional: true,
}

return actionSchema
}

func buildApplyTerraformActionResource(tfAction map[string]interface{}) octopusdeploy.DeploymentAction {
resource := buildDeploymentActionResource(tfAction)

resource.ActionType = "Octopus.TerraformApply"
resource.Properties["Octopus.Action.Terraform.AdditionalInitParams"] = tfAction["additional_init_params"].(string)
resource.Properties["Octopus.Action.Terraform.AllowPluginDownloads"] = "True"
resource.Properties["Octopus.Action.Terraform.ManagedAccount"] = "None"

resource.Properties["Octopus.Action.Script.ScriptSource"] = "Package"

return resource
}
65 changes: 65 additions & 0 deletions octopusdeploy/apply_terraform_action_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package octopusdeploy

import (
"fmt"
"testing"

"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccOctopusDeployApplyTerraformAction(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckOctopusDeployDeploymentProcessDestroy,
Steps: []resource.TestStep{
{
Config: testAccApplyTerraformAction(),
Check: resource.ComposeTestCheckFunc(
testAccCheckApplyTerraformAction(),
),
},
},
})
}

func testAccApplyTerraformAction() string {
return testAccBuildTestAction(`
apply_terraform_action {
name = "Apply Terraform"
run_on_server = true
primary_package {
package_id = "MyPackage"
feed_id = "feeds-builtin"
}
additional_init_params = "Init params"
}
`)
}

func testAccCheckApplyTerraformAction() resource.TestCheckFunc {
return func(s *terraform.State) error {
client := testAccProvider.Meta().(*octopusdeploy.Client)

process, err := getDeploymentProcess(s, client)
if err != nil {
return err
}

action := process.Steps[0].Actions[0]

if action.ActionType != "Octopus.TerraformApply" {
return fmt.Errorf("Action type is incorrect: %s", action.ActionType)
}

if action.Properties["Octopus.Action.Terraform.AdditionalInitParams"] != "Init params" {
return fmt.Errorf("AdditionalInitParams is incorrect: %s", action.Properties["Octopus.Action.Terraform.AdditionalInitParams"])
}

return nil
}
}
5 changes: 5 additions & 0 deletions octopusdeploy/data_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func dataEnvironment() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"allow_dynamic_infrastructure": {
Type: schema.TypeBool,
Computed: true,
},
},
}
}
Expand All @@ -47,6 +51,7 @@ func dataEnvironmentReadByName(d *schema.ResourceData, m interface{}) error {
d.Set("name", env.Name)
d.Set("description", env.Description)
d.Set("use_guided_failure", env.UseGuidedFailure)
d.Set("allow_dynamic_infrastructure", env.AllowDynamicInfrastructure)

return nil
}
61 changes: 61 additions & 0 deletions octopusdeploy/deploy_kubernetes_secret_action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package octopusdeploy

import (
"encoding/json"
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform/helper/schema"
)

func getDeployKubernetesSecretActionSchema() *schema.Schema {

actionSchema, element := getCommonDeploymentActionSchema()
addExecutionLocationSchema(element)
element.Schema["secret_name"] = &schema.Schema{
Type: schema.TypeString,
Description: "The name of the secret resource",
Required: true,
}

element.Schema["secret_values"] = &schema.Schema{
Type: schema.TypeList,
Required: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Type: schema.TypeString,
Required: true,
},
"value": {
Type: schema.TypeString,
Required: true,
},
},
},
}

return actionSchema
}

func buildDeployKubernetesSecretActionResource(tfAction map[string]interface{}) octopusdeploy.DeploymentAction {
resource := buildDeploymentActionResource(tfAction)

resource.ActionType = "Octopus.KubernetesDeploySecret"

resource.Properties["Octopus.Action.KubernetesContainers.SecretName"] = tfAction["secret_name"].(string)

if tfSecretValues, ok := tfAction["secret_values"]; ok {

secretValues := make(map[string]string)

for _, tfSecretValue := range tfSecretValues.([]interface{}) {
tfSecretValueTyped := tfSecretValue.(map[string]interface{})
secretValues[tfSecretValueTyped["key"].(string)] = tfSecretValueTyped["value"].(string)
}

j, _ := json.Marshal(secretValues)

resource.Properties["Octopus.Action.KubernetesContainers.SecretValues"] = string(j)
}

return resource
}
73 changes: 73 additions & 0 deletions octopusdeploy/deploy_kubernetes_secret_action_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package octopusdeploy

import (
"fmt"
"testing"

"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)

func TestAccOctopusDeployDeployKuberentesSecretAction(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckOctopusDeployDeploymentProcessDestroy,
Steps: []resource.TestStep{
{
Config: testAccDeployKuberentesSecretAction(),
Check: resource.ComposeTestCheckFunc(
testAccCheckDeployKuberentesSecretAction(),
),
},
},
})
}

func testAccDeployKuberentesSecretAction() string {
return testAccBuildTestAction(`
deploy_kubernetes_secret_action {
name = "Run Script"
run_on_server = true
secret_name = "secret name"
secret_values = [{
key = "key"
value = "value"
}, {
key = "key1"
value = "value1"
}
]
}
`)
}

func testAccCheckDeployKuberentesSecretAction() resource.TestCheckFunc {
return func(s *terraform.State) error {
client := testAccProvider.Meta().(*octopusdeploy.Client)

process, err := getDeploymentProcess(s, client)
if err != nil {
return err
}

action := process.Steps[0].Actions[0]

if action.ActionType != "Octopus.KubernetesDeploySecret" {
return fmt.Errorf("Action type is incorrect: %s", action.ActionType)
}

if action.Properties["Octopus.Action.KubernetesContainers.SecretName"] != "secret name" {
return fmt.Errorf("SecretName is incorrect: %s", action.Properties["Octopus.Action.KubernetesContainers.SecretName"])
}

if action.Properties["Octopus.Action.KubernetesContainers.SecretValues"] != `{"key":"value","key1":"value1"}` {
return fmt.Errorf("SecretName is incorrect: %s", action.Properties["Octopus.Action.KubernetesContainers.SecretName"])
}

return nil
}
}
4 changes: 2 additions & 2 deletions octopusdeploy/deploy_windows_service_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestAccOctopusDeployWindowsServiceFeature(t *testing.T) {
}

func testAccDeployWindowsServiceAction() string {
return testAccBuildTestActionTerraform(`
return testAccBuildTestAction(`
deploy_windows_service_action {
name = "Test"
Expand All @@ -65,7 +65,7 @@ func testAccDeployWindowsServiceAction() string {
}

func testAccWindowsServiceFeature() string {
return testAccBuildTestActionTerraform(`
return testAccBuildTestAction(`
deploy_package_action {
name = "Test"
Expand Down
10 changes: 10 additions & 0 deletions octopusdeploy/deployment_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
func getDeploymentActionSchema() *schema.Schema {
actionSchema, element := getCommonDeploymentActionSchema()
addExecutionLocationSchema(element)
addActionTypeSchema(element)
addExecutionLocationSchema(element)
element.Schema["action_type"] = &schema.Schema{
Type: schema.TypeString,
Description: "The type of action",
Expand Down Expand Up @@ -94,6 +96,14 @@ func addExecutionLocationSchema(element *schema.Resource) {
}
}

func addActionTypeSchema(element *schema.Resource) {
element.Schema["action_type"] = &schema.Schema{
Type: schema.TypeString,
Description: "The type of action",
Required: true,
}
}

func addWorkerPoolSchema(element *schema.Resource) {
element.Schema["worker_pool_id"] = &schema.Schema{
Type: schema.TypeString,
Expand Down
15 changes: 14 additions & 1 deletion octopusdeploy/deployment_process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ func testAccDeploymentProcessBasic() string {
}
package {
name = "ThePackage2"
package_id = "MyPackage2"
feed_id = "feeds-builtin"
acquisition_location = "NotAcquired"
extract_during_deployment = true
property {
key = "WhatIsThis"
value = "Dunno"
}
}
property {
key = "Octopus.Action.Script.ScriptFileName"
value = "Run.ps132"
Expand Down Expand Up @@ -117,7 +130,7 @@ func testAccDeploymentProcessBasic() string {
`
}

func testAccBuildTestActionTerraform(action string) string {
func testAccBuildTestAction(action string) string {
return fmt.Sprintf(`
resource "octopusdeploy_lifecycle" "test" {
name = "Test Lifecycle"
Expand Down
Loading

0 comments on commit e4f5484

Please sign in to comment.