Simple Terraform demo for GCP to deploy a Flask app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
greglebreton 69ce6ef047 maj 1 year ago
auth maj 1 year ago
docs maj 1 year ago
README.md maj 1 year ago
app.py push 1 year ago
main.tf maj 1 year ago
terraform.tfvars maj 1 year ago
variables.tf maj 1 year ago

README.md

TERRAFORM / GCP

PRE REQUIS

# LINUX INSTALL
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update && sudo apt-get install terraform

PREPARATION

  • Créer un projet "terraform-demo"
  • Séletionner le projet créé puis créer un compte de service dans l'onglet IAM et administration de la console GCP
  • Ajouter les rôles suivant:
    • Compute admin
    • Compute network admin
    • Service account admin
  • Activer les APIs nécessaires (compute engine API, storage API, cloud billing API)

SERVICES ACCOUNT

  • Créer une clé au sein du compte de service avec les droits sur le compute engine (pour créer les VMs), et télécharger le fichier json contenant la clé pour le mettre dans le dossier auth
  • Modifier l'id du projet dans le fichier variables.tf

UTILISATION

  • Lançer Terraform:
terraform init
  • Lançer Terraform:
terraform plan
  • Lançer Terraform:
terraform apply
# Saisir yes quand demandé

L'adresse public de la VM est fournie en output du terraform apply http://public-ip:5000

  • Se connecter en SSH à la VM pour créer l'application Flask:
nano app.py
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_cloud():
  return 'Hello Cloud!'

app.run(host='0.0.0.0')
  • Installer Flask:
python3 -m pip install flask
  • Lançer l'application:
python3 app.py
  • Visiter l'adresse fournie en output du terraform apply