Terraform Features introduction

Terraform is an open-source infrastructure as code software tool that provides a consistent CLI workflow to manage hundreds of cloud services. Terraform codifies cloud APIs into declarative configuration files.

https://www.terraform.io

Deliver Infrastructure as Code

Write

Write infrastructure as code using declarative configuration files. HashiCorp Configuration Language (HCL) allows for concise descriptions of resources using blocks, arguments, and expressions.


resource "aws_instance" "iac_in_action" {
ami = var.ami_id
instance_type = var.instance_type
availability_zone = var.availability_zone

// dynamically retrieve SSH Key Name
key_name = aws_key_pair.iac_in_action.key_name

// dynamically set Security Group ID (firewall)
vpc_security_group_ids = [aws_security_group.iac_in_action.id]

tags = {
Name = “Terraform-managed EC2 Instance for IaC in Action”
}
}

Plan

Run terraform plan to check whether the execution plan for a configuration matches your expectations before provisioning or changing infrastructure.


$ terraform plan
An execution plan has been generated and is shown below.

Resource actions are indicated with the following symbols:
+ create

Terraform will perform the following actions:

# aws_ebs_volume.iac_in_action will be created
+ resource “aws_ebs_volume” “iac_in_action” {
+ arn = (known after apply)
+ availability_zone = “us-east-1a”
+ encrypted = (known after apply)
+ id = (known after apply)
+ iops = 1000
+ kms_key_id = (known after apply)
+ size = 100
+ snapshot_id = (known after apply)
+ tags = {
+ “Name” = “Terraform-managed EBS Volume for IaC in Action”
}
+ type = “io1”
}

Plan: 1 to add, 0 to change, 0 to destroy.

Apply

Apply changes to hundreds of cloud providers with terraform apply to reach the desired state of the configuration.

Terraform Features introduction

Features

  • Define infrastructure as code to manage the full lifecycle — create new resources, manage existing ones, and destroy those no longer needed.


variable "ami_id" {
type = string
description = "AMI ID to use"
default = "ami-09d95fab7fff3776c"
}

variable “instance_type” {
type = string
description = “Instance type to use”
default = “t3.micro”
}

variable “availability_zone” {
type = string
description = “Availability Zone to use”
default = “us-east-1a”
}

Automatically download and install community or partner modules from the registry with terraform init


$ terraform init

Initializing the backend…

Initializing provider plugins…
– Finding hashicorp/local versions matching “~> 1.4.0″…
– Finding hashicorp/http versions matching “1.2.0”…
– Finding hashicorp/aws versions matching “~> 2.70″…
– Finding hashicorp/tls versions matching “~> 2.1″…
– Installing hashicorp/local v1.4.0…
– Installed hashicorp/local v1.4.0 (signed by HashiCorp)
– Installing hashicorp/http v1.2.0…
– Installed hashicorp/http v1.2.0 (signed by HashiCorp)
– Installing hashicorp/aws v2.70.0…
– Installed hashicorp/aws v2.70.0 (signed by HashiCorp)
– Installing hashicorp/tls v2.2.0…
– Installed hashicorp/tls v2.2.0 (signed by HashiCorp)

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running “terraform plan” to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

Terraform allows operators to safely and predictably make changes to infrastructure, with clearly mapped resource dependencies and separation of plan and apply.


$ terraform plan

Refreshing Terraform state in-memory prior to plan…
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

————————————————————————

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create

Terraform will perform the following actions:

# aws_ebs_volume.iac_in_action will be created
+ resource “aws_ebs_volume” “iac_in_action” {
+ arn = (known after apply)
+ availability_zone = “us-east-1a”
+ encrypted = (known after apply)
+ id = (known after apply)
+ iops = 1000
+ kms_key_id = (known after apply)
+ size = 100
+ snapshot_id = (known after apply)
+ tags = {
+ “Name” = “Terraform-managed EBS Volume”
}
+ type = “io1”
}

Plan: 1 to add, 0 to change, 0 to destroy.

Dependency graphing
Easily generate terraform plan, refresh state, and more, with Terraform config dependency graphing.

Terraform Features introduction

Map real world resources to your configuration, keep track of metadata, and improve performance for large infrastructures.

{
"version": 4,
"terraform_version": "0.13.5",
"serial": 26,
"lineage": "3c255742-debd-2c33-ff5f-53a5181f36b2",
"outputs": {},
"resources": []
}

CDK for Terraform (experimental) allows you to define infrastructure code in TypeScript, Python, Java, C#, and Go, using the 1000+ existing Terraform providers and HCL Terraform modules.

Terraform Features introduction

Choose from an array of providers for your cloud platforms and services, add them to your configuration, then use their resources to provision infrastructure.

Terraform Features introduction

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/147743.html

(0)
上一篇 2021年9月9日
下一篇 2021年9月9日

相关推荐

发表回复

登录后才能评论