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

DTSPO-18399 - add plan and apply for ptlsbox #96

Merged
merged 30 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5def0d9
add plan and apply for ptlsbox
louisehuyton Aug 14, 2024
1de9c6b
use suggested loop
louisehuyton Aug 14, 2024
31e83c3
correct indentation
louisehuyton Aug 14, 2024
9fd81b0
add missing colon
louisehuyton Aug 14, 2024
db7fae9
try fix syntax for parameters
louisehuyton Aug 14, 2024
c9ce484
Update azure-pipelines.yml
Tyler-35 Aug 14, 2024
bfcbcd0
use parameters object
louisehuyton Aug 14, 2024
33d5eaa
fix old reference to env and replace with component
louisehuyton Aug 14, 2024
c3ed9d1
try fix error with stage names
louisehuyton Aug 14, 2024
fb48db3
try fix syntax errors
louisehuyton Aug 14, 2024
b9d35ca
remove unneeded quotation mark
louisehuyton Aug 14, 2024
a150e28
remove unneeded quotation marks and spaces
louisehuyton Aug 14, 2024
7a98db8
fix dependson
louisehuyton Aug 14, 2024
e0caf46
create needed tfvars files
louisehuyton Aug 14, 2024
3e4d84e
fix tfvars files
louisehuyton Aug 14, 2024
1b09074
run terraform fmt
louisehuyton Aug 14, 2024
e3138a1
adding tfvars to pipeline
Tyler-35 Aug 30, 2024
e2ca948
Merge branch 'master' into DTSPO-18399
Tyler-35 Aug 30, 2024
4b6d8bb
adding tfvars to pipeline
Tyler-35 Sep 2, 2024
671f734
adding tfvars to pipeline
Tyler-35 Sep 2, 2024
6223383
adding logic so sandbox doesn't create a postgres server
Tyler-35 Sep 2, 2024
ffff970
fixing format
Tyler-35 Sep 2, 2024
ee6f25e
fixing format
Tyler-35 Sep 2, 2024
c3655aa
fixing format
Tyler-35 Sep 2, 2024
b02f810
fixing format
Tyler-35 Sep 2, 2024
bb459a2
setting count for postgres
Tyler-35 Sep 2, 2024
6b6c832
fixing format
Tyler-35 Sep 2, 2024
4310ade
testing life cycle
Tyler-35 Sep 2, 2024
891a95c
fixing format
Tyler-35 Sep 2, 2024
d570400
fixing format
Tyler-35 Sep 2, 2024
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
108 changes: 63 additions & 45 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ variables:
agentPool: 'ubuntu-latest'
action:

parameters:
- name: environment_components
type: object
default:
- environment: 'ptlsbox'
service_connection: 'DTS-CFTSBOX-INTSVC'
storage_account_rg: 'core-infra-intsvc-rg'
storage_account_name: 'cftsboxintsvc'
tfvarsFile: 'ptlsbox.tfvars'
- environment: 'ptl'
service_connection: 'DTS-CFTPTL-INTSVC'
storage_account_rg: 'core-infra-intsvc-rg'
storage_account_name: 'cftptlintsvc'
tfvarsFile: 'ptl.tfvars'

stages:
- stage: GetArtifacts
jobs:
Expand All @@ -37,50 +52,53 @@ stages:
failTaskOnFailedTests: true
condition: always()

- stage: PlanResponse
displayName: "Plan Response - PTL"
dependsOn: GetArtifacts
jobs:
- template: pipeline-templates/terraform-plan.yaml
parameters:
environment: 'ptl'
component: 'response'
service_connection: 'DTS-CFTPTL-INTSVC'
storage_account_rg: 'core-infra-intsvc-rg'
storage_account_name: 'cftptlintsvc'
build: $(Build.BuildNumber)
agentPool: ${{ variables.agentPool }}
terraformVersion: ${{ variables.terraformVersion }}
builtFrom: $(Build.Repository.Name)
- job: Archive
dependsOn: Plan_ptl_response
pool:
vmImage: ${{ variables.agentPool }}
steps:
- task: CopyFiles@2
displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
inputs:
Contents: |
*.tf
*.tfvars
*tfplan
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- ${{ each component in parameters.environment_components }}:
- stage: PlanResponse_${{ component.environment }}
displayName: "Plan Response - ${{ component.environment }}"
dependsOn: GetArtifacts
jobs:
- template: pipeline-templates/terraform-plan.yaml
parameters:
environment: ${{ component.environment }}
component: 'response'
service_connection: ${{ component.service_connection }}
storage_account_rg: ${{ component.storage_account_rg }}
storage_account_name: ${{ component.storage_account_name }}
build: $(Build.BuildNumber)
agentPool: ${{ variables.agentPool }}
terraformVersion: ${{ variables.terraformVersion }}
builtFrom: $(Build.Repository.Name)
tfvarsFile: ${{ component.tfvarsFile }}
- job: Archive
dependsOn: Plan_${{ component.environment }}_response
pool:
vmImage: ${{ variables.agentPool }}
steps:
- task: CopyFiles@2
displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
inputs:
Contents: |
*.tf
*.tfvars
*tfplan
TargetFolder: '$(Build.ArtifactStagingDirectory)'

- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'

- stage: ApplyResponse
displayName: "Apply Response - PTL"
dependsOn: PlanResponse
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
jobs:
- template: pipeline-templates/terraform-apply.yaml
parameters:
environment: 'ptl'
component: 'response'
service_connection: 'DTS-CFTPTL-INTSVC'
storage_account_rg: 'core-infra-intsvc-rg'
storage_account_name: 'cftptlintsvc'
build: $(Build.BuildNumber)
agentPool: ${{ variables.agentPool }}
terraformVersion: ${{ variables.terraformVersion }}
- stage: ApplyResponse_${{ component.environment }}
displayName: "Apply Response - ${{ component.environment }}"
dependsOn: PlanResponse_${{ component.environment }}
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
jobs:
- template: pipeline-templates/terraform-apply.yaml
parameters:
environment: ${{ component.environment }}
component: 'response'
service_connection: ${{ component.service_connection }}
storage_account_rg: ${{ component.storage_account_rg }}
storage_account_name: ${{ component.storage_account_name }}
build: $(Build.BuildNumber)
agentPool: ${{ variables.agentPool }}
terraformVersion: ${{ variables.terraformVersion }}
tfvarsFile: ${{ component.tfvarsFile }}
7 changes: 5 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ resource "azurerm_resource_group" "rg" {
}

data "azurerm_key_vault" "ptl" {
name = "cftptl-intsvc"
name = var.keyvault_data_name
resource_group_name = "core-infra-intsvc-rg"
}

module "postgresql_flexible" {
providers = {
azurerm.postgres_network = azurerm.postgres_network
}
count = var.create_postgres ? 1 : 0

source = "git::https://github.com/hmcts/terraform-module-postgresql-flexible?ref=master"
env = var.env
Expand All @@ -36,7 +37,9 @@ module "postgresql_flexible" {
}

resource "azurerm_key_vault_secret" "response-db-secret-v14" {
count = var.create_postgres ? 1 : 0

name = "response-db-password-v14"
value = module.postgresql_flexible.password
value = module.postgresql_flexible[0].password
key_vault_id = data.azurerm_key_vault.ptl.id
}
2 changes: 1 addition & 1 deletion pipeline-templates/terraform-apply.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ jobs:
displayName: Apply - ${{ parameters.environment }} - ${{ parameters.component }}
inputs:
command: 'apply'
commandOptions: '${{ parameters.environment }}${{ parameters.component }}${{ parameters.build }}plan'
commandOptions: 'var-file=${{ parameters.tfvarsFile }} ${{ parameters.environment }}${{ parameters.component }}${{ parameters.build }}plan'
environmentServiceName: '${{ parameters.service_connection }}'
workingDirectory: '$(Pipeline.Workspace)/drop'
2 changes: 1 addition & 1 deletion pipeline-templates/terraform-plan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
displayName: Plan - ${{ parameters.environment }} - ${{ parameters.component }}
inputs:
command: 'plan'
commandOptions: '-var builtFrom=${{ parameters.builtFrom }} -out=${{ parameters.environment }}${{ parameters.component }}${{ parameters.build }}plan'
commandOptions: '-var-file=${{ parameters.tfvarsFile }} -var builtFrom=${{ parameters.builtFrom }} -out=${{ parameters.environment }}${{ parameters.component }}${{ parameters.build }}plan'
workingDirectory: '$(System.DefaultWorkingDirectory)'
environmentServiceName: '${{ parameters.service_connection }}'
- task: Bash@3
Expand Down
4 changes: 4 additions & 0 deletions ptl.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
env = "ptl"
mi_env = "cftptl-intsvc"
create_postgres = true
keyvault_data_name = "cftptl-intsvc"
4 changes: 4 additions & 0 deletions ptlsbox.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
env = "sandbox"
mi_env = "cftsbox-intsvc"
create_postgres = false
keyvault_data_name = "cftsbox-intsvc"
11 changes: 9 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
variable "env" {
default = "ptl"
}

variable "product" {
Expand All @@ -21,5 +20,13 @@ variable "component" {
}

variable "mi_env" {
default = "cftptl-intsvc"
}

variable "create_postgres" {
description = "Whether to create the PostgreSQL server"
type = bool
default = true
}

variable "keyvault_data_name" {
}