Skip to content
Snippets Groups Projects
Commit a4f693bd authored by Niculut Laurentiu's avatar Niculut Laurentiu
Browse files

added icg controller code

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 291 additions and 0 deletions
resource "aws_db_instance" "{{ identifier }}" {
identifier = "{{ identifier }}"
instance_class = "{{ instance }}"
allocated_storage = {{ storage }}
engine = "{{ engine }}"
engine_version = "{{ version }}"
username = "{{ username }}"
password = {{ password }}
db_subnet_group_name = {{ subnet }}
vpc_security_group_ids = {{ security }}
parameter_group_name = {{ parameter }}
publicly_accessible = {{ accessible }}
skip_final_snapshot = {{ skip }}
}
\ No newline at end of file
resource "azurerm_sql_database" "test2" {
name = "{{ name }}"
resource_group_name = "{{ group_name}}"
location = "{{ location }}"
server_name = "{{ server_name }}"
threat_detection_policy {
state = "{{ state }}"
email_addresses = {{ email }}
retention_days = "{{ days }}"
storage_account_access_key = "{{ access_key }}"
storage_endpoint = "{{ endpoint }}"
use_server_default = "{{ default }}"
}
}
\ No newline at end of file
resource "google_sql_database" "database" {
name = "{{ name }}"
instance = {{ instance }}
}
resource "google_sql_database_instance" "instance" {
name = "{{ instance_name }}"
region = "{{ region }}"
settings {
tier = "{{ tier }}"
}
deletion_protection = "{{ deletion_protection }}"
}
\ No newline at end of file
resource "postgresql_database" {{ name }} {
name = {{ name }}
owner = {{ owner }}
template = {{ template }}
lc_collate = {{ lc_collate }}
connection_limit = {{ connection_limit }}
allow_connections = {{ allow_connections }}
}
\ No newline at end of file
---
- hosts: DB
become: yes
vars_files:
- postgres-vars.yml
pre_tasks:
- name: "Install packages"
###OS###: "name={{ item }} state=present"
with_items:
###OS_PACKETS###
- python3
- python3-pip
- name: "Install Python packages"
pip: "name={{ item }} state=present"
with_items:
- psycopg2-binary
tasks:
- name: "Start and enable services"
service: "name={{ item }} state=started enabled=yes"
with_items:
- postgresql
- name: "Create app database"
postgresql_db:
state: present
name: "{{ db_name }}"
become: yes
become_user: postgres
- name: "Create db user"
postgresql_user:
state: present
name: "{{ db_user }}"
password: "{{ db_password }}"
become: yes
become_user: postgres
- name: "Grant db user access to app db"
postgresql_privs:
type: database
database: "{{ db_name }}"
roles: "{{ db_user }}"
grant_option: no
privs: all
become: yes
become_user: postgres
- name: "Allow md5 connection for the db user"
postgresql_pg_hba:
dest: "/etc/postgresql/10/main/pg_hba.conf"
contype: host
databases: all
method: md5
users: "{{ db_user }}"
create: true
become: yes
become_user: postgres
notify: restart postgresql
\ No newline at end of file
---
db_user: ###DB_USER###
db_password: ###DB_PASSWORD###
db_name: ###DB_NAME###
\ No newline at end of file
---
- hosts: APP1
become: yes
vars_files:
- wordpress-vars.yml
pre_tasks:
- name: "Install packages"
###OS###: "name={{ item }} state=present"
with_items:
###OS_PACKETS###
- name: "Install Python packages"
pip: "name={{ item }} state=present"
with_items:
- docker
tasks:
- name: Start a WP container
community.docker.docker_container:
name: wordpress
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}}"
ports:
- "8080:80"
volumes_from:
- mydata
\ No newline at end of file
---
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###
\ No newline at end of file
ICG.py 0 → 100644
from ansibleBuilder import *
from doml2terraform import *
import json
import sys
arg_len = len(sys.argv)
if arg_len > 1:
file_name = sys.argv[1]
else:
print("Add parameters file name")
sys.exit()
input_file = open(file_name, "r")
parameters = json.load(input_file)
for step in parameters["steps"]:
if step["programing_lenguage"] == "ansible":
input_data = InputData(app_type=step["type"], code_path=step["output_path"], template_type=step["info"]["name"], template_path=step["info"]["template_path"], template_data=step["data"])
icg = AnsibleICG()
icg.generate_code(input_data)
elif step["programing_lenguage"] == "terraform":
input_data = step["data"]
TerraformICG(input_data)
\ No newline at end of file
{"provider": "aws", "network":{"subname": "Danilo", "vpcname": "Molteni"}, "vm":{"os": "ubuntu"}}
\ No newline at end of file
{"provider": "aws", "anagrafica":{"nome": "Danilo", "cognome": "Molteni"}, "vm":{"os": "ubuntu"}}
\ No newline at end of file
{"provider": "azurerm", "network":{"subname": "Danilo", "vpcname": "Molteni"}, "vm":{"source": "hashicorp/azurerm", "version": "~>2.0"}}
\ No newline at end of file
{"provider": "azurerm", "anagrafica":{"nome": "Danilo", "cognome": "Molteni"}, "vm":{"source": "hashicorp/azurerm", "version": "~>2.0"}}
\ No newline at end of file
{"provider": "gcp", "network":{"subname": "Danilo", "vpcname": "Molteni"}, "vm":{"name": "flask-vm-$8"}}
\ No newline at end of file
{"provider": "gcp", "anagrafica":{"nome": "Danilo", "cognome": "Molteni"}, "vm":{"name": "flask-vm-$8"}}
\ No newline at end of file
{
"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
---
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
---
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
---
provider: gcp
network:
- id: 1
subname: Danilo
vpcname: Molteni
vm:
- id: 1
name: flask-vm-$8
db:
- id: 1
name: Danilo
instance_name: Molteni
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment