Skip to content

Ganarok/ganarok-tf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Some time spent using Terraform to create an EC2, S3 or a MongoDB cluster. Feel free to use this code as a starting point for your own projects !

Work to do here :

  • Test even more OpenTofu tools
  • Try to do a lightweight/cheaper version of the MongoDB cluster

################################################################################

Some Terraform configuration

################################################################################

Terraform is an infrastructure as code tool that lets you build, change, and version cloud and on-prem resources safely and efficiently.

Prerequisites

  • Terraform >= 1.5
  • You also need to define a few environment variables LOCALLY

Before anything else, you need to login to AWS and create a user with the following permissions:

  • AmazonEC2FullAccess
  • AmazonVPCFullAccess
  • AmazonS3FullAccess
  • AdministratorAccess

This service is available in the AWS Web-app under the IAM service :

AWS Web App > IAM > Users (on the left panel) > Add Users > (set the user name + check provide user access, then check "I want to create an IAM user" (define a password)) > Attach policies directly. Add following policies:

  • AmazonEC2FullAccess
  • AmazonVPCFullAccess
  • AmazonS3FullAccess
  • AdministratorAccess

... and then confirm.

Then go back to users, click on the user you just created, and click on the "Security credentials" tab. Here you can find the Access key ID and the Secret access key that you need to define locally by creating a new Access key. Finally, you'll get these variables:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY

These ones are used by Terraform to authenticate with AWS. Define them locally by running the following commands:

export AWS_ACCESS_KEY_ID=<your_access_key_id>
export AWS_SECRET_ACCESS_KEY=<your_secret_access_key>

This operation is only needed once (if you're creating a brand new infrastructure). You'll also need to define in variables.tf the following variables (depending on your needs):

  • project_name
  • instance_type

Usage

Initialize

Initiliaze the terraform configuration

terraform init

Plan

Generate and show an execution plan. This is mainly used to check whether the execution plan for a set of changes matches your expectations without making any changes to real resources or to the state.

terraform plan

Apply

Apply the changes required to reach the desired state of the configuration, or the pre-determined set of actions generated by a terraform plan execution plan.

terraform apply

Note

If you want to get back some information about the infrastructure you just created, you can run the following command:

terraform show

... or, if you just need outputs:

terraform output -json

About

Some time spent with Terraform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published