Friday, June 4, 2021

Day12 - Terraform workspace, regex

 Day12 - Terraform - 06042021

Workspace, regex


> mkdir wp; cd wp

> notepad w.tf
provider "aws" {
 region = "ap-south-1"
 profile = "default"
}


variable "type" {
 type = map
 default = {
  dev = "t2.micro"
  test = "t2.small"
  prod = "t2.large"
  }
}
resource "aws_instance" "webos1" {
    ami = "ami..."
    instance_type = "t2.micro"
      security_group     = [ "webport-allow" ]
    key_name = "terraform_key"

    tags = {
       Name = "We server by TF"
    }
}

*/
output "o1" {
  value = terraform.workspace
}

get help
> terraform workspace -h
> tf worksapce list
> tf workspace show





==================


> notepad w.tf
provider "aws" {
 region = "ap-south-1"
 profile = "default"
}


variable "type" {
 type = map
 default = {
  dev = "t2.micro"
  test = "t2.small"
  prod = "t2.large"
  }
}
resource "aws_instance" "webos1" {
    ami = "ami..."
    instance_type = lookup (var.type, terraform.worspace)
 
    tags = {
       Name = "We server by TF"
    }
}

*/
output "o1" {
  value = terraform.workspace
}


> tf worspace show
> tf apply
> tf workspace -h
>

chnage your env
> tf workspace select dev
> tf worksapce show
> tf apply    @ it will automatically understands you are on dev env.

----------------------

Google: terraform regex

regex function

go through the example ..

say you are retriving some values
http://<IP>:<port/path/file.html

- create pattern, format
regex(pattern, format)


regex{}
get only characters
> terraform console
regex("[a-z]+", "24442,5323423basjkdhfsdh4")


do more function

replace function

> replace("1 + 2 + 3", "+", "-")
1 - 2- 3

> replace (hello world". "/w.*d/", "everybody")

There are lots of functions and go through these documents..

--------------------------------------------

FullStack
workspace
- Dev  -> GCP
- Test -> AZ
- Prod -> AWS

EC2 - web server
    - DB RDS server

Azure
- VM instances
- Launch database service


google - multicould strategy example

FE (WordPress)    -> GCP      
DB (MySql)     -> AWS - RDS

--------------------------------------------

google teraform data sources
- to retirve partucular value
and use on other resource..


resource "aws_instance" "app" {
 ami = "$(data.aws_ami.app_ami.id}"
 instance_type = "t2.micro"
}


No comments:

Post a Comment

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...