@@ -285,6 +285,28 @@ resource "octopusdeploy_environment" "environment_production" {
285285  }
286286}
287287
288+ data  "octopusdeploy_community_step_template"  "communitysteptemplate_octopus___check_targets_available"  {
289+   website  =  " https://library.octopus.com/step-templates/81444e7f-d77a-47db-b287-0f1ab5793880" 
290+ }
291+ data  "octopusdeploy_step_template"  "steptemplate_octopus___check_targets_available"  {
292+   name  =  " Octopus - Check Targets Available" 
293+ }
294+ resource  "octopusdeploy_community_step_template"  "communitysteptemplate_octopus___check_targets_available"  {
295+   community_action_template_id  =  " ${ data . octopusdeploy_community_step_template . communitysteptemplate_octopus___check_targets_available . steps [0 ]. id } " 
296+   count                         =  " ${ data . octopusdeploy_step_template . steptemplate_octopus___check_targets_available . step_template  !=  null  ?  0  :  1 } " 
297+ }
298+ 
299+ data  "octopusdeploy_community_step_template"  "communitysteptemplate_octopus___check_smtp_server_configured"  {
300+   website  =  " https://library.octopus.com/step-templates/ad8126be-37af-4297-b46e-fce02ba3987a" 
301+ }
302+ data  "octopusdeploy_step_template"  "steptemplate_octopus___check_smtp_server_configured"  {
303+   name  =  " Octopus - Check SMTP Server Configured" 
304+ }
305+ resource  "octopusdeploy_community_step_template"  "communitysteptemplate_octopus___check_smtp_server_configured"  {
306+   community_action_template_id  =  " ${ data . octopusdeploy_community_step_template . communitysteptemplate_octopus___check_smtp_server_configured . steps [0 ]. id } " 
307+   count                         =  " ${ data . octopusdeploy_step_template . steptemplate_octopus___check_smtp_server_configured . step_template  !=  null  ?  0  :  1 } " 
308+ }
309+ 
288310resource  "octopusdeploy_process"  "process_random_quotes__net_iis"  {
289311  count       =  " ${ length (data. octopusdeploy_projects . project_random_quotes__net_iis . projects ) !=  0  ?  0  :  1 } " 
290312  project_id  =  " ${ length (data. octopusdeploy_projects . project_random_quotes__net_iis . projects ) !=  0  ?  data . octopusdeploy_projects . project_random_quotes__net_iis . projects [0 ]. id  :  octopusdeploy_project . project_random_quotes__net_iis [0 ]. id } " 
@@ -308,8 +330,8 @@ resource "octopusdeploy_process_step" "process_step_random_quotes__net_iis_appro
308330  properties             =   {
309331      }
310332  execution_properties   =   {
311-         " Octopus.Action.Manual.BlockConcurrentDeployments"  =  " False" 
312333        " Octopus.Action.Manual.Instructions"  =  " Do you approve the production deployment?" 
334+         " Octopus.Action.Manual.BlockConcurrentDeployments"  =  " False" 
313335        " Octopus.Action.RunOnServer"  =  " true" 
314336      }
315337}
@@ -318,8 +340,8 @@ resource "octopusdeploy_process_templated_step" "process_step_random_quotes__net
318340  count                  =  " ${ length (data. octopusdeploy_projects . project_random_quotes__net_iis . projects ) !=  0  ?  0  :  1 } " 
319341  name                   =  " Octopus - Check Targets Available" 
320342  process_id             =  " ${ length (data. octopusdeploy_projects . project_random_quotes__net_iis . projects ) !=  0  ?  null  :  octopusdeploy_process . process_random_quotes__net_iis [0 ]. id } " 
321-   template_id            =  " " 
322-   template_version       =  " " 
343+   template_id            =  " ${ data . octopusdeploy_step_template . steptemplate_octopus___check_targets_available . step_template   !=   null   ?   data . octopusdeploy_step_template . steptemplate_octopus___check_targets_available . step_template . id   :   octopusdeploy_community_step_template . communitysteptemplate_octopus___check_targets_available [ 0 ] . id } " 
344+   template_version       =  " ${ data . octopusdeploy_step_template . steptemplate_octopus___check_targets_available . step_template   !=   null   ?   data . octopusdeploy_step_template . steptemplate_octopus___check_targets_available . step_template . version   :   octopusdeploy_community_step_template . communitysteptemplate_octopus___check_targets_available [ 0 ] . version } " 
323345  channels               =  null 
324346  condition              =  " Success" 
325347  environments           =  null 
@@ -334,8 +356,8 @@ resource "octopusdeploy_process_templated_step" "process_step_random_quotes__net
334356      }
335357  execution_properties   =   {
336358        " OctopusUseBundledTooling"  =  " False" 
337-         " Octopus.Action.Script.ScriptSource"  =  " Inline" 
338359        " Octopus.Action.Script.Syntax"  =  " PowerShell" 
360+         " Octopus.Action.Script.ScriptSource"  =  " Inline" 
339361        " Octopus.Action.RunOnServer"  =  " true" 
340362        "Octopus.Action.Script.ScriptBody" = "$errorCollection = @()\n$setupValid = $false\n\nWrite-Host \"Checking for deployment targets ...\"\n\ntry\n{\n    # Check to make sure targets have been created\n    if ([string]::IsNullOrWhitespace(\"#{Octopus.Web.ServerUri}\"))\n    {\n        $octopusUrl = \"#{Octopus.Web.BaseUrl}\"\n    }\n    else\n    {\n        $octopusUrl = \"#{Octopus.Web.ServerUri}\"\n    }\n\n    $apiKey = \"#{CheckTargets.Octopus.Api.Key}\"\n    $role = \"#{CheckTargets.Octopus.Role}\"\n    $message = \"#{CheckTargets.Message}\"\n\n    if (![string]::IsNullOrWhitespace($apiKey) -and $apiKey.StartsWith(\"API-\"))\n    {\n        $spaceId = \"#{Octopus.Space.Id}\"\n        $headers = @{ \"X-Octopus-ApiKey\" = \"$apiKey\" }\n\n        try\n        {\n            $roleTargets = Invoke-RestMethod -Method Get -Uri \"$octopusUrl/api/$spaceId/machines?roles=$role\" -Headers $headers\n            if ($roleTargets.Items.Count -lt 1)\n            {\n                $errorCollection += @(\"Expected at least 1 target for tag $role, but found $( $roleTargets.Items.Count ). $message\")\n            }\n        }\n        catch\n        {\n            $errorCollection += @(\"Failed to retrieve role targets: $( $_.Exception.Message )\")\n        }\n\n        if ($errorCollection.Count -gt 0)\n        {\n            foreach ($item in $errorCollection)\n            {\n                Write-Highlight \"$item\"\n            }\n        }\n        else\n        {\n            $setupValid = $true\n            Write-Host \"Setup valid!\"\n        }\n    }\n    else\n    {\n        Write-Highlight \"The project variable CheckTargets.Octopus.Api.Key has not been configured, unable to check deployment targets.\"\n    }\n\n    Set-OctopusVariable -Name SetupValid -Value $setupValid\n} catch {\n    Write-Verbose \"Fatal error occurred:\"\n    Write-Verbose \"$($_.Exception.Message)\"\n}"
341363      }
@@ -345,8 +367,8 @@ resource "octopusdeploy_process_templated_step" "process_step_random_quotes__net
345367  count                  =  " ${ length (data. octopusdeploy_projects . project_random_quotes__net_iis . projects ) !=  0  ?  0  :  1 } " 
346368  name                   =  " Octopus - Check SMTP Server Configured" 
347369  process_id             =  " ${ length (data. octopusdeploy_projects . project_random_quotes__net_iis . projects ) !=  0  ?  null  :  octopusdeploy_process . process_random_quotes__net_iis [0 ]. id } " 
348-   template_id            =  " " 
349-   template_version       =  " " 
370+   template_id            =  " ${ data . octopusdeploy_step_template . steptemplate_octopus___check_smtp_server_configured . step_template   !=   null   ?   data . octopusdeploy_step_template . steptemplate_octopus___check_smtp_server_configured . step_template . id   :   octopusdeploy_community_step_template . communitysteptemplate_octopus___check_smtp_server_configured [ 0 ] . id } " 
371+   template_version       =  " ${ data . octopusdeploy_step_template . steptemplate_octopus___check_smtp_server_configured . step_template   !=   null   ?   data . octopusdeploy_step_template . steptemplate_octopus___check_smtp_server_configured . step_template . version   :   octopusdeploy_community_step_template . communitysteptemplate_octopus___check_smtp_server_configured [ 0 ] . version } " 
350372  channels               =  null 
351373  condition              =  " Success" 
352374  environments           =  null 
@@ -360,10 +382,10 @@ resource "octopusdeploy_process_templated_step" "process_step_random_quotes__net
360382  properties             =   {
361383      }
362384  execution_properties   =   {
363-         " Octopus.Action.Script.Syntax"  =  " PowerShell" 
364-         "Octopus.Action.Script.ScriptBody" = "$apiKey = \"#{SmtpCheck.Octopus.Api.Key}\"\n$isSmtpConfigured = $false\n\nif (![string]::IsNullOrWhitespace($apiKey) -and $apiKey.StartsWith(\"API-\"))\n{\n    if ([String]::IsNullOrWhitespace(\"#{Octopus.Web.ServerUri}\"))\n    {\n        $octopusUrl = \"#{Octopus.Web.BaseUrl}\"\n    }\n    else\n    {\n        $octopusUrl = \"#{Octopus.Web.ServerUri}\"\n    }\n\n    $uriBuilder = New-Object System.UriBuilder(\"$octopusUrl/api/smtpconfiguration/isconfigured\")\n    $uri = $uriBuilder.ToString()\n\n    try\n    {\n        $headers = @{ \"X-Octopus-ApiKey\" = $apiKey }\n        $smtpConfigured = Invoke-RestMethod -Method Get -Uri $uri -Headers $headers\n        $isSmtpConfigured = $smtpConfigured.IsConfigured\n    }\n    catch\n    {\n        Write-Host \"Error checking SMTP configuration: $($_.Exception.Message)\"\n    }\n}\nelse\n{\n    Write-Highlight \"The project variable SmtpCheck.Octopus.Api.Key has not been configured, unable to check SMTP configuration.\"\n}\n\nif (-not $isSmtpConfigured)\n{\n    Write-Highlight \"SMTP is not configured. Please [configure SMTP](https://octopus.com/docs/projects/built-in-step-templates/email-notifications#smtp-configuration) settings in Octopus Deploy.\"\n}\n\nSet-OctopusVariable -Name SmtpConfigured -Value $isSmtpConfigured"
365385        " Octopus.Action.RunOnServer"  =  " true" 
366386        " OctopusUseBundledTooling"  =  " False" 
387+         " Octopus.Action.Script.Syntax"  =  " PowerShell" 
388+         "Octopus.Action.Script.ScriptBody" = "$apiKey = \"#{SmtpCheck.Octopus.Api.Key}\"\n$isSmtpConfigured = $false\n\nif (![string]::IsNullOrWhitespace($apiKey) -and $apiKey.StartsWith(\"API-\"))\n{\n    if ([String]::IsNullOrWhitespace(\"#{Octopus.Web.ServerUri}\"))\n    {\n        $octopusUrl = \"#{Octopus.Web.BaseUrl}\"\n    }\n    else\n    {\n        $octopusUrl = \"#{Octopus.Web.ServerUri}\"\n    }\n\n    $uriBuilder = New-Object System.UriBuilder(\"$octopusUrl/api/smtpconfiguration/isconfigured\")\n    $uri = $uriBuilder.ToString()\n\n    try\n    {\n        $headers = @{ \"X-Octopus-ApiKey\" = $apiKey }\n        $smtpConfigured = Invoke-RestMethod -Method Get -Uri $uri -Headers $headers\n        $isSmtpConfigured = $smtpConfigured.IsConfigured\n    }\n    catch\n    {\n        Write-Host \"Error checking SMTP configuration: $($_.Exception.Message)\"\n    }\n}\nelse\n{\n    Write-Highlight \"The project variable SmtpCheck.Octopus.Api.Key has not been configured, unable to check SMTP configuration.\"\n}\n\nif (-not $isSmtpConfigured)\n{\n    Write-Highlight \"SMTP is not configured. Please [configure SMTP](https://octopus.com/docs/projects/built-in-step-templates/email-notifications#smtp-configuration) settings in Octopus Deploy.\"\n}\n\nSet-OctopusVariable -Name SmtpConfigured -Value $isSmtpConfigured"
367389        " Octopus.Action.Script.ScriptSource"  =  " Inline" 
368390      }
369391}
0 commit comments