---
# System prepended metadata

title: Epic ENG-4 Terraform refactoring

---

# Epic ENG-4 Terraform refactoring


Tasks remaining to be performed within ENG-4 Terraform refactoring


## 1) Move remaining resourcs from Infrastructure repository to foundational repository ()

##### Time estimation -> resource migration 3-4 working days. The migration process is dependent on the time taken to review and evaluate each MR. Working day = 8h

- [x] environments/account:
    - [ ] 307275847480 [MR open](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/215)
    - [ ] newrelic_27588 [MR open](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/233)
- [x] legacy/global [MR open](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/271) 
- [x] monitoring/loging [MR closed no longer required](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/186)
- [x] prod/db: 
    - [x] cmaths [MR closed no longer required](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/198)
    - [x] progression [MR closed no longer required](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/199)
- [x] prod/gitlab (already migrated) [MR Merged](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/193)
- [x] prod/jenkins [MR merged](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/228) 
- [x] prod/maths [MR merged](https://gitlab.sumdog.com/DevOps/infrastructure/-/merge_requests/348)
- [x] prod/questions [MR closed no longer required](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/213)
- [x] prod/wordpress [MR merged ](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/275)
- [x] prod/wordpress-stack [MR merged ](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/275)
- [x] staging/sandbox [MR closed no longer required](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/201)
- [x] test [MR closed no longer required](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/206)
- [x] state (already exist, no need to migrate)
- [ ] **vpc** [MR Open, should be reviewed at the beginning, because of its complexity](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/178)
- [x] **lb** [MR merged, should be reviewed at the beginning, because of its complexity](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/179)
- [x] modules
    - [x] autoscaling-group-no-cloudformation
    - [x] bastion-host (already exist, no need to migrate)
    - [x] efs-filesystem [MR closed no longer required](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/199)
    - [x] route53-entry-alias (already exist, no need to migrate)
    - [x] route53-entry-weighted (already exist, no need to migrate)
    - [x] scheduled-lambda [MR merged](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/271)
    - [x] security-group-rules (already exist, no need to migrate)
    - [x] ubuntu-ami [MR closed no longer required](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/198)
## 2) Transferring legacy services

##### Time estimation -> resource migration 3-4 working days.


- [ ] Resource usage analysis - [draft branch](https://gitlab.sumdog.com/DevOps/infrastructure/-/tree/feature/legacy-service-usage-analysis/environments/legacy/global) WIP
These documents can be usefull:
- https://hackmd.io/8UYHnJQyS72OQHU1zRwOZw
- https://hackmd.io/8g7dZHnAS6y0FHDNzaa-Cg
- https://docs.driftctl.com/0.25.0 - to analyse terraform coverege and usage
- [ ] basic refactoring(removing provider.tf, provider aliases, syntax check) WIP
- [x] list of sg that are not used

This step can be done in parallel with 1,3 

## 3) DNS puzzle
##### Time estimation -> resource migration 2-3 working days.
- [x] Migrate all records from route53 to code in terraform [commit id ](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/commit/1ac31560ede540539cfd189045fabda4e8cbd2a0)
- [x] Provide record granularity, by domain. Provide a simple way to manage records (Using the for loop) 
- [x]  Import all records into the state file on workspace prod and correct any errors 
- [x]  Determine what to do with records that do not exist on the remote state (which records to add/update/delete)
- [x]  Implementing potential changes and generating the final terraform plan
- [x]  Approve everything using terraform apply [MR merged](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/258)

This step can be done in parallel with 1,2

## 4) Terraform version upgrade

##### Time estimation -> resource migration 5-7 working days.

- [x] Module code preparation for Terraform 0.12 version [Git Branch](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/tree/feature/prepare_code_of_module_to_v13)
- [x] Preparation code of services for Terraform 0.12 version [Git Branch](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/tree/feature/prepare_code_of_module_to_v13)
    - [x] databases
    - [x] dns
    - [x] meta
    - [x] legacy/global [MR merged](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/271)
        - [x] accesses
        - [x] assets
        - [x] cache
        - [x] cdn
        - [x] certificates
        - [x] ci_jenkins
        - [x] ci
        - [x] container_repository
        - [x] courses
        - [x] data_sources
        - [x] db_progression
        - [x] db_questions
        - [x] db_reports
        - [x] db_skills
        - [x] db_web
        - [x] db_world
        - [x] elb
        - [x] git
        - [x] lb
        - [x] main
        - [x] mq_maths
        - [x] outputs
        - [x] packer
        - [x] progression
        - [x] question_font
        - [x] reports
        - [x] skills
        - [x] systems
        - [x] test_servers
        - [x] var cert_arns
        - [x] var_cidr_blocks
        - [x] versions
        - [x] web
        - [x] webjob
        - [x] wiki
    - [x] services/
        - [x] analysis (state written in 0.15 version)
        - [x] bastion
        - [x] courses 
        - [x] events-data
        - [x] game-beta
        - [x] game-stack-beta
        - [x] gitlab
        - [x] gitlab-runner
        - [x] http-default-responses
        - [x] jenkins
        - [x] maths
        - [x] pet-test-servers
        - [x] pgadmin
        - [x] progression
        - [x] progression-dynamic
        - [x] progression-redis
        - [x] progression-seed
        - [x] questions
        - [x] rabbitmq
        - [x] redis
        - [x] reports [MR closed no longer required](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/235)
        - [x] reports-beta
        - [x] skills [MR closed no longer required](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/235)
        - [x] web
        - [x] web-canary
        - [x] webjob
        - [x] wordpress
        - [x] wordpress-stack
        - [x] world [MR closed no longer required](https://gitlab.sumdog.com/DevOps/foundational-infrastructure/-/merge_requests/235)
    - [x] storage / 
- [ ] Testing the code after the update
- [ ] Repeat until the latest version is applied 

## 5) Refactoring 

##### Time estimation -> resource migration 4-6 working days.

- [ ] splitting resources into modules, if possible
- [ ] ensure code readability 
- [ ] legacy catalog refactoring

## 6) Prepare documentation









