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

Cannot create octopusdeploy_machine_policy with or without kubernetes_agent_update_behavior #830

Open
bprathap104 opened this issue Nov 30, 2024 · 4 comments

Comments

@bprathap104
Copy link

bprathap104 commented Nov 30, 2024

Describe the bug
The following error is thrown when trying to create an octopusdeploy_machine_policy with kubernetes_agent_update_behavior :

Error: Key: 'MachineUpdatePolicy.KubernetesAgentUpdateBehavior' Error: Field validation for 'KubernetesAgentUpdateBehavior' failed on the required tag.
resource: octopusdeploy_machine_policy

Steps to reproduce
Write Terraform to create a new octopusdeploy_machine_policy with or without kubernetes_agent_update_behavior in machine_update_policy

resource "octopusdeploy_machine_policy" "machinepolicy_testing" {
  name                                               = "Testing"
  description                                        = "test machine policy"
  connection_connect_timeout                         = 60000000000
  connection_retry_count_limit                       = 5
  connection_retry_sleep_interval                    = 100000000
  connection_retry_time_limit                        = 300000000000

  machine_cleanup_policy {
    delete_machines_behavior         = "DeleteUnavailableMachines"
    delete_machines_elapsed_timespan = 1200000000000
  }

  machine_connectivity_policy {
    machine_connectivity_behavior = "ExpectedToBeOnline"
  }

  machine_health_check_policy {

    bash_health_check_policy {
      run_type    = "Inline"
      script_body = ""
    }

    powershell_health_check_policy {
      run_type    = "Inline"
      script_body = "$freeDiskSpaceThreshold = 5GB\r\n\r\nTry {\r\n\tGet-WmiObject win32_LogicalDisk -ErrorAction Stop  | ? { ($_.DriveType -eq 3) -and ($_.FreeSpace -ne $null)} |  % { CheckDriveCapacity @{Name =$_.DeviceId; FreeSpace=$_.FreeSpace} }\r\n} Catch [System.Runtime.InteropServices.COMException] {\r\n\tGet-WmiObject win32_Volume | ? { ($_.DriveType -eq 3) -and ($_.FreeSpace -ne $null) -and ($_.DriveLetter -ne $null)} | % { CheckDriveCapacity @{Name =$_.DriveLetter; FreeSpace=$_.FreeSpace} }\r\n\tGet-WmiObject Win32_MappedLogicalDisk | ? { ($_.FreeSpace -ne $null) -and ($_.DeviceId -ne $null)} | % { CheckDriveCapacity @{Name =$_.DeviceId; FreeSpace=$_.FreeSpace} }\t\r\n}"
    }

    health_check_cron_timezone = "UTC"
    health_check_interval      = 600000000000
    health_check_type          = "RunScript"
  }

  machine_update_policy {
    calamari_update_behavior = "UpdateOnDeployment"
    tentacle_update_behavior = "NeverUpdate"
  }
}

Expected behavior
A machine policy gets created without any error

Additional context
Because of the error with machine policy creation, we are not able to create a worker

@mjhilton
Copy link
Contributor

mjhilton commented Dec 1, 2024

Hi @bprathap104, can you please confirm which versions of Octopus Server and the Terraform Provider you're using?

I tested your provided HCL using TFP v0.36.0 and was unable to reproduce the same error you're experiencing.

❯ tf apply

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # octopusdeploy_machine_policy.machinepolicy_testing will be created
  + resource "octopusdeploy_machine_policy" "machinepolicy_testing" {
      + connection_connect_timeout      = 60000000000
      + connection_retry_count_limit    = 5
      + connection_retry_sleep_interval = 100000000
      + connection_retry_time_limit     = 300000000000
      + description                     = "test machine policy"
      + id                              = (known after apply)
      + is_default                      = (known after apply)
      + name                            = "Testing"
      + polling_request_queue_timeout   = 120000000000
      + space_id                        = (known after apply)

      + machine_cleanup_policy {
          + delete_machines_behavior         = "DeleteUnavailableMachines"
          + delete_machines_elapsed_timespan = 1200000000000
        }

      + machine_connectivity_policy {
          + machine_connectivity_behavior = "ExpectedToBeOnline"
        }

      + machine_health_check_policy {
          + health_check_cron_timezone = "UTC"
          + health_check_interval      = 600000000000
          + health_check_type          = "RunScript"
            # (1 unchanged attribute hidden)

          + bash_health_check_policy {
              + run_type    = "Inline"
                # (1 unchanged attribute hidden)
            }

          + powershell_health_check_policy {
              + run_type    = "Inline"
              + script_body = <<-EOT
                    $freeDiskSpaceThreshold = 5GB
                    
                    Try {
                        Get-WmiObject win32_LogicalDisk -ErrorAction Stop  | ? { ($_.DriveType -eq 3) -and ($_.FreeSpace -ne $null)} |  % { CheckDriveCapacity @{Name =$_.DeviceId; FreeSpace=$_.FreeSpace} }
                    } Catch [System.Runtime.InteropServices.COMException] {
                        Get-WmiObject win32_Volume | ? { ($_.DriveType -eq 3) -and ($_.FreeSpace -ne $null) -and ($_.DriveLetter -ne $null)} | % { CheckDriveCapacity @{Name =$_.DriveLetter; FreeSpace=$_.FreeSpace} }
                        Get-WmiObject Win32_MappedLogicalDisk | ? { ($_.FreeSpace -ne $null) -and ($_.DeviceId -ne $null)} | % { CheckDriveCapacity @{Name =$_.DeviceId; FreeSpace=$_.FreeSpace} }
                    }
                EOT
            }
        }

      + machine_update_policy {
          + calamari_update_behavior         = "UpdateOnDeployment"
          + kubernetes_agent_update_behavior = "Update"
          + tentacle_update_behavior         = "NeverUpdate"
            # (1 unchanged attribute hidden)
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

octopusdeploy_machine_policy.machinepolicy_testing: Creating...
octopusdeploy_machine_policy.machinepolicy_testing: Creation complete after 1s [id=MachinePolicies-922]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

@bprathap104
Copy link
Author

Hi @mjhilton, Thanks for looking into the issue.
I'm also using v0.36.0 TFP, error occurs at Terraform apply stage to me, there is no error during Terraform plan stage.

@mjhilton
Copy link
Contributor

mjhilton commented Dec 2, 2024

Which version of Octopus Server are you running your config against?

@mjhilton
Copy link
Contributor

Hey @bprathap104, can you please let me know which version of Octopus Server you were running your Terraform against? As you can see, I was able to do a full terraform apply of the repro config with no issues, against Octopus Cloud 2025.1.

There might be some API-level incompatibility in earlier versions, so it would help if I can test against the exact version of Octopus Server you're using.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants