Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/core/TerraformRunner.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ function Initialize-TerraformBackend {
# Create backend config file
$backendConfig = "path=`"./$ConfigPath/$StateFileName`""
$backendConfigPath = "./$TemplateFolder/$ConfigPath/config.backend"
$stateFilePath = "./$TemplateFolder/$ConfigPath/$StateFileName"
$stateFileExistedBeforeInit = Test-Path $stateFilePath

$backendConfig | Out-File -FilePath $backendConfigPath -Force

Expand All @@ -47,8 +49,8 @@ function Initialize-TerraformBackend {
throw "Terraform initialization failed"
}

# Drift detection only when a varfile is supplied and -Force is not set
if ($VarFilePath -and -not $Force) {
# Drift detection only makes sense when a state file existed before init, varfile is supplied and -Force is not set
if ($VarFilePath -and -not $Force -and $stateFileExistedBeforeInit) {
$driftResult = Invoke-TerraformDriftCheck -TemplateFolder $TemplateFolder -VarFilePath $VarFilePath -Variables $Variables
if ($driftResult.HasDrift) {
Write-Host ""
Expand All @@ -67,6 +69,9 @@ function Initialize-TerraformBackend {
Write-Host "No drift detected." -ForegroundColor Green
}
}
elseif ($VarFilePath -and -not $Force) {
Write-Host "Skipping drift detection because no Terraform state file existed before initialization." -ForegroundColor DarkGray
}
}

function Invoke-TerraformPlan {
Expand Down
19 changes: 19 additions & 0 deletions lib/templates/PropertyManager.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@ class PropertyManagerTemplate {
Write-Host "Secure by Default not enabled - skipping product validation" -ForegroundColor Yellow
}
}


# Only validate if enable_mpulse is enabled and not skipped
if (-not $this.DeployParams.SkipValidation) {
$enableMPulseValue = Get-TfVarValue -FilePath $tfvarsPath -VarName "enable_mPulse"

if ($enableMPulseValue -eq "true") {
Write-Host "mPulse enabled - validating product ID" -ForegroundColor Cyan

$expectedProducts = @(
@{Id = "M-LC-161244"; Name = "mPulse::mPulse"}
)

Test-AkamaiProductId -TfVarsPath $tfvarsPath -ExpectedProducts $expectedProducts
}
else {
Write-Host "mPulse not enabled - skipping product validation" -ForegroundColor Yellow
}
}
}

[hashtable] BuildTerraformVars() {
Expand Down
23 changes: 13 additions & 10 deletions new-property/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ module "example" {

# Required variables
additional_origins = <map(object({
origin_name = string
hostname_match = list(string)
path_match = list(string)
origin_name = string
forward_host_header = string
hostname_match = list(string)
path_match = list(string)
}))>
contract_id = <string>
default_origin = <string>
Expand All @@ -123,10 +124,11 @@ module "example" {
certificate_id = <number> | default: null
cpcode_name = <string> | default: null
customer_email = <string> | default: null
dummy_test = <string> | default: "dummy_test"
default_cpcode = <bool> | default: false
edgerc_path = <string> | default: "~/.edgerc"
ehn_domain = <string> | default: null
enable_mPulse = <bool> | default: true
forward_host_header = <string> | default: "REQUEST_HOST_HEADER"
ip_behavior = <string> | default: "IPV6_COMPLIANCE"
noncompliance_reason = <list(string)> | default: []
other_noncompliance_reason = <string> | default: null
Expand All @@ -146,7 +148,7 @@ module "example" {
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.9.0 |
| <a name="requirement_akamai"></a> [akamai](#requirement\_akamai) | ~> 9.0 |
| <a name="requirement_akamai"></a> [akamai](#requirement\_akamai) | ~> 10.1 |

## Resources

Expand All @@ -156,13 +158,13 @@ No resources.

| Name | Source | Version |
|------|--------|---------|
| <a name="module_property"></a> [property](#module\_property) | git::ssh://git@github.com/akamai/terraform-templates-modules.git//delivery | v1.3.3 |
| <a name="module_property"></a> [property](#module\_property) | git::ssh://git@github.com/akamai/terraform-templates-modules.git//delivery | integration |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_additional_origins"></a> [additional\_origins](#input\_additional\_origins) | Additional origins for the property. For now the match is only by hostname. | <pre>map(object({<br/> origin_name = string<br/> hostname_match = list(string)<br/> path_match = list(string)<br/> }))</pre> | n/a | yes |
| <a name="input_additional_origins"></a> [additional\_origins](#input\_additional\_origins) | Additional origins for the property. For now the match is only by hostname. The field forward\_host\_header allows specifying a custom host header for each additional origin.Possible fixed values are ORIGIN\_HOSTNAME or REQUEST\_HOST\_HEADER. But the user can also select any host header they would like to use as a custom value. | <pre>map(object({<br/> origin_name = string<br/> forward_host_header = string<br/> hostname_match = list(string)<br/> path_match = list(string)<br/> }))</pre> | n/a | yes |
| <a name="input_contract_id"></a> [contract\_id](#input\_contract\_id) | Contract ID for property/config creation | `string` | n/a | yes |
| <a name="input_default_origin"></a> [default\_origin](#input\_default\_origin) | Default origin server for all properties | `string` | n/a | yes |
| <a name="input_edgerc_section"></a> [edgerc\_section](#input\_edgerc\_section) | Section in the .edgerc file.<br/><br/> For professional services, it is recommended to create a new section for<br/> each account managed. | `string` | n/a | yes |
Expand All @@ -179,11 +181,12 @@ No resources.
| <a name="input_certificate_id"></a> [certificate\_id](#input\_certificate\_id) | Certificate enrollment id. Only applicable if enhanced\_tls is true, and secure\_by\_default<br/>is false.<br/><br/>Can be retrieved using AkamaiPowershell or the Akamai CPS CLI. | `number` | `null` | no |
| <a name="input_cpcode_name"></a> [cpcode\_name](#input\_cpcode\_name) | Default CP Code name. Will be the property name (var.name) if null. | `string` | `null` | no |
| <a name="input_customer_email"></a> [customer\_email](#input\_customer\_email) | Email address of the customer that acknowledged, tested and accepted the change | `string` | `null` | no |
| <a name="input_dummy_test"></a> [dummy\_test](#input\_dummy\_test) | n/a | `string` | `"dummy_test"` | no |
| <a name="input_default_cpcode"></a> [default\_cpcode](#input\_default\_cpcode) | Boolean to enable the default CP Code for all properties. If false, the CP Code must be specified in the property definition. | `bool` | `false` | no |
| <a name="input_edgerc_path"></a> [edgerc\_path](#input\_edgerc\_path) | Path to the .edgerc file. | `string` | `"~/.edgerc"` | no |
| <a name="input_ehn_domain"></a> [ehn\_domain](#input\_ehn\_domain) | EdgeHostname domain, e.g. edgesuite.net or edgekey.net. Will default to one or<br/>the other, based on the value of etls variable. | `string` | `null` | no |
| <a name="input_enable_mPulse"></a> [enable\_mPulse](#input\_enable\_mPulse) | Boolean tod ecide whether to inject the mpulse behavior | `bool` | `true` | no |
| <a name="input_ip_behavior"></a> [ip\_behavior](#input\_ip\_behavior) | EdgeHostname IP behaviour. | `string` | `"IPV6_COMPLIANCE"` | no |
| <a name="input_enable_mPulse"></a> [enable\_mPulse](#input\_enable\_mPulse) | Boolean to decide whether to inject the mpulse behavior | `bool` | `true` | no |
| <a name="input_forward_host_header"></a> [forward\_host\_header](#input\_forward\_host\_header) | Host header to be forwarded to the origin server. Possible fixed values are ORIGIN\_HOSTNAME or REQUEST\_HOST\_HEADER. But the user can also select any host header they would like to use as a custom value. | `string` | `"REQUEST_HOST_HEADER"` | no |
| <a name="input_ip_behavior"></a> [ip\_behavior](#input\_ip\_behavior) | EdgeHostname IP behaviour.Possible values are IPV4 or IPV6\_COMPLIANCE. | `string` | `"IPV6_COMPLIANCE"` | no |
| <a name="input_noncompliance_reason"></a> [noncompliance\_reason](#input\_noncompliance\_reason) | Allowed values for noncompliance\_reason are "NO\_PRODUCTION\_TRAFFIC", "EMERGENCY", "NONE". (OR null for the customer, as None will require the complaince block) | `list(string)` | `[]` | no |
| <a name="input_other_noncompliance_reason"></a> [other\_noncompliance\_reason](#input\_other\_noncompliance\_reason) | Describes the reason why the activation must occur immediately, out of compliance with the standard procedure | `string` | `null` | no |
| <a name="input_peer_reviewed_by"></a> [peer\_reviewed\_by](#input\_peer\_reviewed\_by) | Email address of the peer who performed the review | `string` | `null` | no |
Expand Down
15 changes: 12 additions & 3 deletions new-property/environments/dev/dev.tfvars.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,31 @@ name = "<Config Name>"
hostnames = ["dev.example.com", "dev-api.example.com"]
etls = true
default_origin = "dev-origin.example.com"
forward_host_header = "REQUEST_HOST_HEADER"

# Set additional_origins=null if no additional origins are needed. In a similar fashion, set path_match or hostname_match to null if not needed.
# The field forward_host_header allows specifying a custom host header for each additional origin.Possible fixed values are ORIGIN_HOSTNAME or REQUEST_HOST_HEADER. But the user can also select any host header they would like to use as a custom value."
additional_origins = {
"api_origin" = {
origin_name = "dev-api-origin.example.com"
hostname_match = ["dev-api.example.com"]
origin_name = "api-origin.example.com"
hostname_match = ["api.example.com"]
forward_host_header = "REQUEST_HOST_HEADER"
path_match = ["/api/*"]
},
"images_origin" = {
origin_name = "dev-images-origin.example.com"
origin_name = "images-origin.example.com"
hostname_match = null
forward_host_header = "REQUEST_HOST_HEADER"
path_match = ["/images/*"]
}
}
sure_route_test_object = "/terraform/srto.html"
td_region = "CH2"
cpcode_name = "cpcode_name"
default_cpcode = false

# Enable only if product is Fresca or SPM
enable_mpulse = false

## ----------------------------------------------------------------------------
## Activation
Expand Down
9 changes: 9 additions & 0 deletions new-property/environments/prod/prod.tfvars.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,31 @@ name = "<Config Name>"
hostnames = ["www.example.com", "api.example.com"]
etls = true
default_origin = "origin.example.com"
forward_host_header = "REQUEST_HOST_HEADER"

# Set additional_origins=null if no additional origins are needed. In a similar fashion, set path_match or hostname_match to null if not needed.
# The field forward_host_header allows specifying a custom host header for each additional origin.Possible fixed values are ORIGIN_HOSTNAME or REQUEST_HOST_HEADER. But the user can also select any host header they would like to use as a custom value."
additional_origins = {
"api_origin" = {
origin_name = "api-origin.example.com"
hostname_match = ["api.example.com"]
forward_host_header = "REQUEST_HOST_HEADER"
path_match = ["/api/*"]
},
"images_origin" = {
origin_name = "images-origin.example.com"
hostname_match = null
forward_host_header = "REQUEST_HOST_HEADER"
path_match = ["/images/*"]
}
}
sure_route_test_object = "/terraform/srto.html"
td_region = "CH2"
cpcode_name = "cpcode_name"
default_cpcode = false

# Enable only if product is Fresca or SPM
enable_mpulse = false

## ----------------------------------------------------------------------------
## Activation
Expand Down
15 changes: 12 additions & 3 deletions new-property/environments/qa/qa.tfvars.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,31 @@ name = "<Config Name>"
hostnames = ["qa.example.com", "qa-api.example.com"]
etls = true
default_origin = "qa-origin.example.com"
forward_host_header = "REQUEST_HOST_HEADER"

# Set additional_origins=null if no additional origins are needed. In a similar fashion, set path_match or hostname_match to null if not needed.
# The field forward_host_header allows specifying a custom host header for each additional origin.Possible fixed values are ORIGIN_HOSTNAME or REQUEST_HOST_HEADER. But the user can also select any host header they would like to use as a custom value."
additional_origins = {
"api_origin" = {
origin_name = "qa-api-origin.example.com"
hostname_match = ["qa-api.example.com"]
origin_name = "api-origin.example.com"
hostname_match = ["api.example.com"]
forward_host_header = "REQUEST_HOST_HEADER"
path_match = ["/api/*"]
},
"images_origin" = {
origin_name = "qa-images-origin.example.com"
origin_name = "images-origin.example.com"
hostname_match = null
forward_host_header = "REQUEST_HOST_HEADER"
path_match = ["/images/*"]
}
}
sure_route_test_object = "/terraform/srto.html"
td_region = "CH2"
cpcode_name = "cpcode_name"
default_cpcode = false

# Enable only if product is Fresca or SPM
enable_mpulse = false

## ----------------------------------------------------------------------------
## Activation
Expand Down
8 changes: 5 additions & 3 deletions new-property/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,19 @@


module "property" {
source = "git::ssh://git@github.com/akamai/terraform-templates-modules.git//delivery?ref=v1.3.3"
source = "git::ssh://git@github.com/akamai/terraform-templates-modules.git//delivery?ref=integration"

contract_id = var.contract_id
group_id = var.group_id


product_id = var.product_id
name = var.name
version_notes = "${var.version_notes}${var.dummy_test}"
version_notes = var.version_notes
hostnames = var.hostnames
etls = var.etls
default_origin = var.default_origin
forward_host_header = var.forward_host_header
additional_origins = var.additional_origins
sure_route_test_object = var.sure_route_test_object
td_region = var.td_region
Expand All @@ -123,7 +124,8 @@ module "property" {
activation_to_staging_exists = var.activation_to_staging_exists
activation_to_production_exists = var.activation_to_production_exists

cpcode_name = var.cpcode_name
default_cpcode = var.default_cpcode
cpcode_name = var.cpcode_name

secure_by_default = var.secure_by_default
certificate_id = var.certificate_id
Expand Down
Loading
Loading