|
| 1 | +--- |
| 2 | + |
| 3 | +name: $(Build.SourceBranchName)-$(Date:yyyyMMdd)_$(Rev:r) |
| 4 | +trigger: none |
| 5 | +pr: none |
| 6 | + |
| 7 | +pool: |
| 8 | + #vmImage: ubuntu-latest |
| 9 | + name: private-pool-dev-uks |
| 10 | + |
| 11 | +resources: |
| 12 | + repositories: |
| 13 | + - repository: dtos-devops-templates |
| 14 | + type: github |
| 15 | + name: NHSDigital/dtos-devops-templates |
| 16 | + ref: c00889236a258a52a2f3131272427ce81d4da951 |
| 17 | + endpoint: NHSDigital |
| 18 | + |
| 19 | +parameters: |
| 20 | + - name: pipelineAction |
| 21 | + displayName: 'Pipeline Action' |
| 22 | + type: string |
| 23 | + values: |
| 24 | + - 'PlanOnly' |
| 25 | + - 'Apply' |
| 26 | + - 'Destroy' |
| 27 | + default: 'Apply' |
| 28 | + |
| 29 | +variables: |
| 30 | + - group: SBX_audit_backend |
| 31 | + - group: DEV_hub_backend_remote_state |
| 32 | + - name: TF_DIRECTORY |
| 33 | + value: $(System.DefaultWorkingDirectory)/$(System.TeamProject)/infrastructure/tf-audit |
| 34 | + - name: TF_VERSION |
| 35 | + value: 1.11.4 |
| 36 | + - name: TF_PLAN_ARTIFACT |
| 37 | + value: tf_plan_audit_SANDBOX |
| 38 | + - name: ENVIRONMENT |
| 39 | + value: sandbox |
| 40 | + |
| 41 | +stages: |
| 42 | + - stage: terraform_plan |
| 43 | + displayName: Terraform Plan |
| 44 | + condition: and(in('${{ parameters.pipelineAction }}', 'Apply', 'PlanOnly'), eq(variables['Build.Reason'], 'Manual')) |
| 45 | + variables: |
| 46 | + tfVarsFile: environments/$(ENVIRONMENT).tfvars |
| 47 | + jobs: |
| 48 | + - job: init_and_plan |
| 49 | + displayName: Init, plan, store artifact |
| 50 | + steps: |
| 51 | + - checkout: self |
| 52 | + - checkout: dtos-devops-templates |
| 53 | + - template: .azuredevops/templates/steps/tf_plan.yaml@dtos-devops-templates |
| 54 | + |
| 55 | + - stage: terraform_apply |
| 56 | + displayName: Terraform Apply |
| 57 | + dependsOn: [terraform_plan] |
| 58 | + condition: and(eq('${{ parameters.pipelineAction }}', 'Apply'), eq(dependencies.terraform_plan.outputs['init_and_plan.TerraformPlan.changesPresent'], 'true'), eq(variables['Build.Reason'], 'Manual')) |
| 59 | + jobs: |
| 60 | + - deployment: terraform_apply |
| 61 | + displayName: Init, get plan artifact, apply |
| 62 | + environment: $(ENVIRONMENT) |
| 63 | + strategy: |
| 64 | + runOnce: |
| 65 | + deploy: |
| 66 | + steps: |
| 67 | + - checkout: self |
| 68 | + - checkout: dtos-devops-templates |
| 69 | + - template: .azuredevops/templates/steps/tf_apply.yaml@dtos-devops-templates |
| 70 | + |
| 71 | + - stage: terraform_destroy |
| 72 | + displayName: Terraform Destroy |
| 73 | + condition: and(eq('${{ parameters.pipelineAction }}', 'Destroy'), eq(variables['Build.Reason'], 'Manual')) |
| 74 | + variables: |
| 75 | + tfVarsFile: environments/$(ENVIRONMENT).tfvars |
| 76 | + jobs: |
| 77 | + - deployment: terraform_destroy |
| 78 | + displayName: Terraform Destroy |
| 79 | + environment: $(ENVIRONMENT) |
| 80 | + strategy: |
| 81 | + runOnce: |
| 82 | + deploy: |
| 83 | + steps: |
| 84 | + - checkout: self |
| 85 | + - checkout: dtos-devops-templates |
| 86 | + - template: .azuredevops/templates/steps/tf_destroy.yaml@dtos-devops-templates |
0 commit comments