Skip to content

Commit

Permalink
Add kubernetes_agent_update_behavior to machine_update_policy (#640)
Browse files Browse the repository at this point in the history
* Add kubernetes_agent_update_behavior to machine_update_policy

* Update comments for machine update policy
  • Loading branch information
APErebus authored Jun 3, 2024
1 parent f860c5a commit 7771378
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 18 deletions.
1 change: 1 addition & 0 deletions docs/data-sources/machine_policies.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Read-Only:
Read-Only:

- `calamari_update_behavior` (String)
- `kubernetes_agent_update_behavior` (String)
- `tentacle_update_account_id` (String)
- `tentacle_update_behavior` (String)

Expand Down
7 changes: 4 additions & 3 deletions docs/resources/machine_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ Optional:

Optional:

- `calamari_update_behavior` (String)
- `tentacle_update_account_id` (String)
- `tentacle_update_behavior` (String)
- `calamari_update_behavior` (String) The behaviour of how Calamari is updated. Valid values are `UpdateAlways`, `UpdateOnDeployment` and `UpdateOnNewMachine`.
- `kubernetes_agent_update_behavior` (String) The behaviour of how Kubernetes agent machines are updated. Valid values are `NeverUpdate` and `Update`.
- `tentacle_update_account_id` (String) The Account ID to perform any Tentacle updates under.
- `tentacle_update_behavior` (String) The behaviour of how Tentacle machines are updated. Valid values are `NeverUpdate` and `Update`.


4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/OctopusDeploy/terraform-provider-octopusdeploy
go 1.21

require (
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.42.2
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.43.0
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240502041300-f71244db277d
github.com/google/uuid v1.6.0
github.com/gruntwork-io/terratest v0.41.11
Expand All @@ -16,6 +16,7 @@ require (
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea
golang.org/x/text v0.13.0
k8s.io/utils v0.0.0-20230505201702-9f6742963106
software.sslmate.com/src/go-pkcs12 v0.4.0
)

require (
Expand Down Expand Up @@ -158,5 +159,4 @@ require (
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
software.sslmate.com/src/go-pkcs12 v0.4.0 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8=
github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYxPRqGcpAD9w=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.42.2 h1:UuDW2UkW9akLuuYE3kUf/irOr8NaegHw8qaBvQ1SRV0=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.42.2/go.mod h1:GZmFu6LmN8Yg0tEoZx3ytk9FnaH+84cWm7u5TdWZC6E=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.43.0 h1:fYwGBqG88xy3qHp5j1ySCztdqfw2NLfg2yp0N3XcBYg=
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.43.0/go.mod h1:GZmFu6LmN8Yg0tEoZx3ytk9FnaH+84cWm7u5TdWZC6E=
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240502041300-f71244db277d h1:E0Rm52/XBlVzdkHET/+Js1FVVgf5/0oRk1tNkI4jcyk=
github.com/OctopusSolutionsEngineering/OctopusTerraformTestFramework v0.0.0-20240502041300-f71244db277d/go.mod h1:Nyg+7cyTrSQ/lMIy5YY1UdJekRuoMWf4uHIPfaGmgTM=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ=
Expand Down
12 changes: 8 additions & 4 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1994,12 +1994,16 @@ func TestMachinePolicyResource(t *testing.T) {
t.Fatal("The machine policy must have a MachineHealthCheckPolicy.HealthCheckInterval of \"00:10:00\" (was \"" + fmt.Sprint(resource.MachineHealthCheckPolicy.HealthCheckInterval) + "\")")
}

if resource.MachineUpdatePolicy.CalamariUpdateBehavior != "UpdateOnDeployment" {
t.Fatal("The machine policy must have a MachineUpdatePolicy.CalamariUpdateBehavior of \"UpdateOnDeployment\" (was \"" + resource.MachineUpdatePolicy.CalamariUpdateBehavior + "\")")
if resource.MachineUpdatePolicy.CalamariUpdateBehavior != "UpdateAlways" {
t.Fatal("The machine policy must have a MachineUpdatePolicy.CalamariUpdateBehavior of \"UpdateAlways\" (was \"" + resource.MachineUpdatePolicy.CalamariUpdateBehavior + "\")")
}

if resource.MachineUpdatePolicy.TentacleUpdateBehavior != "NeverUpdate" {
t.Fatal("The machine policy must have a MachineUpdatePolicy.TentacleUpdateBehavior of \"NeverUpdate\" (was \"" + resource.MachineUpdatePolicy.CalamariUpdateBehavior + "\")")
if resource.MachineUpdatePolicy.TentacleUpdateBehavior != "Update" {
t.Fatal("The machine policy must have a MachineUpdatePolicy.TentacleUpdateBehavior of \"Update\" (was \"" + resource.MachineUpdatePolicy.CalamariUpdateBehavior + "\")")
}

if resource.MachineUpdatePolicy.KubernetesAgentUpdateBehavior != "NeverUpdate" {
t.Fatal("The machine policy must have a MachineUpdatePolicy.KubernetesAgentUpdateBehavior of \"NeverUpdate\" (was \"" + resource.MachineUpdatePolicy.CalamariUpdateBehavior + "\")")
}

return nil
Expand Down
28 changes: 23 additions & 5 deletions octopusdeploy/schema_machine_update_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func expandMachineUpdatePolicy(values interface{}) *machinepolicies.MachineUpdat
machineUpdatePolicy.TentacleUpdateBehavior = v.(string)
}

if v, ok := flattenedMap["kubernetes_agent_update_behavior"]; ok {
machineUpdatePolicy.KubernetesAgentUpdateBehavior = v.(string)
}

return machineUpdatePolicy
}

Expand All @@ -40,9 +44,10 @@ func flattenMachineUpdatePolicy(machineUpdatePolicy *machinepolicies.MachineUpda
}

return []interface{}{map[string]interface{}{
"calamari_update_behavior": machineUpdatePolicy.CalamariUpdateBehavior,
"tentacle_update_account_id": machineUpdatePolicy.TentacleUpdateAccountID,
"tentacle_update_behavior": machineUpdatePolicy.TentacleUpdateBehavior,
"calamari_update_behavior": machineUpdatePolicy.CalamariUpdateBehavior,
"tentacle_update_account_id": machineUpdatePolicy.TentacleUpdateAccountID,
"tentacle_update_behavior": machineUpdatePolicy.TentacleUpdateBehavior,
"kubernetes_agent_update_behavior": machineUpdatePolicy.KubernetesAgentUpdateBehavior,
}}
}

Expand All @@ -57,10 +62,12 @@ func getMachineUpdatePolicySchema() map[string]*schema.Schema {
"UpdateOnDeployment",
"UpdateOnNewMachine",
}, false)),
Description: "The behaviour of how Calamari is updated. Valid values are `UpdateAlways`, `UpdateOnDeployment` and `UpdateOnNewMachine`.",
},
"tentacle_update_account_id": {
Optional: true,
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Description: "The Account ID to perform any Tentacle updates under.",
},
"tentacle_update_behavior": {
Default: "NeverUpdate",
Expand All @@ -70,6 +77,17 @@ func getMachineUpdatePolicySchema() map[string]*schema.Schema {
"NeverUpdate",
"Update",
}, false)),
Description: "The behaviour of how Tentacle machines are updated. Valid values are `NeverUpdate` and `Update`.",
},
"kubernetes_agent_update_behavior": {
Default: "Update",
Optional: true,
Type: schema.TypeString,
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{
"NeverUpdate",
"Update",
}, false)),
Description: "The behaviour of how Kubernetes agent machines are updated. Valid values are `NeverUpdate` and `Update`.",
},
}
}
5 changes: 3 additions & 2 deletions terraform/27-machinepolicy/machinepolicy.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ resource "octopusdeploy_machine_policy" "machinepolicy_testing" {
}

machine_update_policy {
calamari_update_behavior = "UpdateOnDeployment"
tentacle_update_behavior = "NeverUpdate"
calamari_update_behavior = "UpdateAlways"
tentacle_update_behavior = "Update"
kubernetes_agent_update_behavior = "NeverUpdate"
}
}

0 comments on commit 7771378

Please sign in to comment.