2022年8月25日木曜日

Terraform

【terraform aws 公式ドキュメント】
https://registry.terraform.io/providers/hashicorp/aws/latest/docs

tfenv 越しにtrratermインストール
$ git clone https://github.com/tfutils/tfenv.git ~/.tfenv    # インストール
$ sudo ln -s ~/.tfenv/bin/* /usr/local/bin                                  # PATH
$ tfenv list-remote                                                                              # バージョン確認
$ tfenv install 1.2.8
$ tfenv use 1.2.8                                                                                  # バージョン切り替え
$ tfenv list

$ terraform init
$ terraform init -reconfigure
$ terraform plan
$ terraform validate     # 構文チェック
$ terraform fmt              # 構文整形
$ terraform apply
$ terraform destroy

$ terraform destroy -taget = aaaa.aaaa

$ terraform workspace new "stage"
$ terraform workspace new "prod"
$ terraform workspace list
$ terraform workspace select stage
$ terraform workspace delete "prod"


$ terraform console
> cidrsubnet("10.0.0.0/16", 8, 1)
"10.0.1.0/24"
※ネットワーク部を8ビット拡張して、1を代入



1) s3にバケット(test-terraform-tfstate)作成
2) terraform ユーザ作成
3) assume role 作成
     test-AssumeRole-for-terraform
{
"Version":"2012-10-17", "Statement":[ { "Effect":"Allow", "Action":[ "s3:PutObject", "s3:GetObject", "s3:GetObjectVersion", "s3:DeleteObject", "s3:DeleteObjectVersion" ], "Resource":"arn:aws:s3:::test-terraform-ttfstate/*" } ] }
4) terraform ユーザにassume権限を付加


# vi settings.tf
terraform { 
    required_version = "1.2.8"
    backend "s3" {
        backet = "test-terraform-tfstate"
        key = "test-teraform"
        reagion = "ap-northeast-1"
    }
}

provider "aws" {
    reagion = "ap-northeast-1"
}


"demo-vpc"   → "${terraform.workspace}-demo-vpc"


0 件のコメント:

コメントを投稿

シャットダウン時の後処理 (shutdown)

# vi /etc/systemd/system/drop.service [Unit] Description= stop httpgwd DefaultDependencies=no Before=shutdown.target RefuseManualStart=true ...