-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from OctopusDeploy/drift
Upstream changes from private octopus branch.
- Loading branch information
Showing
40 changed files
with
2,110 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.