diff --git a/Output-code/mysql-vars.yml b/Output-code/mysql-vars.yml deleted file mode 100644 index 918bfb5f114ba0358f4f1d357b721208f055f10c..0000000000000000000000000000000000000000 --- a/Output-code/mysql-vars.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -db_user: app1user -db_password: app1user -db_name: app1 \ No newline at end of file diff --git a/Output-code/outputNetwork.tf b/Output-code/outputNetwork.tf deleted file mode 100644 index f8a76aabd9aaa1c3858b4e89896021f23adb48b3..0000000000000000000000000000000000000000 --- a/Output-code/outputNetwork.tf +++ /dev/null @@ -1,14 +0,0 @@ -resource "aws_subnet" "aws_subnet" { - vpc_id = aws_vpc.aws_vpc.id - cidr_block = "10.0.1.0/24" - tags = { - Name = "piacere_subnet" - } - -} -resource "aws_vpc" "aws_vpc" { - cidr = "10.0.0.0/16" - tags = { - Name = "piacere_vpc" - } -} diff --git a/Output-code/outputdb.tf b/Output-code/outputdb.tf deleted file mode 100644 index d4cb60bdd8f2279cc39117657e3e4098dde90ea8..0000000000000000000000000000000000000000 --- a/Output-code/outputdb.tf +++ /dev/null @@ -1,14 +0,0 @@ -resource "aws_db_instance" "education" { - identifier = "education" - instance_class = "db.t3.micro" - allocated_storage = 5 - engine = "postgres" - engine_version = "13.1" - username = "edu" - password = var.db_password - db_subnet_group_name = aws_db_subnet_group.education.name - vpc_security_group_ids = [aws_security_group.rds.id] - parameter_group_name = aws_db_parameter_group.education.name - publicly_accessible = true - skip_final_snapshot = true -} diff --git a/Output-code/outputvm.tf b/Output-code/outputvm.tf deleted file mode 100644 index fb8865784b64f2b332ce26da5cfb1df5e94cffef..0000000000000000000000000000000000000000 --- a/Output-code/outputvm.tf +++ /dev/null @@ -1,32 +0,0 @@ - -data "aws_ami" "ami1" { - #executable_users = ["self"] - most_recent = true - name_regex = "ubuntu*" - #owners = ["self"] - - owners = ["099720109477"] # Canonical -} -resource "aws_instance" "instance1" { - ami = data.aws_ami.ami1.id - instance_type = "t2.micro" - tags = { - Name = "firstvm" - } -} - -data "aws_ami" "ami2" { - #executable_users = ["self"] - most_recent = true - name_regex = "ubuntu*" - #owners = ["self"] - - owners = ["099720109477"] # Canonical -} -resource "aws_instance" "instance2" { - ami = data.aws_ami.ami2.id - instance_type = "t2.micro" - tags = { - Name = "secondvm" - } -} diff --git a/Output-code/postgres-vars.yml b/Output-code/postgres-vars.yml deleted file mode 100644 index 918bfb5f114ba0358f4f1d357b721208f055f10c..0000000000000000000000000000000000000000 --- a/Output-code/postgres-vars.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -db_user: app1user -db_password: app1user -db_name: app1 \ No newline at end of file diff --git a/Output-code/wordpress-vars.yml b/Output-code/wordpress-vars.yml deleted file mode 100644 index b62b45763ad631ef67141d36150700bfb9697eeb..0000000000000000000000000000000000000000 --- a/Output-code/wordpress-vars.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -WORDPRESS_DB_HOST: 10.10.10.10 -WORDPRESS_DB_USER: app1user -WORDPRESS_DB_PASSWORD: app1user -WORDPRESS_DB_NAME: app1 -WORDPRESS_TABLE_PREFIX: wp \ No newline at end of file diff --git a/__pycache__/ansibleBuilder.cpython-39.pyc b/__pycache__/ansibleBuilder.cpython-39.pyc deleted file mode 100644 index 245f04603423cbbd1fc1aaee129825259c9264d9..0000000000000000000000000000000000000000 Binary files a/__pycache__/ansibleBuilder.cpython-39.pyc and /dev/null differ diff --git a/__pycache__/ansibleUtils.cpython-39.pyc b/__pycache__/ansibleUtils.cpython-39.pyc deleted file mode 100644 index 0ba03ad252deaa81133f89e1de3929d6ac1ee814..0000000000000000000000000000000000000000 Binary files a/__pycache__/ansibleUtils.cpython-39.pyc and /dev/null differ diff --git a/ansibleBuilder.py b/ansibleBuilder.py deleted file mode 100644 index 424ef7016ed0ef269814a6e5795c3cf858c2e63b..0000000000000000000000000000000000000000 --- a/ansibleBuilder.py +++ /dev/null @@ -1,60 +0,0 @@ -import ansibleUtils - -class InputData: - app_type: str - code_path: str - template_type: str - template_path: str - template_data: map - - def __init__(self, app_type, code_path, template_type, template_path, template_data): - self.app_type = app_type - self.code_path = code_path - self.template_type = template_type - self.template_path = template_path - self.template_data = template_data - -class TemplateInfo: - path: str - type: str - data: map - - def __init__(self, input_data: InputData): - self.path = input_data.template_path - self.type = input_data.template_type - self.data = input_data.template_data - -class AnsibleModule: - - def get_template(self, template_complete_path): - template = open(template_complete_path, "r") - return template.readlines() - - def edit_template(self, template_type, template_list, template_data, kind): - if template_type == "postgres": - new_file = ansibleUtils.databases_postgres(template_list, template_data, kind) - if template_type == "mysql": - new_file = ansibleUtils.databases_mysql(template_list, template_data, kind) - if template_type == "wordpress": - new_file = ansibleUtils.service_wordpress(template_list, template_data, kind) - return new_file - - def write_file(self, edited_content, code_path: str): - file = open(code_path, "w+") - file.write(edited_content) - file.close() - -class AnsibleICG: - - def generate_code(self, input_data: InputData): - - templateFile = TemplateInfo(input_data) - ansibleModule = AnsibleModule() - - kinds = ["play", "vars"] - for kind in kinds: - template_complete_path = templateFile.path + templateFile.type + "-" + kind + ".tpl" - template_list = ansibleModule.get_template(template_complete_path) - edited_content = ansibleModule.edit_template(templateFile.type, template_list, templateFile.data, kind) - code_path = input_data.code_path + templateFile.type + "-" + kind + ".yml" - ansibleModule.write_file(edited_content, code_path) diff --git a/ansibleUtils.py b/ansibleUtils.py deleted file mode 100644 index dbfe787322b28405424dcf6274c182a93c259d0f..0000000000000000000000000000000000000000 --- a/ansibleUtils.py +++ /dev/null @@ -1,43 +0,0 @@ -from ansibleBuilder import * - -def generic_matcher(template_list, specific_data): - matching_lines = [s for s in template_list if "###" in s] - for line in matching_lines: - line_plit = line.split('###') - var = line_plit[1] - index = template_list.index(line) - template_list[index] = line_plit[0]+specific_data[var]+line_plit[2] - return template_list - -def databases_postgres(template_list, template_data, kind): - if kind == "vars": - new_template_list = generic_matcher(template_list, template_data[kind]) - if kind == "play": - if template_data[kind]["OS"] == "debian": - specific_data = {"OS": "apt", "OS_PACKETS": " - postgresql-10"} - elif template_data[kind]["OS"] == "centos": - specific_data = {"OS": "yum", "OS_PACKETS": " - postgresql10\n - postgresql10-server\n - postgresql10-contrib\n - postgresql10-libs"} - new_template_list = generic_matcher(template_list, specific_data) - return "".join(new_template_list) - -def databases_mysql(template_list, template_data, kind): - if kind == "vars": - new_template_list = generic_matcher(template_list, template_data[kind]) - if kind == "play": - if template_data[kind]["OS"] == "debian": - specific_data = {"OS": "apt", "OS_PACKETS": " - mysql-server\n - mysql-client\n - python-setuptools\n - python-mysqldb\n - libmysqlclient-dev\n - python3-pip"} - elif template_data[kind]["OS"] == "centos": - specific_data = {"OS": "yum", "OS_PACKETS": " - postgresql10\n - postgresql10-server\n - postgresql10-contrib\n - postgresql10-libs"} - new_template_list = generic_matcher(template_list, specific_data) - return "".join(new_template_list) - -def service_wordpress(template_list, template_data, kind): - if kind == "vars": - new_template_list = generic_matcher(template_list, template_data[kind]) - if kind == "play": - if template_data[kind]["OS"] == "debian": - specific_data = {"OS": "apt", "OS_PACKETS": " - python3\n - python3-pip\n - docker\n - docker.io"} - elif template_data[kind]["OS"] == "centos": - specific_data = {"OS": "yum", "OS_PACKETS": " - docker"} - new_template_list = generic_matcher(template_list, specific_data) - return "".join(new_template_list) \ No newline at end of file diff --git a/api/InfrastructureTemplateController.py b/api/InfrastructureTemplateController.py index 070602457c76c64a257f45ecbf7ea7a9ac654c50..ca223f41b53de7c9ae6e80c1fe2414dbb822fff9 100644 --- a/api/InfrastructureTemplateController.py +++ b/api/InfrastructureTemplateController.py @@ -21,7 +21,7 @@ def create_infrastructure_files(intermediate_representation: dict = Body(...)): return FileResponse(compress_file_path, media_type='application/octet-stream', filename=compress_file_name) def choose_plugin(parameters): - # os.system('rm -f /opt/Output-code/*') + # os.system('rm -f /opt/output_files_generated/*') for step in parameters["steps"]: if step["programming_language"] == "ansible": input_data = step["data"] diff --git a/input_file_example/nginx/parameter.json b/input_file_example/nginx/parameter.json index 87c35d855ceb8315ed17d9f057d6fadb30d5e43b..37c1f8e33b6f0c0c726593b87dd45d4e7dea9361 100644 --- a/input_file_example/nginx/parameter.json +++ b/input_file_example/nginx/parameter.json @@ -1,5 +1,5 @@ { - "output_path": "output_file_example/nginx_openstack/", + "output_path": "output_files_generated/nginx_openstack/", "steps": [ { "programming_language": "terraform", diff --git a/input_file_example/parametri.JSON b/input_file_example/parametri.JSON deleted file mode 100644 index 0372e76a26c161e4c9aace45e3b8103eeaad8734..0000000000000000000000000000000000000000 --- a/input_file_example/parametri.JSON +++ /dev/null @@ -1 +0,0 @@ -{"provider": "aws", "network":{"subname": "Danilo", "vpcname": "Molteni"}, "vm":{"os": "ubuntu"}} \ No newline at end of file diff --git a/input_file_example/parametri.txt b/input_file_example/parametri.txt deleted file mode 100644 index 9837d5ded6f3e48ba34fd3534dc597a2bdc87587..0000000000000000000000000000000000000000 --- a/input_file_example/parametri.txt +++ /dev/null @@ -1 +0,0 @@ -{"provider": "aws", "anagrafica":{"nome": "Danilo", "cognome": "Molteni"}, "vm":{"os": "ubuntu"}} \ No newline at end of file diff --git a/input_file_example/parametriaz.JSON b/input_file_example/parametriaz.JSON deleted file mode 100644 index fba59e43c7d26d8665edbef4eae19a3b72b4cbcb..0000000000000000000000000000000000000000 --- a/input_file_example/parametriaz.JSON +++ /dev/null @@ -1 +0,0 @@ -{"provider": "azurerm", "network":{"subname": "Danilo", "vpcname": "Molteni"}, "vm":{"source": "hashicorp/azurerm", "version": "~>2.0"}} \ No newline at end of file diff --git a/input_file_example/parametriaz.txt b/input_file_example/parametriaz.txt deleted file mode 100644 index 0e243c177e1c917ed0619b55fe15db76862c96ea..0000000000000000000000000000000000000000 --- a/input_file_example/parametriaz.txt +++ /dev/null @@ -1 +0,0 @@ -{"provider": "azurerm", "anagrafica":{"nome": "Danilo", "cognome": "Molteni"}, "vm":{"source": "hashicorp/azurerm", "version": "~>2.0"}} \ No newline at end of file diff --git a/input_file_example/parametrig.JSON b/input_file_example/parametrig.JSON deleted file mode 100644 index 0f7d559592cbc7ec9b659b139f3d161c25a93773..0000000000000000000000000000000000000000 --- a/input_file_example/parametrig.JSON +++ /dev/null @@ -1 +0,0 @@ -{"provider": "gcp", "network":{"subname": "Danilo", "vpcname": "Molteni"}, "vm":{"name": "flask-vm-$8"}} \ No newline at end of file diff --git a/input_file_example/parametrig.txt b/input_file_example/parametrig.txt deleted file mode 100644 index 7075dbde3d25cc5903f78f622ba0e4a075d41298..0000000000000000000000000000000000000000 --- a/input_file_example/parametrig.txt +++ /dev/null @@ -1 +0,0 @@ -{"provider": "gcp", "anagrafica":{"nome": "Danilo", "cognome": "Molteni"}, "vm":{"name": "flask-vm-$8"}} \ No newline at end of file diff --git a/input_file_example/properties.JSON b/input_file_example/properties.JSON deleted file mode 100644 index 7a352877ae679cde20d01fd1711dce42ca0eb2e5..0000000000000000000000000000000000000000 --- a/input_file_example/properties.JSON +++ /dev/null @@ -1,30 +0,0 @@ -{ - "provider": "aws", - "network": [ - { - "id": 1, - "subname": "Danilo", - "vpcname": "Molteni" - } - ], - "vm": [ - { - "id": 1, - "ram": 128, - "cpu": 32 - }, - { - "id": 2, - "ram": 256, - "cpu": 64 - } - ], - "db": [ - { - "id": 1, - "engine": "postgres", - "username": "danilo", - "storage": 1 - } - ] -} \ No newline at end of file diff --git a/input_file_example/properties.yaml b/input_file_example/properties.yaml deleted file mode 100644 index 0e87c8447758da6d5c75e77a2cef9d1f5f27471e..0000000000000000000000000000000000000000 --- a/input_file_example/properties.yaml +++ /dev/null @@ -1,18 +0,0 @@ ---- -provider: aws -network: - - id: 1 - subname: Danilo - vpcname: Molteni -vm: - - id: 1 - ram : 128 - cpu : 32 - - id: 2 - ram : 256 - cpu : 64 -db: - - id: 1 - engine: postgres - username: danilo - storage: 1 \ No newline at end of file diff --git a/input_file_example/propertiesaz.yaml b/input_file_example/propertiesaz.yaml deleted file mode 100644 index 04c6f604b7da49c31346989fc3c9996aed90b297..0000000000000000000000000000000000000000 --- a/input_file_example/propertiesaz.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -provider: azurerm -network: - - id: 1 - name: Danilo - subnet_names: [Molteni] -vm: - - id: 1 - source: hashicorp/azurerm - version: "~>2.0" -db: - - id: 1 - name: Danilo - group_name: Molteni - server_name: DaniloMolteni - email: molteni@hpe.com diff --git a/input_file_example/propertiesg.yaml b/input_file_example/propertiesg.yaml deleted file mode 100644 index 60a7582df2d94006307f9776c6750a80d7e6c417..0000000000000000000000000000000000000000 --- a/input_file_example/propertiesg.yaml +++ /dev/null @@ -1,13 +0,0 @@ ---- -provider: gcp -network: - - id: 1 - subname: Danilo - vpcname: Molteni -vm: - - id: 1 - name: flask-vm-$8 -db: - - id: 1 - name: Danilo - instance_name: Molteni diff --git a/input_file_example/toscainput.yaml b/input_file_example/toscainput.yaml deleted file mode 100644 index 3e4615f26dafe4ab77167bf08494009ead00ee0d..0000000000000000000000000000000000000000 --- a/input_file_example/toscainput.yaml +++ /dev/null @@ -1,10 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0 - -description: Template for deploying a single server with predefined properties. - -provider: aws -network: - subname: Danilo - vpcname: Molteni -vm: - os: ubuntu \ No newline at end of file diff --git a/input_file_example/wordpress/parameters.json b/input_file_example/wordpress/parameters.json index 93f3c901daed2e55444c914de606332c69c6a32f..45a7d27e85e55d73610a33eaa95dae937daccc45 100644 --- a/input_file_example/wordpress/parameters.json +++ b/input_file_example/wordpress/parameters.json @@ -1,91 +1,77 @@ { - "steps": [ - { - "programming_language": "terraform", - "output_path": "Output-code/", - "data": { - "provider": "aws", - "network": [ - { - "id": 1, - "subnetname": "piacere_subnet", - "subnet_cidrblock": "10.0.1.0/24", - "vpcname": "piacere_vpc", - "vpc_cidr": "10.0.0.0/16" - } - ], - "vm": [ - { - "id": 1, - "os": "ubuntu", - "ram": 1, - "cpu": 1, - "name": "firstvm" - }, - { - "id": 2, - "os": "ubuntu", - "ram": 1, - "cpu": 1, - "name": "secondvm" - } - ], - "db": [ - { - "id": 1, - "name": "Danilo", - "group_name": "Molteni", - "server_name": "DaniloMolteni", - "email": "molteni@hpe.com" - } - ] - } - }, - { - "programming_language": "ansible", - "type": "database", - "output_path": "Output-code/", - "info": { - "name": "mysql", - "template_path": "Databases-templates/" - }, - "data": { - "vars": { - "DB_USER": "app1user", - "DB_PASSWORD": "app1user", - "DB_NAME": "app1" - }, - "play": { - "OS": "debian", - "HOST": 1, - "ADMIN_USER": "A", - "ADMIN_PASSWORD": "A" - } - } - }, - { - "programming_language": "ansible", - "type": "docker-service", - "output_path": "Output-code/", - "info": { - "name": "wordpress", - "template_path": "Docker-services-templates/" - }, - "data": { - "vars": { - "WORDPRESS_DB_HOST": "10.10.10.10", - "WORDPRESS_DB_USER": "app1user", - "WORDPRESS_DB_PASSWORD": "app1user", - "WORDPRESS_DB_NAME": "app1", - "WORDPRESS_TABLE_PREFIX": "wp" - }, - "play": { - "OS": "debian", - "HOST": 2, - "ADMIN_USER": "B", - "ADMIN_PASSWORD": "B" - } - } + "output_path": "output_files_generated/wordpress_azure/", + "steps": [ + { + "programming_language": "terraform", + "data": { + "provider": "azure", + "resource_group": [ + { + "name": "wordpress-rg", + "location": "eastus" + } + ], + "vms": [ + { + "resource_group_name": "wordpress-example", + "name": "wordpress-vm", + "size": "Standard_B1s", + "admin_username": "adminuser", + "admin_password": "P@$$w0rd1234!", + "ssh_user": "adminuser", + "ssh_key_file": "/ssh_keys/wordpress_rsa.pub", + "image_offer": "UbuntuServer", + "image_sku": "18.04-LTS", + "network_name": "wordpress_net" + }, + { + "resource_group_name": "wordpress-example", + "name": "myql-vm", + "size": "Standard_B1s", + "admin_username": "adminuser", + "admin_password": "P@$$w0rd1234!", + "ssh_user": "adminuser", + "ssh_key_file": "/ssh_keys/wordpress_rsa.pub", + "image_offer": "UbuntuServer", + "image_sku": "18.04-LTS", + "network_name": "mysql_net" + } + ], + "net": [ + { + "resource_group_name": "wordpress-example", + "name": "wordpress_net" + }, + { + "resource_group_name": "mysql-example", + "name": "mysql_net" + } + ] + } + }, + { + "programming_language": "ansible", + "data": { + "operating_system": "ubuntu", + "mysql": { + "db_user": "app1user", + "db_password": "app1user", + "db_name": "app1" } - ] + } + }, + { + "programming_language": "ansible", + "data": { + "operating_system": "ubuntu", + "wordpress": { + "wordpress_db_host": "10.10.10.10", + "wordpress_db_user": "app1user", + "wordpress_db_password": "app1user", + "wordpress_db_name": "app1", + "wordpress_table_prefix": "wp" + } + } + } + ] } \ No newline at end of file diff --git a/main.py b/main.py index 960b240d75c7416f94feaf85efda25b249f1691c..098ca349e14c9cff3ebf1b753e754edd204f533e 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,6 @@ -import json import logging from fastapi import FastAPI - import api.InfrastructureTemplateController -from api import InfrastructureTemplateController fast_api = FastAPI() @@ -11,6 +8,4 @@ fast_api.include_router(api.InfrastructureTemplateController.api_router) logging.getLogger().setLevel(logging.INFO) if __name__ == '__main__': - parameters_file = open("input_file_example/nginx/parameter.json") - parameters_file = json.load(parameters_file) - InfrastructureTemplateController.choose_plugin(parameters_file) + logging.info("Starting ICG application") diff --git a/output_file_example/nginx_openstack/terraform/main.tf b/output_file_example/nginx_openstack/terraform/main.tf index a91ec88b9008734246ae07cb869fd23ad8b910f4..341a4e497ef31443ff7487149c919f1593129e5e 100644 --- a/output_file_example/nginx_openstack/terraform/main.tf +++ b/output_file_example/nginx_openstack/terraform/main.tf @@ -10,76 +10,48 @@ required_version = ">= 0.14.0" # Configure the OpenStack Provider provider "openstack" { - user_name = "admin" - tenant_name = "test" - password = "wRpuXgVqBzQqGwx8Bu0sylEeb8FgjSYG" - auth_url = "https://127.0.0.1:5000/v3" + user_name = "{{ user }}" #admin + tenant_name = "{{ tenant }}" #test + password = "{{ password }}" #test + auth_url = "{{ url }}" #https://127.0.0.1:5000/v3 insecure = true } -# Create virtual machine -resource "openstack_compute_instance_v2" "nginx-host" { - name = "nginx-host" - image_name = "ubuntu-20.04.3" - flavor_name = "small" - key_pair = openstack_compute_keypair_v2.nginx-host_ssh_key.name - network { - port = openstack_networking_port_v2.ostack2.id - } -} -# Create ssh keys -resource "openstack_compute_keypair_v2" "nginx-host_ssh_key" { - name = "ubuntu" - public_key = "/home/user1/.ssh/openstack.key" +resource "openstack_compute_keypair_v2" "user_key" { + name = "user1" + public_key = "{{ ssh_key }}" #ssh-rsa xxxx } -# Create floating ip -resource "openstack_networking_floatingip_v2" "nginx-host_floating_ip" { - pool = "external" - # fixed_ip = "16.0.0.1" -} - -# Attach floating ip to instance -resource "openstack_compute_floatingip_associate_v2" "nginx-host_floating_ip_association" { - floating_ip = openstack_networking_floatingip_v2.nginx-host_floating_ip.address - instance_id = openstack_compute_instance_v2.nginx-host.id +# Router creation. UUID external gateway +resource "openstack_networking_router_v2" "generic" { + name = "router-generic" + external_network_id = "${openstack_networking_network_v2.external.id}" #External network id } -## Network - -# Create Network -resource "openstack_networking_network_v2" "ostack2" { +# Network creation +resource "openstack_networking_network_v2" "generic" { name = "ostack2" } -# Create Subnet -resource "openstack_networking_subnet_v2" "ostack2_subnet" { - name = "ostack2_subnet" - network_id = openstack_networking_network_v2.ostack2.id +#### HTTP SUBNET #### + +# Subnet http configuration +resource "openstack_networking_subnet_v2" "nginx" { + name = "subnet-nginx" + network_id = openstack_networking_network_v2.generic.id cidr = "16.0.0.0/24" dns_nameservers = ["8.8.8.8", "8.8.8.4"] } -# Attach networking port -resource "openstack_networking_port_v2" "ostack2" { - name = "ostack2" - network_id = openstack_networking_network_v2.ostack2.id - admin_state_up = true - security_group_ids = [ - - openstack_compute_secgroup_v2.rule_1_secgroup.id, - - openstack_compute_secgroup_v2.rule_2_secgroup.id, - - ] - fixed_ip { - subnet_id = openstack_networking_subnet_v2.ostack2_subnet.id - } +# Router interface configuration +resource "openstack_networking_router_interface_v2" "nginx" { + router_id = openstack_networking_router_v2.generic.id + subnet_id = openstack_networking_subnet_v2.nginx.id } -resource "openstack_compute_secgroup_v2" "rule_1_secgroup" { - name = "rule_1" - description = "Security group rule for port 80-80" +resource "openstack_compute_secgroup_v2" "http" { + name = "http" + description = "Open input http port" rule { from_port = 80 to_port = 80 @@ -88,9 +60,9 @@ resource "openstack_compute_secgroup_v2" "rule_1_secgroup" { } } -resource "openstack_compute_secgroup_v2" "rule_2_secgroup" { - name = "rule_2" - description = "Security group rule for port 22-22" +resource "openstack_compute_secgroup_v2" "ssh" { + name = "ssh" + description = "Open input ssh port" rule { from_port = 22 to_port = 22 @@ -99,3 +71,42 @@ resource "openstack_compute_secgroup_v2" "rule_2_secgroup" { } } +# +# Create instance +# +resource "openstack_compute_instance_v2" "nginx" { + name = "nginx-host" + image_name = "cirros" + flavor_name = "m1.tiny" + key_pair = openstack_compute_keypair_v2.user_key.name + network { + port = openstack_networking_port_v2.nginx.id + } +} + +# Create network port +resource "openstack_networking_port_v2" "nginx" { + name = "nginx" + network_id = openstack_networking_network_v2.generic.id + admin_state_up = true + security_group_ids = [ + "${openstack_compute_flavor_v2.default.id}" #default flavour id + ] + fixed_ip { + subnet_id = openstack_networking_subnet_v2.nginx.id + } +} + +# Create floating ip +resource "openstack_networking_floatingip_v2" "nginx" { +# pool = "ostack2" +# port_id = openstack_networking_port_v2.nginx.id + pool = "external" +# fixed_ip = "16.0.0.1" +} + +# Attach floating ip to instance +resource "openstack_compute_floatingip_associate_v2" "nginx" { + floating_ip = openstack_networking_floatingip_v2.nginx.address + instance_id = openstack_compute_instance_v2.nginx.id +} diff --git a/output_file_example/wordpress_azure/terraform/main.tf b/output_file_example/wordpress_azure/terraform/main.tf index da9a04888253cb4ce3420adf661ba7f7d225b38d..004ee38c4b917abf3c392148c5fc1c66716f0935 100644 --- a/output_file_example/wordpress_azure/terraform/main.tf +++ b/output_file_example/wordpress_azure/terraform/main.tf @@ -13,154 +13,37 @@ provider "azurerm" { features {} } -resource "azurerm_resource_group" "rg" { - name = "TerraformTesting" - location = "eastus" ## REQUIRED -} - ## VIRTUAL NETWORK -resource "azurerm_virtual_network" "vnet" { - name = "vNet" +resource "azurerm_virtual_network" "wordpress_net_vnetwork" { + name = "wordpress_net" address_space = ["10.0.0.0/16"] - location = azurerm_resource_group.rg.location - resource_group_name = azurerm_resource_group.rg.name + location = azurerm_resource_group.wordpress-example.location + resource_group_name = azurerm_resource_group.wordpress-example.name } -resource "azurerm_subnet" "subnet" { +## SUBNET +resource "azurerm_subnet" "wordpress_net_subnet" { name = "internal" - resource_group_name = azurerm_resource_group.rg.name - virtual_network_name = azurerm_virtual_network.vnet.name + resource_group_name = azurerm_resource_group.wordpress-example.name + virtual_network_name = azurerm_virtual_network.wordpress_net_vnetwork.name address_prefixes = ["10.0.2.0/24"] } -## WORDPRESS PUBLIC IP -resource "azurerm_public_ip" "wordpress_public_ip" { - name = "wordpress_public_ip" - location = azurerm_resource_group.rg.location - resource_group_name = azurerm_resource_group.rg.name - allocation_method = "Dynamic" ##REQUIRED?? - sku = "Basic" -} - -## WORDPRESS NETWORK INTERFACE -resource "azurerm_network_interface" "wordpress_nic" { - name = "wordpress_nic" - location = azurerm_resource_group.rg.location - resource_group_name = azurerm_resource_group.rg.name - - ip_configuration { - name = "ipconfig1" - subnet_id = azurerm_subnet.subnet.id - private_ip_address_allocation = "Dynamic" - public_ip_address_id = azurerm_public_ip.wordpress_public_ip.id - } -} - -## WORDPRESS VM -resource "azurerm_linux_virtual_machine" "wordpress" { ## REQUIRED - resource_group_name = azurerm_resource_group.rg.name - ## instance details - name = "wordpress-machine" - location = azurerm_resource_group.rg.location - size = "Standard_B1s" ## REQUIRED - ## administrator account - admin_username = "adminuser" - admin_password = "P@$$w0rd1234!" ##For Bastion Connection - disable_password_authentication = false - #availability_set_id = azurerm_availability_set.DemoAset.id - network_interface_ids = [ - azurerm_network_interface.wordpress_nic.id - ] - - os_disk { - caching = "None" - storage_account_type = "Standard_LRS" ## REQUIRED - } - - admin_ssh_key { - username = "adminuser" - public_key = file("${path.module}/ssh_keys/wordpress_rsa.pub") - } - - source_image_reference { - publisher = "Canonical" - offer = "UbuntuServer" - sku = "18.04-LTS" - version = "latest" - } -} - -## MYSQL SAAS -resource "azurerm_mysql_server" "mysql" { - name = "mysql-machine" - location = azurerm_resource_group.rg.location - resource_group_name = azurerm_resource_group.rg.name - - administrator_login = "app1user" - administrator_login_password = "app1" - - sku_name = "B_Gen5_2" - storage_mb = 10 - version = "5.7" - - auto_grow_enabled = true - backup_retention_days = 7 - geo_redundant_backup_enabled = false - infrastructure_encryption_enabled = false - public_network_access_enabled = true - ssl_enforcement_enabled = true - ssl_minimal_tls_version_enforced = "TLS1_2" -} -## EXECUTION MANAGER PUBLIC IP -resource "azurerm_public_ip" "em_public_ip" { - name = "em_public_ip" - location = azurerm_resource_group.rg.location - resource_group_name = azurerm_resource_group.rg.name - allocation_method = "Dynamic" ##REQUIRED?? - sku = "Basic" +## VIRTUAL NETWORK +resource "azurerm_virtual_network" "mysql_net_vnetwork" { + name = "mysql_net" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.mysql-example.location + resource_group_name = azurerm_resource_group.mysql-example.name } -## EXECUTION MANAGER NETWORK INTERFACE -resource "azurerm_network_interface" "em_nic" { - name = "em_nic" - location = azurerm_resource_group.rg.location - resource_group_name = azurerm_resource_group.rg.name - - ip_configuration { - name = "ipconfig1" - subnet_id = azurerm_subnet.subnet.id - private_ip_address_allocation = "Dynamic" - public_ip_address_id = azurerm_public_ip.em_public_ip.id - } +## SUBNET +resource "azurerm_subnet" "mysql_net_subnet" { + name = "internal" + resource_group_name = azurerm_resource_group.mysql-example.name + virtual_network_name = azurerm_virtual_network.mysql_net_vnetwork.name + address_prefixes = ["10.0.2.0/24"] } -## EXECUTION MANAGER -resource "azurerm_linux_virtual_machine" "execution_manager" { ## REQUIRED - resource_group_name = azurerm_resource_group.rg.name - ## instance details - name = "execution-manager-machine" - location = azurerm_resource_group.rg.location - size = "Standard_B1s" ## REQUIRED - ## administrator account - admin_username = "adminuser" - admin_ssh_key { - username = "adminuser" - public_key = file("${path.module}/ssh_keys/wordpress_rsa.pub") - } - network_interface_ids = [ - azurerm_network_interface.em_nic.id - ] - os_disk { - caching = "None" - storage_account_type = "Standard_LRS" - } - - source_image_reference { - publisher = "OpenLogic" - offer = "CentOS" - sku = "7.5" - version = "latest" - } -} \ No newline at end of file diff --git a/output_files_generated/nginx_openstack/ansible/nginx.play b/output_files_generated/nginx_openstack/ansible/nginx.play new file mode 100644 index 0000000000000000000000000000000000000000..c8790e19071787ba9fef7d270947c8ec6f09048d --- /dev/null +++ b/output_files_generated/nginx_openstack/ansible/nginx.play @@ -0,0 +1,45 @@ +--- +- hosts: 16.0.0.1 + gather_facts: no + become: yes + vars: + ansible_ssh_private_key_file: "/home/user1/.ssh/openstack.key" + ansible_ssh_user: "ubuntu" + tasks: + - name: Update repositories + apt: + update_cache: yes + + - name: Install nginx + package: + name: nginx + + - name: Start nginx + service: + name: nginx + enabled: yes + state: started + + - name: Set attributes + set_stats: + data: + site_config_dir: /etc/nginx/conf.d + + - name: Install sample site + copy: + dest: "" + content: | + <!doctype html> + <html lang="en"> + <head> + <title>Hello World!</title> + </head> + <body> + <h1>Sample web page</h1> + <p>With little content ;)</p> + </body> + </html> + with_items: + - /var/www/html/index.html + - /usr/share/nginx/html/index.html + diff --git a/output_files_generated/nginx_openstack/terraform/main.tf b/output_files_generated/nginx_openstack/terraform/main.tf new file mode 100644 index 0000000000000000000000000000000000000000..a91ec88b9008734246ae07cb869fd23ad8b910f4 --- /dev/null +++ b/output_files_generated/nginx_openstack/terraform/main.tf @@ -0,0 +1,101 @@ +terraform { +required_version = ">= 0.14.0" + required_providers { + openstack = { + source = "terraform-provider-openstack/openstack" + version = "~> 1.35.0" + } + } +} + +# Configure the OpenStack Provider +provider "openstack" { + user_name = "admin" + tenant_name = "test" + password = "wRpuXgVqBzQqGwx8Bu0sylEeb8FgjSYG" + auth_url = "https://127.0.0.1:5000/v3" + insecure = true +} +# Create virtual machine +resource "openstack_compute_instance_v2" "nginx-host" { + name = "nginx-host" + image_name = "ubuntu-20.04.3" + flavor_name = "small" + key_pair = openstack_compute_keypair_v2.nginx-host_ssh_key.name + network { + port = openstack_networking_port_v2.ostack2.id + } +} + +# Create ssh keys +resource "openstack_compute_keypair_v2" "nginx-host_ssh_key" { + name = "ubuntu" + public_key = "/home/user1/.ssh/openstack.key" +} + +# Create floating ip +resource "openstack_networking_floatingip_v2" "nginx-host_floating_ip" { + pool = "external" + # fixed_ip = "16.0.0.1" +} + +# Attach floating ip to instance +resource "openstack_compute_floatingip_associate_v2" "nginx-host_floating_ip_association" { + floating_ip = openstack_networking_floatingip_v2.nginx-host_floating_ip.address + instance_id = openstack_compute_instance_v2.nginx-host.id +} + +## Network + +# Create Network +resource "openstack_networking_network_v2" "ostack2" { + name = "ostack2" +} + +# Create Subnet +resource "openstack_networking_subnet_v2" "ostack2_subnet" { + name = "ostack2_subnet" + network_id = openstack_networking_network_v2.ostack2.id + cidr = "16.0.0.0/24" + dns_nameservers = ["8.8.8.8", "8.8.8.4"] +} + +# Attach networking port +resource "openstack_networking_port_v2" "ostack2" { + name = "ostack2" + network_id = openstack_networking_network_v2.ostack2.id + admin_state_up = true + security_group_ids = [ + + openstack_compute_secgroup_v2.rule_1_secgroup.id, + + openstack_compute_secgroup_v2.rule_2_secgroup.id, + + ] + fixed_ip { + subnet_id = openstack_networking_subnet_v2.ostack2_subnet.id + } +} + +resource "openstack_compute_secgroup_v2" "rule_1_secgroup" { + name = "rule_1" + description = "Security group rule for port 80-80" + rule { + from_port = 80 + to_port = 80 + ip_protocol = "tcp" + cidr = "0.0.0.0/0" + } +} + +resource "openstack_compute_secgroup_v2" "rule_2_secgroup" { + name = "rule_2" + description = "Security group rule for port 22-22" + rule { + from_port = 22 + to_port = 22 + ip_protocol = "tcp" + cidr = "0.0.0.0/0" + } +} + diff --git a/output_files_generated/wordpress_azure/ansible/mysql.play b/output_files_generated/wordpress_azure/ansible/mysql.play new file mode 100644 index 0000000000000000000000000000000000000000..d273e15412006bc7c31625323df0ef9283850747 --- /dev/null +++ b/output_files_generated/wordpress_azure/ansible/mysql.play @@ -0,0 +1,97 @@ +--- +- hosts: DB + become: yes + + pre_tasks: + - name: Install MySQL + apt: name= update_cache=yes cache_valid_time=3600 state=present + with_items: + - mysql-server + - mysql-client + - python-setuptools + - python-mysqldb + - libmysqlclient-dev + - python3-pip + + - name: Remove a symbolic link + ansible.builtin.file: + path: /usr/bin/python + state: absent + + - name: Create a symbolic link + ansible.builtin.file: + src: /usr/bin/python3 + dest: /usr/bin/python + state: link + register: result + retries: 3 + delay: 5 + until: result is not failed + + - name: Create a symbolic link + ansible.builtin.file: + src: /usr/bin/pip3 + dest: /usr/bin/pip + state: link + register: result + retries: 3 + delay: 5 + until: result is not failed + + - name: Install Python packages + pip: "name= state=present" + with_items: + - PyMySQL + + - name: edit firewall + service: + name: ufw + state: stopped + enabled: false + + tasks: + - name: Start the MySQL service + service: + name: mysql + state: started + enabled: true + + - name: Creation mysql file configuration + file: + path: "/root/.my.cnf" + state: touch + + - name: Editing configuration file + replace: + path: /etc/mysql/mysql.conf.d/mysqld.cnf + regexp: '(.*bind-addres.*)' + replace: '#\1' + + - name: Restart MySQL + service: name=mysql state=restarted + + - name: Ensure MySQL started + service: + name: mysql + state: started + + - name: update mysql password for application account + mysql_user: + login_unix_socket: /var/run/mysqld/mysqld.sock + name: "app1user" + host: "%" + password: "app1user" + state: present + login_user: root + login_password: test + check_implicit_admin: yes + priv: "*.*:ALL,GRANT" + + - name: Add the application database + mysql_db: + name: "app1" + state: present + login_unix_socket: /var/run/mysqld/mysqld.sock + + - name: Restart MySQL + service: name=mysql state=restarted diff --git a/output_files_generated/wordpress_azure/ansible/wordpress.play b/output_files_generated/wordpress_azure/ansible/wordpress.play new file mode 100644 index 0000000000000000000000000000000000000000..f8e98e07b07851348ed95af3fe2c10180279e724 --- /dev/null +++ b/output_files_generated/wordpress_azure/ansible/wordpress.play @@ -0,0 +1,69 @@ +--- +- hosts: APP1 + become: yes + + pre_tasks: + - name: "Install packages" + apt: "name= state=present" + with_items: + - python3 + - python3-pip + - docker + - docker.io + + - name: Remove a symbolic link + ansible.builtin.file: + path: /usr/bin/python + state: absent + + - name: Create a symbolic link + ansible.builtin.file: + src: /usr/bin/python3 + dest: /usr/bin/python + state: link + register: result + retries: 3 + delay: 5 + until: result is not failed + + - name: Create a symbolic link + ansible.builtin.file: + src: /usr/bin/pip3 + dest: /usr/bin/pip + state: link + register: result + retries: 3 + delay: 5 + until: result is not failed + + - name: "Install Python packages" + pip: "name= state=present" + with_items: + - docker + + - name: edit firewall + service: + name: ufw + state: stopped + enabled: false + + tasks: + - name: Create a volume + community.docker.docker_volume: + name: mydata + + - name: Start a WP container + community.docker.docker_container: + name: wordpress + image: wordpress:5.8.0 + state: started + env: + WORDPRESS_DB_HOST: "10.10.10.10" + WORDPRESS_DB_USER: "app1user" + WORDPRESS_DB_PASSWORD: "app1user" + WORDPRESS_DB_NAME: "app1" + WORDPRESS_TABLE_PREFIX: "wp" + ports: + - "8080:80" + volumes: + - mydata diff --git a/output_files_generated/wordpress_azure/terraform/main.tf b/output_files_generated/wordpress_azure/terraform/main.tf new file mode 100644 index 0000000000000000000000000000000000000000..851c1443bb1657d2954fc9639196530e521ed359 --- /dev/null +++ b/output_files_generated/wordpress_azure/terraform/main.tf @@ -0,0 +1,47 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~> 2.65" + } + } + + required_version = ">= 0.14.9" +} + +provider "azurerm" { + features {} +} + +## VIRTUAL NETWORK +resource "azurerm_virtual_network" "wordpress_net_vnetwork" { + name = "wordpress_net" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.wordpress-example.location + resource_group_name = azurerm_resource_group.wordpress-example.name +} + +## SUBNET +resource "azurerm_subnet" "wordpress_net_subnet" { + name = "internal" + resource_group_name = azurerm_resource_group.wordpress-example.name + virtual_network_name = azurerm_virtual_network.wordpress_net_vnetwork.name + address_prefixes = ["10.0.2.0/24"] +} + +## VIRTUAL NETWORK +resource "azurerm_virtual_network" "mysql_net_vnetwork" { + name = "mysql_net" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.mysql-example.location + resource_group_name = azurerm_resource_group.mysql-example.name +} + +## SUBNET +resource "azurerm_subnet" "mysql_net_subnet" { + name = "internal" + resource_group_name = azurerm_resource_group.mysql-example.name + virtual_network_name = azurerm_virtual_network.mysql_net_vnetwork.name + address_prefixes = ["10.0.2.0/24"] +} + diff --git a/plugin/TemplateUtils.py b/plugin/TemplateUtils.py index c90ff5d0585e75e07aae53b2c4deb0723535510b..1bda9f2b7d8252b5a4800e0c2bcbcd35a44ec98d 100644 --- a/plugin/TemplateUtils.py +++ b/plugin/TemplateUtils.py @@ -1,5 +1,7 @@ import configparser import logging +import os + import jinja2 from jinja2 import Template @@ -35,6 +37,7 @@ def read_template(template_path): def write_template(template, output_path_file): + os.makedirs(os.path.dirname(output_path_file), exist_ok=True) file = open(output_path_file, "w+") file.write(template) logging.info("Writing file at: '%s'", output_path_file) diff --git a/template-location.properties b/template-location.properties index af672eb0b79fb9c93a33b655dbeba5cfe64927d3..a1b9ac4601acd09a3c1b1e7ad121c9dcff34cd90 100644 --- a/template-location.properties +++ b/template-location.properties @@ -4,7 +4,19 @@ vm = templates/terraform/open_stack/virtual_machine.tpl net = templates/terraform/open_stack/network.tpl sg = templates/terraform/open_stack/port_rule.tpl +[terraform.azure] +init = templates/terraform/azure/init.tpl +vm = templates/terraform/azure/virtual_machine.tpl +net = templates/terraform/azure/network.tpl +rg = templates/terraform/azure/resource_group.tpl + [ansible.ubuntu] nginx = templates/ansible/ubuntu/nginx.tpl -mysql = templates/ansible/ubuntu/mysql-play.tpl -wordpress = templates/ansible/ubuntu/wordpress-play.tpl \ No newline at end of file +mysql = templates/ansible/ubuntu/mysql.tpl +wordpress = templates/ansible/ubuntu/wordpress.tpl +postgres = templates/ansible/ubuntu/postgres.tpl + +[ansible.centos] +mysql = templates/ansible/centos/mysql.tpl +postgres = templates/ansible/centos/postgres.tpl +wordpress = templates/ansible/centos/wordpress.tpl \ No newline at end of file diff --git a/Output-code/mysql-play.yml b/templates/ansible/centos/mysql.tpl similarity index 89% rename from Output-code/mysql-play.yml rename to templates/ansible/centos/mysql.tpl index 8025582e41ecc1a981e770280d832cc8f5cebaf1..fff114876355f16e7a6c9a9d9cfda408c1d61957 100644 --- a/Output-code/mysql-play.yml +++ b/templates/ansible/centos/mysql.tpl @@ -1,12 +1,10 @@ --- - hosts: DB become: yes - vars_files: - - mysql-vars.yml pre_tasks: - name: Install MySQL - apt: name={{ item }} update_cache=yes cache_valid_time=3600 state=present + yum: name={{ item }} update_cache=yes cache_valid_time=3600 state=present with_items: - mysql-server - mysql-client @@ -47,7 +45,7 @@ - name: edit firewall service: - name: ufw + name: firewalld state: stopped enabled: false @@ -79,7 +77,6 @@ - name: update mysql password for application account mysql_user: - login_unix_socket: /var/run/mysqld/mysqld.sock name: "{{ db_user }}" host: "%" password: "{{ db_password }}" @@ -93,7 +90,6 @@ mysql_db: name: "{{ db_name }}" state: present - login_unix_socket: /var/run/mysqld/mysqld.sock - name: Restart MySQL service: name=mysql state=restarted diff --git a/Output-code/postgres-play.yml b/templates/ansible/centos/postgres.tpl similarity index 89% rename from Output-code/postgres-play.yml rename to templates/ansible/centos/postgres.tpl index d9249911a0802dc51ad6a3875f8df86ab9dfa4ed..b4fa1e8da06274aa4f206034c783654cf9adc1a7 100644 --- a/Output-code/postgres-play.yml +++ b/templates/ansible/centos/postgres.tpl @@ -2,14 +2,14 @@ - hosts: DB become: yes - vars_files: - - postgres-vars.yml - pre_tasks: - name: "Install packages" - apt: "name={{ item }} state=present" + yum: "name={{ item }} state=present" with_items: - - postgresql-10 + - postgresql10 + - postgresql10-server + - postgresql10-contrib + - postgresql10-libs - python3 - python3-pip diff --git a/Output-code/wordpress-play.yml b/templates/ansible/centos/wordpress.tpl similarity index 77% rename from Output-code/wordpress-play.yml rename to templates/ansible/centos/wordpress.tpl index 695d1638a8c6966186fe4e1e2301df2960392e3f..fecc1d516a22d4ddd4dcc014410d8c7a9674f4e0 100644 --- a/Output-code/wordpress-play.yml +++ b/templates/ansible/centos/wordpress.tpl @@ -2,17 +2,11 @@ - hosts: APP1 become: yes - vars_files: - - wordpress-vars.yml - pre_tasks: - name: "Install packages" apt: "name={{ item }} state=present" with_items: - - python3 - - python3-pip - docker - - docker.io - name: Remove a symbolic link ansible.builtin.file: @@ -61,11 +55,11 @@ image: wordpress:5.8.0 state: started env: - WORDPRESS_DB_HOST: "{{WORDPRESS_DB_HOST}}" - WORDPRESS_DB_USER: "{{WORDPRESS_DB_USER}}" - WORDPRESS_DB_PASSWORD: "{{WORDPRESS_DB_PASSWORD}}" - WORDPRESS_DB_NAME: "{{WORDPRESS_DB_NAME}}" - WORDPRESS_TABLE_PREFIX: "{{WORDPRESS_TABLE_PREFIX}}" + WORDPRESS_DB_HOST: "{{ wordpress_db_host }}" + WORDPRESS_DB_USER: "{{ wordpress_db_user }}" + WORDPRESS_DB_PASSWORD: "{{ wordpress_db_password }}" + WORDPRESS_DB_NAME: "{{ wordpress_db_name }}" + WORDPRESS_TABLE_PREFIX: "{{ wordpress_table_prefix }}" ports: - "8080:80" volumes: diff --git a/templates/ansible/ubuntu/mysql.tpl b/templates/ansible/ubuntu/mysql.tpl index afb424210f02ec1815aaa0b35d192659edc40080..38a8e8328dd02fa01e9c8baf86844b7c5869729b 100644 --- a/templates/ansible/ubuntu/mysql.tpl +++ b/templates/ansible/ubuntu/mysql.tpl @@ -4,9 +4,14 @@ pre_tasks: - name: Install MySQL - ###OS###: name={{ item }} update_cache=yes cache_valid_time=3600 state=present + apt: name={{ item }} update_cache=yes cache_valid_time=3600 state=present with_items: -###OS_PACKETS### + - mysql-server + - mysql-client + - python-setuptools + - python-mysqldb + - libmysqlclient-dev + - python3-pip - name: Remove a symbolic link ansible.builtin.file: diff --git a/templates/ansible/ubuntu/postgres.tpl b/templates/ansible/ubuntu/postgres.tpl index 129ee69bb0d3a06160a471878a695deb99117560..b8de4847ff463eba8da70d6e01173ece82b10cbd 100644 --- a/templates/ansible/ubuntu/postgres.tpl +++ b/templates/ansible/ubuntu/postgres.tpl @@ -4,9 +4,9 @@ pre_tasks: - name: "Install packages" - ###OS###: "name={{ item }} state=present" + apt: "name={{ item }} state=present" with_items: -###OS_PACKETS### + - postgresql-10 - python3 - python3-pip diff --git a/templates/ansible/ubuntu/wordpress.tpl b/templates/ansible/ubuntu/wordpress.tpl index 42d4399322c3bfa3fc93085621864c593484b413..774efd7c8a0fce99b2bdfec73dd108d19c77dc1d 100644 --- a/templates/ansible/ubuntu/wordpress.tpl +++ b/templates/ansible/ubuntu/wordpress.tpl @@ -4,9 +4,12 @@ pre_tasks: - name: "Install packages" - ###OS###: "name={{ item }} state=present" + apt: "name={{ item }} state=present" with_items: -###OS_PACKETS### + - python3 + - python3-pip + - docker + - docker.io - name: Remove a symbolic link ansible.builtin.file: diff --git a/templates/terraform/azure/init.tpl b/templates/terraform/azure/init.tpl new file mode 100644 index 0000000000000000000000000000000000000000..33d115d37cfac2beb7a902455578140ecd19af0b --- /dev/null +++ b/templates/terraform/azure/init.tpl @@ -0,0 +1,15 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~> 2.65" + } + } + + required_version = ">= 0.14.9" +} + +provider "azurerm" { + features {} +} + diff --git a/templates/terraform/azure/network.tpl b/templates/terraform/azure/network.tpl index 51acd1afc3c707d47d8348c6fabf9d01f9d950e3..b2ee4468955c79e5e5c27c8440ae86bc4cb7c14e 100644 --- a/templates/terraform/azure/network.tpl +++ b/templates/terraform/azure/network.tpl @@ -1,23 +1,15 @@ -resource "azurerm_resource_group" "example" { - name = "{{ name }}" - location = "West Europe" +## VIRTUAL NETWORK +resource "azurerm_virtual_network" "{{ name ~ "_vnetwork" }}" { + name = "{{ name }}" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.{{ resource_group_name }}.location + resource_group_name = azurerm_resource_group.{{ resource_group_name }}.name } -module "network" { - source = "Azure/network/azurerm" - resource_group_name = azurerm_resource_group.example.name - address_spaces = ["10.0.0.0/16", "10.2.0.0/16"] - subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] - subnet_names = {{ subnet_names }} - - subnet_service_endpoints = { - {{ endpoints }} - } - - tags = { - environment = "dev" - costcenter = "it" - } - - depends_on = [azurerm_resource_group.example] +## SUBNET +resource "azurerm_subnet" "{{ name ~ "_subnet" }}" { + name = "internal" + resource_group_name = azurerm_resource_group.{{ resource_group_name }}.name + virtual_network_name = azurerm_virtual_network.{{ name ~ "_vnetwork" }}.name + address_prefixes = ["10.0.2.0/24"] } \ No newline at end of file diff --git a/templates/terraform/azure/resource_group.tpl b/templates/terraform/azure/resource_group.tpl new file mode 100644 index 0000000000000000000000000000000000000000..1647b0ce60bf16874c5eafd498dae30d6173369a --- /dev/null +++ b/templates/terraform/azure/resource_group.tpl @@ -0,0 +1,6 @@ +## RESOURCE GROUP + +resource "azurerm_resource_group" "{{ name }}" { + name = "{{ name }}" + location = "{{ location }}" ## REQUIRED +} \ No newline at end of file diff --git a/templates/terraform/azure/virtual_machine.tpl b/templates/terraform/azure/virtual_machine.tpl new file mode 100644 index 0000000000000000000000000000000000000000..eac12cdb283ddcdff85069c351a0eaca47326b3c --- /dev/null +++ b/templates/terraform/azure/virtual_machine.tpl @@ -0,0 +1,55 @@ +## CREATE VM +resource "azurerm_linux_virtual_machine" "{{ name }}" { ## REQUIRED + resource_group_name = azurerm_resource_group.rg.{{ resource_group_name }} + ## instance details + name = "{{ name }}" + location = azurerm_resource_group.{{ resource_group_name }}.location + size = "{{ size }}" ## REQUIRED + ## administrator account + admin_username = "{{ admin_username }}" + admin_password = "{{ admin_password }}" ##For Bastion Connection + disable_password_authentication = false + network_interface_ids = [ + azurerm_network_interface.{{ network_name }}.id + ] + + os_disk { + caching = "None" + storage_account_type = "Standard_LRS" ## REQUIRED + } + + admin_ssh_key { + username = "{{ ssh_user }}" + public_key = file("${path.module}{{ ssh_key_file }}") + } + + source_image_reference { + publisher = "Canonical" + offer = "{{ image_offer }}" + sku = "{{ image_sku }}" + version = "latest" + } +} + +## VM NETWORK INTERFACE +resource "azurerm_network_interface" "{{ name ~ "_vnet_interface" }}" { + name = "{{ name ~ "_nic" }}" + location = azurerm_resource_group.{{ resource_group_name }}.location + resource_group_name = azurerm_resource_group.{{ resource_group_name }}.name + + ip_configuration { + name = "ipconfig1" + subnet_id = azurerm_subnet.{{ network_name ~ "_subnet" }}.id + private_ip_address_allocation = "Dynamic" + public_ip_address_id = azurerm_public_ip.wordpress_public_ip.id + } +} + +## PUBLIC IP +resource "azurerm_public_ip" "{{ name ~ "_public_ip" }}" { + name = "{{ name ~ "_public_ip" }}" + location = azurerm_resource_group.{{ resource_group_name }}.location + resource_group_name = azurerm_resource_group.{{ resource_group_name }}.name + allocation_method = "Dynamic" ##REQUIRED?? + sku = "Basic" +} \ No newline at end of file diff --git a/templates/terraform/azure/vm.tpl b/templates/terraform/azure/vm.tpl deleted file mode 100644 index 5380c5ad23cc294230e8c92821e9bf29cdf2ef87..0000000000000000000000000000000000000000 --- a/templates/terraform/azure/vm.tpl +++ /dev/null @@ -1,15 +0,0 @@ -terraform { - required_providers { - azurerm = { - source = "{{ source }}" - version = "{{ version }}" - } - } -} -provider "azurerm" { - features {} -} -resource "azurerm_resource_group" "rg" { - name = "{{ name }}" - location = "{{ location }}" -} \ No newline at end of file