Initial setup to git-gitlab-terraform connection.

Initial setup to git-gitlab-terraform connection.

PC to AWS connection config.

  1. create amazon account.
  2. configure the aws account to use MFA, could be admin permision or limited permission. Use authy app to auhenticate.
  3. configure aws account with a access key to be used with aws vault.
  4. install aws-vault
  5. run aws-vault add “awsuserhere”
  6. vi ~/.aws/config

add

[awsuserhere]
region=”regionhere”

mfa_serial=”mfaserialhere” mfa serial is under the user credential a string like aws:iam::202575445566:mfa/userforaws

  1. run ./brew/aws-vault exec userterraform –duration=12h

PC git to Gitalb config.

  1. Create a ssh public key to remote access in your linux.
  2. go to gitlab account , user setting and configure ssh key to access gitlab.
  3. Create a new project
  4. Configure project to merge files just from members. setting-general-project visibility, pipelines, chose “only project member”.
  5. Setting-Ci/CD-General pipelines, uncheck public pipelines to not leave the pipeline public.
  6. protected branches, setting-reposirory-protected branches, Branch: create *-release allowed to merge and to push: just form maintaines.
  7. Protected tags, setting-repositories-protected tags,Branch: create *-release allowed to create: just form maintaines.
  8. you can use gti clone, git pull origin, gti add . , git commit -am “comment about change”, git push origin, git checkout -b folder/name

git-lab to aws
create a user to be used by gitlab for CI/CD
configure gitlab to use that user, set variables for aws in Gitlab CI/CD variables of the project.

To use terraform centralized

  1. Create a S3 bucket to save the terraform state. tfstate
  2. create a table to save the state, to not have 2 people working at the same time in the same terraform project, using dynamodb table.
    3.create the files with the connections to aws from terraform, the files is main.tf
    Terrafom {
    }
  3. create docker-compose.yml, enviroment where the terraforma is going to run.

Install Docker and docker compose.
Install docker with apt-get install docker
and docker compose with:

1.sudo curl -L “https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)” -o /usr/local/bin/docker-compose
this is for version 1.27.4 for the last one verify with the site.

after that:

  1. sudo chmod +x /usr/local/bin/docker-compose
  2. sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
  3. initialize terraform
    docker-compose -f docker-compose.yml run –rm terraform init.
Comments are closed.