Skip to main content

Getting started with terraform

Install terraform:
brew install terraform

Terraform - infrastructure as code.
- To build, manage and modify the infrastructure in a safe and repeatable way

Why terraform?
- to manage environments using configuration language
- here it uses HCL - HashiCorp Configuration Language


Infrastructure as a code?
- Instead of using UI to create resources, we use a file/files to mange infrastructure
- Resource: Any piece of infrastructure (Ex: Virtual machine, security group, network interface)'
- Provider - AWS, GCP, GitHub, Docker
- automates the creation of resources at the time of apply


Advantages of IAC:
- Easily repeatable
- easily readable
- operational certainty with "terraform plan"
- standardized environment builds
- quickly provisioned development environments
- disaster recovery

provider "aws" {
      access_key = "ACCESS_KEY",
      secret_key = "SECRET_KEY",
      region = "us-east-1"
}

# specific type of resource that we want to create, using ID - here example
resource "aws_instance" "example" {
       ami = "ami-8347957"
      instance_type = "t2.micro"
}



Terraform workflow to deploy:
1. scope - confirm what resources need to be created for a given project
2. author - create the configuration file in HCL based on the scoped parameters
3. initialize - run terraform init in the project directory with the configuration files, this will download the correct provider plug-ins for the project
4. plan and apply:
        - terraform plan -> to verify creation process
        - terraform apply -> to create real resources as well as state file that compares future changes in our configuration files to what actually exists in the development environment

create a terraform template (.tf)

provider "aws" {
 profile = "default"
 region = "us-east-1"
}

module "sns-topics" {
 source = "devops-workflow/sns-topics/aws"
 names = ["mt_teraform_example"]
 environment = "dev"

}


initialize the terraform template:

(base) HML-1612:terraform ladu$ terraform init


now apply the template

(base) HML-1612:terraform ladu$ terraform apply


now, to destroy the terraform template:


(base) HML-1612:terraform ladu$ terraform destroy

Comments

Popular posts from this blog

AWS Connect: Reporting and Visualizations

Amazon connect offers: - built in reports i.e., historical and real-time reports.  We can customize these reports, schedule them and can integrate with any BI tool of our requirement to query and view the connect data.  Sample solution provided by AWS: 1. Make sure Connect is exporting the CTR data using Kinesis Data Stream 2. Use Kinesis Firehose to deliver the CTR that are in KDS to S3. (CTR's can be delivered as batch of records, so one s3 object might have multiple CTR's). AWS Lambda is used to add a new line character to each record, which makes object easier to parse.  3. s3 Event Notifications are used to send an event to modify the CTR record and saves it in S3. 4. Athena queries the modified CTR's using SQL. Use partitions to restrict the amount of data scanned by each query, improving performance and reducing cost. Lambda function is used to maintain the partitions.  5. Quicksight is used to visualize the modified CTRs.  Solution variations: Convert re...

Databricks: Job aborted due to stage failure. Total size of serialized results is bigger that spark driver memory.

  While running a databricks job, especially running a job with large datasets and longer running queries that creates a lot of temp space - we might be facing below issue if we have a minimal configuration set to the cluster.  The simple way to fix this would be changing the spark driver config in the databricks cluster tab spark.driver.maxResultSize = 100G (change the GB based on your cluster size)

SoleTechie: Setting up Gitlab

 - Created a gitlab group: Group name : SoleTechie Group URL : http://gitlab.com/soletechie1 Visibility level : private          Group ID : 52826632    - Creating a Gitlab project: Project name : cicd-demo Project URL : https://gitlab.com/soletechie/ Project slug : cicd-demo Project description : Setting up git lab runners and trying to implement the CI-CD flow Project deployment target (optional) : Infrastructure provider (Terraform) Visibility level : Private