まえがき
Terraformの学習用に作成しました。
Linuxのローカル環境で実行しています。
事前準備
$ sudo dnf install terraform -y
$ terraform --version
$ vi variables.tf #内容は以下へ記載
$ vi terraform.tfvars #内容は以下へ記載
$ vi main.tf #内容は以下へ記載
TerraformでLAMP環境自動構築
variables.tf
variable "server_ip" {
description = "ターゲットLinuxサーバのIPアドレス"
type = string
default = "127.0.0.1"
}
terraform.tfvars
server_ip = "127.0.0.1"
main.tf
provider "local" {}
resource "null_resource" "install_lamp" {
provisioner "local-exec" {
command = <<EOT
sudo yum update -y
sudo dnf install -y httpd mariadb-server php php-mysqlnd
sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl start mariadb
sudo systemctl enable mariadb
echo '<?php phpinfo(); ?>' | sudo tee /var/www/html/index.php
sudo systemctl restart httpd
EOT
}
}
$ terraform init
$ terraform plan
$ terraform apply
$ sudo systemctl status httpd
$ curl http://localhost/:80