<commit_before>resources:
  - name: cf-deployment
    type: bosh-deployment
    source:
      target: https://10.0.0.6:25555
      username: admin
      password: <PASSWORD>}}
      deployment: {{deploy_env}}
      ignore_ssl: true

  - name: paas-cf
    type: git
    source:
      uri: https://github.com/alphagov/paas-cf.git
      branch: {{branch_name}}

  - name: vpc-tfstate
    type: s3
    source:
      bucket: {{state_bucket}}
      region_name: {{aws_region}}
      access_key_id: {{aws_access_key_id}}
      secret_access_key: {{aws_secret_access_key}}
      versioned_file: vpc.tfstate

  - name: bosh-tfstate
    type: s3
    source:
      bucket: {{state_bucket}}
      region_name: {{aws_region}}
      access_key_id: {{aws_access_key_id}}
      secret_access_key: {{aws_secret_access_key}}
      versioned_file: bosh.tfstate

  - name: concourse-tfstate
    type: s3
    source:
      bucket: {{state_bucket}}
      access_key_id: {{aws_access_key_id}}
      secret_access_key: {{aws_secret_access_key}}
      versioned_file: concourse.tfstate
      region_name: eu-west-1

  - name: cf-tfstate
    type: s3
    source:
      bucket: {{state_bucket}}
      access_key_id: {{aws_access_key_id}}
      secret_access_key: {{aws_secret_access_key}}
      versioned_file: cf.tfstate
      region_name: eu-west-1

  - name: cf-manifest
    type: s3
    source:
      bucket: {{state_bucket}}
      region_name: {{aws_region}}
      access_key_id: {{aws_access_key_id}}
      secret_access_key: {{aws_secret_access_key}}
      versioned_file: cf-manifest.yml

jobs:
  - name: s3init
    serial_groups: [ deploy ]
    serial: true
    plan:
      - get: paas-cf
      - task: s3init
        config:
          image: docker:///governmentpaas/curl-ssl
          run:
            path: sh
            args:
            - -e
            - -c
            - |
              paas-cf/concourse/scripts/s3init.sh {{state_bucket}} cf.tfstate paas-cf/concourse/init_files/terraform.tfstate.tpl
          inputs:
          - name: paas-cf
      - put: cf-tfstate
        params:
          file: s3init/cf.tfstate
  - name: terraform
    serial_groups: [ deploy ]
    serial: true
    plan:
      - aggregate:
        - get: paas-cf
          passed: ['s3init']
        - get: vpc-tfstate
        - get: concourse-tfstate
        - get: bosh-tfstate
        - get: cf-tfstate
          passed: ['s3init']
          trigger: true
      - task: terraform-variables
        config:
          image: docker:///ruby
          inputs:
            - name: paas-cf
            - name: vpc-tfstate
            - name: concourse-tfstate
            - name: bosh-tfstate
          run:
            path: sh
            args:
            - -e
            - -c
            - |
              ruby paas-cf/concourse/scripts/extract_tf_vars_from_terraform_state.rb \
              < vpc-tfstate/vpc.tfstate > vpc.tfvars.sh
              ruby paas-cf/concourse/scripts/extract_tf_vars_from_terraform_state.rb \
              < concourse-tfstate/concourse.tfstate > concourse.tfvars.sh
              ruby paas-cf/concourse/scripts/extract_tf_vars_from_terraform_state.rb \
              < bosh-tfstate/bosh.tfstate > bosh.tfvars.sh
      - task: terraform
        config:
          image: docker:///governmentpaas/docker-terraform
          params:
            TF_VAR_env: {{deploy_env}}
            AWS_DEFAULT_REGION: {{aws_region}}
          inputs:
            - name: terraform-variables
            - name: paas-cf
            - name: cf-tfstate
          run:
            path: sh
            args:
            - -e
            - -c
            - |
              . terraform-variables/vpc.tfvars.sh
              . terraform-variables/concourse.tfvars.sh
              . terraform-variables/bosh.tfvars.sh

              terraform apply -state=cf-tfstate/cf.tfstate -state-out=cf.tfstate paas-cf/terraform/cloudfoundry

      - put: cf-tfstate
        params:
          file: terraform/cf.tfstate

  - name: generate-manifest
    serial_groups: [ deploy ]
    serial: true
    plan:
      - aggregate:
        - get: paas-cf
          passed: ['terraform']
        - get: vpc-tfstate
        - get: bosh-tfstate<commit_msg>Always put CF terraform state<commit_after>resources:
  - name: cf-deployment
    type: bosh-deployment
    source:
      target: https://10.0.0.6:25555
      username: admin
      password: <PASSWORD>}}
      deployment: {{deploy_env}}
      ignore_ssl: true

  - name: paas-cf
    type: git
    source:
      uri: https://github.com/alphagov/paas-cf.git
      branch: {{branch_name}}

  - name: vpc-tfstate
    type: s3
    source:
      bucket: {{state_bucket}}
      region_name: {{aws_region}}
      access_key_id: {{aws_access_key_id}}
      secret_access_key: {{aws_secret_access_key}}
      versioned_file: vpc.tfstate

  - name: bosh-tfstate
    type: s3
    source:
      bucket: {{state_bucket}}
      region_name: {{aws_region}}
      access_key_id: {{aws_access_key_id}}
      secret_access_key: {{aws_secret_access_key}}
      versioned_file: bosh.tfstate

  - name: concourse-tfstate
    type: s3
    source:
      bucket: {{state_bucket}}
      access_key_id: {{aws_access_key_id}}
      secret_access_key: {{aws_secret_access_key}}
      versioned_file: concourse.tfstate
      region_name: eu-west-1

  - name: cf-tfstate
    type: s3
    source:
      bucket: {{state_bucket}}
      access_key_id: {{aws_access_key_id}}
      secret_access_key: {{aws_secret_access_key}}
      versioned_file: cf.tfstate
      region_name: eu-west-1

  - name: cf-manifest
    type: s3
    source:
      bucket: {{state_bucket}}
      region_name: {{aws_region}}
      access_key_id: {{aws_access_key_id}}
      secret_access_key: {{aws_secret_access_key}}
      versioned_file: cf-manifest.yml

jobs:
  - name: s3init
    serial_groups: [ deploy ]
    serial: true
    plan:
      - get: paas-cf
      - task: s3init
        config:
          image: docker:///governmentpaas/curl-ssl
          run:
            path: sh
            args:
            - -e
            - -c
            - |
              paas-cf/concourse/scripts/s3init.sh {{state_bucket}} cf.tfstate paas-cf/concourse/init_files/terraform.tfstate.tpl
          inputs:
          - name: paas-cf
      - put: cf-tfstate
        params:
          file: s3init/cf.tfstate
  - name: terraform
    serial_groups: [ deploy ]
    serial: true
    plan:
      - aggregate:
        - get: paas-cf
          passed: ['s3init']
        - get: vpc-tfstate
        - get: concourse-tfstate
        - get: bosh-tfstate
        - get: cf-tfstate
          passed: ['s3init']
          trigger: true
      - task: terraform-variables
        config:
          image: docker:///ruby
          inputs:
            - name: paas-cf
            - name: vpc-tfstate
            - name: concourse-tfstate
            - name: bosh-tfstate
          run:
            path: sh
            args:
            - -e
            - -c
            - |
              ruby paas-cf/concourse/scripts/extract_tf_vars_from_terraform_state.rb \
              < vpc-tfstate/vpc.tfstate > vpc.tfvars.sh
              ruby paas-cf/concourse/scripts/extract_tf_vars_from_terraform_state.rb \
              < concourse-tfstate/concourse.tfstate > concourse.tfvars.sh
              ruby paas-cf/concourse/scripts/extract_tf_vars_from_terraform_state.rb \
              < bosh-tfstate/bosh.tfstate > bosh.tfvars.sh
      - task: terraform
        config:
          image: docker:///governmentpaas/docker-terraform
          params:
            TF_VAR_env: {{deploy_env}}
            AWS_DEFAULT_REGION: {{aws_region}}
          inputs:
            - name: terraform-variables
            - name: paas-cf
            - name: cf-tfstate
          run:
            path: sh
            args:
            - -e
            - -c
            - |
              . terraform-variables/vpc.tfvars.sh
              . terraform-variables/concourse.tfvars.sh
              . terraform-variables/bosh.tfvars.sh

              terraform apply -state=cf-tfstate/cf.tfstate -state-out=cf.tfstate paas-cf/terraform/cloudfoundry
        ensure:
          put: cf-tfstate
          params:
            file: terraform/cf.tfstate

  - name: generate-manifest
    serial_groups: [ deploy ]
    serial: true
    plan:
      - aggregate:
        - get: paas-cf
          passed: ['terraform']
        - get: vpc-tfstate
        - get: bosh-tfstate
{'fraction_non_alphanumeric': 0.10434165385070389, 'fraction_numerical': 0.005441854962735124, 'mean_word_length': 1.6778587266392144, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4812855', 'n_tokens_mistral': 2783, 'n_tokens_neox': 2761, 'n_words': 486}