DevOps Classroom notes 22/Aug/2026

terraform import

  • to import existing resources to terraform or manuall created resources add to tf state file

import s3

  1. backend file and provide
  2. import resoure two ways
import {
  to = aws_s3_bucket.example
  identity = {
    bucket = "bucket-name"
  }
}

resource "aws_s3_bucket" "example" {
  ### Configuration omitted for brevity ###
}

terraform import aws_s3_bucket.example bucket-name

Note: After import completed remove import configure and run terraform init && terraform plan and fix plan changes and make tf state no changes then apply changes by terraform apply

Task:

create ec2 instance & security group manually and import resources to terraform statefile

Terraform workspace

  • create virtual enviromenmt and deploy resource specific names

  • before create workspace need run terraform init -backend-config="key=dev/terraform.tfstate"

  • terraform workspace

terraform workspace
Usage: terraform [global options] workspace

  new, list, show, select and delete Terraform workspaces.

Subcommands:
    delete    Delete a workspace
    list      List Workspaces
    new       Create a new workspace
    select    Select a workspace
    show      Show the name of the current workspace

Ex:

  1. create workspace terraform workspace new dev
  2. select workspace terraform workspace select dev
variable "s3-name" {
    type = string
    default = "qt-demo-s3-app"
}

locals {
  enviroment = "${terraform.workspace}"
  s3_name = "${var.s3-name}-${terraform.workspace}"
}


resource "aws_s3_bucket" "import_s3" {
    bucket = local.s3_name
}

Watch class recording and create workspace.

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%