Créer une application Flask sur Compute Engine
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Créez une application Flask à l'aide de Compute Engine, Mise en réseau, Storage et KMS.
Exemple de code
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],[],[],[],null,["# Create a Flask application on Compute Engine\n\nUse Compute Engine, Networking, Storage, and KMS to create a Flask application.\n\nCode sample\n-----------\n\n### Terraform\n\n\nTo learn how to apply or remove a Terraform configuration, see\n[Basic Terraform commands](/docs/terraform/basic-commands).\n\n\nFor more information, see the\n[Terraform provider reference documentation](https://registry.terraform.io/providers/hashicorp/google/latest/docs).\n\n resource \"google_compute_network\" \"vpc_network\" {\n name = \"my-custom-mode-network\"\n auto_create_subnetworks = false\n mtu = 1460\n }\n\n resource \"google_compute_subnetwork\" \"default\" {\n name = \"my-custom-subnet\"\n ip_cidr_range = \"10.0.1.0/24\"\n region = \"us-west1\"\n network = google_compute_network.vpc_network.id\n }\n\n # Create a single Compute Engine instance\n resource \"google_compute_instance\" \"default\" {\n name = \"flask-vm\"\n machine_type = \"f1-micro\"\n zone = \"us-west1-a\"\n tags = [\"ssh\"]\n\n boot_disk {\n initialize_params {\n image = \"debian-cloud/debian-11\"\n }\n }\n\n # Install Flask\n metadata_startup_script = \"sudo apt-get update; sudo apt-get install -yq build-essential python3-pip rsync; pip install flask\"\n\n network_interface {\n subnetwork = google_compute_subnetwork.default.id\n\n access_config {\n # Include this section to give the VM an external IP address\n }\n }\n }\n\n resource \"google_compute_firewall\" \"ssh\" {\n name = \"allow-ssh\"\n allow {\n ports = [\"22\"]\n protocol = \"tcp\"\n }\n direction = \"INGRESS\"\n network = google_compute_network.vpc_network.id\n priority = 1000\n source_ranges = [\"0.0.0.0/0\"]\n target_tags = [\"ssh\"]\n }\n\n\n resource \"google_compute_firewall\" \"flask\" {\n name = \"flask-app-firewall\"\n network = google_compute_network.vpc_network.id\n\n allow {\n protocol = \"tcp\"\n ports = [\"5000\"]\n }\n source_ranges = [\"0.0.0.0/0\"]\n }\n\n # Create new multi-region storage bucket in the US\n # with versioning enabled\n\n resource \"google_kms_key_ring\" \"terraform_state\" {\n name = \"${random_id.bucket_prefix.hex}-bucket-tfstate\"\n location = \"us\"\n }\n\n resource \"google_kms_crypto_key\" \"terraform_state_bucket\" {\n name = \"test-terraform-state-bucket\"\n key_ring = google_kms_key_ring.terraform_state.id\n rotation_period = \"86400s\"\n\n lifecycle {\n prevent_destroy = false\n }\n }\n\n # Enable the Cloud Storage service account to encrypt/decrypt Cloud KMS keys\n data \"google_project\" \"project\" {\n }\n\n resource \"google_project_iam_member\" \"default\" {\n project = data.google_project.project.project_id\n role = \"roles/cloudkms.cryptoKeyEncrypterDecrypter\"\n member = \"serviceAccount:service-${data.google_project.project.number}@gs-project-accounts.iam.gserviceaccount.com\"\n }\n\n resource \"random_id\" \"bucket_prefix\" {\n byte_length = 8\n }\n\n resource \"google_storage_bucket\" \"default\" {\n name = \"${random_id.bucket_prefix.hex}-bucket-tfstate\"\n force_destroy = false\n location = \"US\"\n storage_class = \"STANDARD\"\n versioning {\n enabled = true\n }\n encryption {\n default_kms_key_name = google_kms_crypto_key.terraform_state_bucket.id\n }\n depends_on = [\n google_project_iam_member.default\n ]\n }\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=storage)."]]