This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# open on chrome | |
resource "null_resource" "openwebsite" { | |
depends_on = [ | |
kubernetes_service.wp_service | |
] | |
provisioner "local-exec" { | |
command = "minikube service ${kubernetes_service.wp_service.metadata[0].name}" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#service | |
resource "kubernetes_service" "wp_service" { | |
depends_on = [ | |
kubernetes_deployment.wp_deploy, | |
] | |
metadata { | |
name = "wp-service" | |
} | |
spec { | |
selector = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#deployment | |
resource "kubernetes_deployment" "wp_deploy" { | |
depends_on = [ | |
aws_db_instance.rds_wp | |
] | |
metadata { | |
name = "wordpress" | |
labels = { | |
app = "wordpress" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# subnet group for DB | |
resource "aws_db_subnet_group" "sub_ids" { | |
name = "main" | |
subnet_ids = data.aws_subnet_ids.vpc_sub.ids | |
tags = { | |
Name = "DB subnet group" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Security Group for DB | |
resource "aws_security_group" "allow_data_in_db" { | |
name = "allow_db" | |
description = "Allow WP to put data in DB" | |
vpc_id = data.aws_vpc.def_vpc.id | |
ingress { | |
description = "MySQL" | |
from_port = 3306 | |
to_port = 3306 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# VPC data soruce | |
data "aws_vpc" "def_vpc" { | |
default = true | |
} | |
# Subnet data source | |
data "aws_subnet_ids" "vpc_sub" { | |
vpc_id = data.aws_vpc.def_vpc.id | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Kubernetes Provider | |
provider "kubernetes" {} | |
# AWS Provider | |
provider "aws" { | |
profile = "khushi" | |
region = "ap-south-1" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "null_resource" "openwordpress" { | |
depends_on = [ | |
null_resource.wp-sql-connection | |
] | |
provisioner "local-exec" { | |
command = "start chrome http://${aws_instance.wordpress.public_ip}/" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# security group for wordpress | |
resource "aws_security_group" "tf_wp_sg" { | |
name = "tf_wp_sg" | |
description = "wordpress inbound" | |
vpc_id = aws_vpc.tf_vpc.id | |
ingress { | |
description = "http" | |
from_port = 80 | |
to_port = 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_instance" "mysql" { | |
depends_on = [ | |
aws_instance.wordpress | |
] | |
ami = "ami-0732b62d310b80e97" | |
instance_type = "t2.micro" | |
subnet_id = aws_subnet.pvt_subnet2.id | |
security_groups = [aws_security_group.tf_sql_sg.id] | |
key_name = "key1" | |
user_data = <<END |
NewerOlder