Platform Questions Flashcards

(44 cards)

1
Q

What is the difference between a provider and a resource in Terraform?

A

A provider is the cloud platform e.g. Azure, AWS and the resource is the services that you can access for that platform e.g. EC2, Users, RDS etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why would you use Terraform over Ansible? Three strengths of Terraform

A

Terraform’s strength is in the infrastructure provisioning (like to AWS, Azure etc).

  • Declarative
  • State
  • Idem-potency (it won’t run things over again that it knows its already executed)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Is Terraform declarative or imperative and what is the difference?

A

Terraform is declarative which means you just update your config file with your desired state and Terraform will figure out how to get there. E.g. if you want to update a firewall config Terraform might remove the old one then add a new one.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Ansible good for?

A

Ansible - config management, includes things like application deployment. Working with resources that are already created.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define VPC

A

A virtual private cloud (VPC) is a secure, isolated private cloud hosted within a public cloud.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a dependency in Terraform?

A

Dependencies control the order in which Terraform creates, updates or destroys resources.

You can enforce dependencies explicitly using the ‘depends_on’ keyword.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a provisioner in Terraform?

A

Provisioners are used to run scripts or commands on a resource after it’s created or before it is destroyed.

Use sparingly because they introduce dependencies outside of Terraform’s control.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is state locking in Terraform?

A

State locking is a mechanism to prevent multiple users from making concurrent changes to the same infrastructure, which could lead to conflicts or corruption in the state file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a state file in Terraform?

A

Terraform keeps a state file with the current setup saved as a snapshot.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Where is the state file saved/where should it be saved?

A

By default Terraform saves the state file locally but it should be saved in a backend like AWS S3 with DynamoDB.

S3 stores the state file itself, making it accessible to team members. DynamoDB provides a locking mechanism to prevent concurrent modifications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are four common Terraform errors? And how to fix

A

State lock errors - if no one else if running a Terraform command you can manually release the lock by deleting the locking entry in DynamoDB.

Provider version mismatches.

Missing dependency - run Terraform refresh and see what is missing.

Config syntax/logic errors - fix then run Terraform validate

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What should you do if there is a failed Terraform deployment?

A
  1. Understand what happened - check the logs, review partial changes that Terraform has applied.
  2. Refresh and check the current state - run Terraform refresh, identify remaining changes.
  3. Decide on rolling back or moving forward - if rolling back then identify partially created resources and remove them manually, revert to an earlier commit then refresh, plan, apply. If moving forward, you can fix the config error/permission issue then rerun terraform apply.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Where do you store AWS creds when using Terraform with GitHub Actions?

A

GitHub secrets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the two key files for using Terraform with GitHub Actions?

A

Terraform config file and GitHub Actions workflow file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What should be in the Terraform config file for building a review environment?

A

Define AWS provider

Variable for commit sha passed from GitHub actions

Create EC2 instance resource with config to install Docker, login to ECR, docker pull image from ECR, docker run.

Add tags to resource with name and commit SHA.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What should be in the GitHub Actions workflow file for creating a review environment?

A

on: push: branches: ‘feature’

jobs:
- Checkout code
- Set up AWS CLI
- Install dependencies like node etc and run unit tests on GitHub runner
- Terraform init
- Delete old image from ECR
- Terraform destroy (kill any existing EC2 instances)
- Terraform plan
- Terraform apply
- Load sample data (via bash script)
- Run E2E tests in parallel on GitHub runner

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Why is the commit SHA used for review envs?

A

It is used as part of the Docker image tag to ensure that each branch/commit gets its own unique environment.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What if someone wanted to update 100 AWS security groups as a once off?

A

Prep Terraform config file with 100 sec groups and details.

Run Terraform locally or in GitHub runner:
- terraform init
- terraform plan
- terraform apply

19
Q

What would be in the config file for updating 100 AWS security groups?

A

Define AWS provider

Define a list of security groups and their properties

Create security groups resources dynamically from list

20
Q

What would be in the GitHub Actions workflow file for updating 100 AWS security groups?

A

on: push

jobs:
- checkout code
- set up AWS CLI
- terraform init
- terraform plan
- terraform apply

21
Q

What if someone wanted to have their Terraform plan checked before applying it?

A

Plan on push and apply on merge.

2 separate actions:

on: push: branches: ‘feature’
jobs:
- checkout code
- set up AWS CLI
- terraform init
- terraform plan

Reviewed and approved then:

on: push: branches: ‘main’
jobs:
- checkout code
- set up AWS CLI
- terraform init
- terraform apply

22
Q

What are 5 popular pipeline tools and their Terraform integration?

A

GitHub Actions - .github/workflows/terraform_plan.yml

Jenkins - Jenkinsfile

GitLab - .gitlab_ci.yml

Azure DevOps - azure-pipelines.yml

AWS CodePipeline - used with AWS CodeBuild

23
Q

What are the two methods for running a GitHub Actions workflow (timing)?

A

On a schedule:
- on: schedule: cron: ‘00*0’

On a trigger:
- on: push: branches: main/feature

24
Q

What is an AWS Security Group?

A

Acts as a virtual firewall to control incoming and outgoing traffic.

Security groups allow you to specify rules to allow or block traffic based on IP addresses, ports and protocols.

25
How can you run unit tests and E2E tests with GitHub Actions?
Run unit tests locally in GHA runner. Use Terraform to provision the review env in EC2. Run E2E tests. After the review env is up, the E2E tests can be configured to point to the review environment and run on the GHA runner or from a container.
26
What AWS service manages user permissions and roles?
IAM - Identity and Access Management. Users, roles and policies (JSON docs that define permissions for users or roles)
27
What is AWS VPC?
Virtual Private Cloud is a virtual network in AWS that isolates resources and defines how they communicate.
28
What is a subnet?
Dividing a network into smaller network to organise the resources.
29
What is a NAT gateway?
Allows private instances to access the internet.
30
What controls traffic to and from resources in a VPC?
Security groups and network ACLs
31
What is AWS specific version of Terraform?
AWS CloudFormation
32
What is auto scaling?
Automatically adjusts the number of EC2 instances in response to traffic demand.
33
What is the AWS service that is Platform as a Service?
Elastic Beanstalk
34
Where do you check logs in AWS?
CloudWatch Logs, alarms, metrics
35
What is the difference between a Docker image and container?
Docker image = blueprint/template Docker container = running instance of an image
36
What is the Azure equivalent of the following? AWS CloudFormation, VPC, EC2, Elastic Beanstalk
CloudFormation = Azure Resource Manager VPC = Virtual Networks (VNets) EC2 = Azure VMs Elastic Beanstalk = Azure App Service
37
What is the Azure equivalent of the following? AWS Lambda, S3, IAM, CodePipeline
Lambda = Azure Functions S3 = Blob storage/file storage IAM = Azure Active Directory CodePipeline = Azure DevOps
38
What is the Azure equivalent of the following? AWS ELB, Route 53
ELB = Azure Load Balancer Route 53 = Azure Traffic Manager
39
Name three cloud agnostic CICD tools. Name two cloud specific CICD tools
Cloud agnostic = Jenkins, GitLab, GitHub Azure = Azure DevOps AWS = AWS CodePipeline, CodeBuild
40
If you wanted to provision infrastructure would you use Terraform or Ansible?
Terraform
41
If you wanted to configure software on existing servers would you use Terraform or Ansible?
Ansible
42
If you had a multi cloud infra setup would you use Terraform or Ansible?
Terraform
43
If you wanted to do some quick fixes or ad hoc tasks would you use Terraform or Ansible?
Ansible
44
If you wanted to perform an end to end application deployment would you use Terraform or Ansible?
Both Terraform provisions infra Ansible configures and deploys