🦊基础设施即代码
Terraform简介


Terraform入门


构建公有云漏洞环境
Last updated




Last updated
#Centos7
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo
https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo yum -y install terraformterraform {
required_providers {
tencentcloud = {
source = "tencentcloudstack/tencentcloud"
version = "1.78.15"
}
}
}mkdir test
cd test
vim version.tf
terraform initvariable "tencentcloud_secret_id" {
type = string
description = "Set TencentCloud access key id."
sensitive = true
nullable = false
}
variable "tencentcloud_secret_key" {
type = string
description = "Set TencentCloud secret access key."
sensitive = true
nullable = false
}
tencentcloud_secret_id = "xxx" #填写AK
tencentcloud_secret_key = "xxx" #填写密钥
provider "tencentcloud" {
secret_id = var.tencentcloud_secret_id
secret_key = var.tencentcloud_secret_key
region = "ap-beijing"
}export TF_VAR_tencentcloud_access_key="LxxxT”
export TF_VAR_tencentcloud_secret_key="zWSKxxxIUu”
export TF_VAR_region="cn-beijing-b"provider "tencentcloud" {
secret_id = var.tencentcloud_secret_id
secret_key = var.tencentcloud_secret_key
region = "ap-hongkong"
}
resource "tencentcloud_instance" "test" {
instance_name = "test_terraform" #实例名称
availability_zone = "ap-hongkong-2" #地区
image_id = "img-l8og963d" #镜像ID
instance_type = "SA2.MEDIUM2" #机器类型
allocate_public_ip = true
internet_max_bandwidth_out = 50
security_groups = ["sg-3yy8drp7"] #安全组
user_data_raw = <<EOF
#!/bin/bash
touch /tmp/test.txt
EOF
}
terraform init #初始化
terraform plan #计划与预览
terraform apply #申请资源
terraform show #显示资源
terraform destroy #销毁资源docker pull
registry.cn-hongkong.aliyuncs.com/huoxian_pub/terraformgoat_tencentcloud:0.0.7
docker run -itd --name terraformgoat_tencentcloud_0.0.7
registry.cn-hongkong.aliyuncs.com/huoxian_pub/terraformgoat_tencentcloud:0.0.7
docker exec -it terraformgoat_tencentcloud_0.0.7 /bin/bash cd /TerraformGoat/tencentcloud/cvm/cvm_ssrf/vim terraform.tfvarsterraform init
terraform apply