Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Getting started with HashiCorp Terraform

Getting started with HashiCorp Terraform

Avatar for Bruno Schaatsbergen

Bruno Schaatsbergen

August 06, 2024
Tweet

More Decks by Bruno Schaatsbergen

Other Decks in Technology

Transcript

  1. ©2024 HASHICORP 4 Execution errors lead to challenging problems. Traditional

    IT infrastructure Manual hardware and software provisioning. Not easy to enforce compliance standards.
  2. ©2024 HASHICORP 5 Minimize errors and reduce blast radius with

    policies. Modern IT infrastructure Automated hardware and software provisioning. From one or two continents to global and multi-cloud.
  3. ©2024 HASHICORP 7 Write once, deploy everywhere. Benefits of Infrastructure

    as Code Track, review and revert. Enforce compliance and security policies.
  4. ©2024 HASHICORP A community-powered product Providers by HashiCorp and partners

    AWS, Google, Kubernetes, etc. Providers by our community Dominos, Unifi, Spotify, etc.
  5. ©2024 HASHICORP Specify the required providers and configure version constraints.

    HashiCorp Terraform Defining requirements terraform { required_version = ">= 1.8.0" required_providers { aws = { source = "hashicorp/aws" version = ">= 5.0.0, < 6.0.0" } } } terraform.tf
  6. ©2024 HASHICORP Configure how a Terraform provider interacts with an

    upstream API. HashiCorp Terraform Configuring a provider provider "aws" { region = "eu-central-1" default_tags { tags = { "environment" = "dev" } } } providers.tf
  7. ©2024 HASHICORP Defines an S3 bucket with a unique name

    and enables object versioning. HashiCorp Terraform Defining a resource resource "aws_s3_bucket" "example" { bucket_prefix = "example" } resource "aws_s3_bucket_versioning" "example" { bucket = aws_s3_bucket.example.id versioning_configuration { status = "Enabled" } } bucket.tf
  8. ©2024 HASHICORP Downloads the provider and creates a lock file.

    HashiCorp Terraform Initializing a directory >_ terraform init Initializing provider plugins… - Finding hashicorp/aws versions matching ">= 5.0.0" - Installing hashicorp/aws v5.55.0 - Installed hashicorp/aws v5.55.0 (signed by HashiCorp) Terraform has created a lock file .terraform.lock.hcl to record the provider selections it made above. Terraform has been successfully initialized! Terminal
  9. ©2024 HASHICORP Creates an execution plan to preview Terraformʼs planned

    changes to your infrastructure. HashiCorp Terraform Planning a change >_ terraform plan Terraform will perform the following actions: # aws_s3_bucket.example will be created + resource "aws_s3_bucket" "example" # aws_s3_bucket_versioning.example will be created + resource "aws_s3_bucket_versioning" "example" Plan: 2 to add, 0 to change, 0 to destroy. To perform these actions, run the following command to apply: terraform apply Terminal
  10. ©2024 HASHICORP Applies the execution plan, making Terraformʼs planned changes

    to your infrastructure. HashiCorp Terraform Applying a change >_ terraform apply aws_s3_bucket.example: Creating... aws_s3_bucket.example: Creation complete aws_s3_bucket_versioning.example: Creating... aws_s3_bucket_versioning.example: Creation complete Apply complete! Resources: 2 added, 0 changed, 0 destroyed. Terminal