0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

<Terraform>LAMP環境自動構築

Last updated at Posted at 2025-02-22

まえがき

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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?