Skip to content

Instantly share code, notes, and snippets.

View chrome.tf
# 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}"
}
}
View wordpress.tf
#service
resource "kubernetes_service" "wp_service" {
depends_on = [
kubernetes_deployment.wp_deploy,
]
metadata {
name = "wp-service"
}
spec {
selector = {
View wordpress.tf
#deployment
resource "kubernetes_deployment" "wp_deploy" {
depends_on = [
aws_db_instance.rds_wp
]
metadata {
name = "wordpress"
labels = {
app = "wordpress"
}
View rds.tf
# 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"
}
}
View rds.tf
# 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
View provider.tf
# 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
}
View provider.tf
# Kubernetes Provider
provider "kubernetes" {}
# AWS Provider
provider "aws" {
profile = "khushi"
region = "ap-south-1"
}
View chrome.tf
resource "null_resource" "openwordpress" {
depends_on = [
null_resource.wp-sql-connection
]
provisioner "local-exec" {
command = "start chrome http://${aws_instance.wordpress.public_ip}/"
}
}
View WPsg.tf
# 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
View SQLinstance.tf
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