Best practice per la comunicazione tra configurazioni
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Questa pagina fornisce linee guida e consigli per la comunicazione tra configurazioni quando utilizzi Terraform per Google Cloud.
Questa guida non è un'introduzione a Terraform. Per un'introduzione all'utilizzo di Terraform con Google Cloud, consulta Introduzione a Terraform.
Un problema comune che si verifica quando si utilizza Terraform è come condividere informazioni tra diverse configurazioni Terraform (eventualmente gestite da team diversi). In genere, le informazioni possono essere condivise tra le configurazioni senza dover essere memorizzate in un'unica directory di configurazione (o anche in un unico repository).
Il modo consigliato per condividere informazioni tra diverse configurazioni Terraform è utilizzare lo stato remoto per fare riferimento ad altri moduli principali.
Cloud Storage o
Terraform Enterprise
sono i backend dello stato preferiti.
Per eseguire query sulle risorse non gestite da Terraform, utilizza le origini dati del
provider Google.
Ad esempio, l'account di servizio Compute Engine predefinito può essere recuperato
utilizzando un'origine dati.
Non utilizzare le origini dati per eseguire query sulle risorse gestite da un'altra configurazione Terraform. In questo modo, puoi creare dipendenze implicite sui nomi e sulle strutture delle risorse che le normali operazioni di Terraform potrebbero rompere involontariamente.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[[["\u003cp\u003eThis page offers guidelines for cross-configuration communication in Terraform when working with Google Cloud.\u003c/p\u003e\n"],["\u003cp\u003eRemote state, using Cloud Storage or Terraform Enterprise, is recommended for sharing information between different Terraform configurations.\u003c/p\u003e\n"],["\u003cp\u003eUtilize data sources from the Google provider to query resources not managed by Terraform.\u003c/p\u003e\n"],["\u003cp\u003eAvoid using data sources to query resources managed by other Terraform configurations to prevent unintentional breaking changes.\u003c/p\u003e\n"]]],[],null,["# Best practices for cross-configuration communication\n\nThis page provides guidelines and recommendations for\ncross-configuration communication when using Terraform for Google Cloud.\n\nThis guide is not an introduction to Terraform. For an introduction to using\nTerraform with Google Cloud, see\n[Get started with Terraform](/docs/terraform/get-started-with-terraform).\n\nA common problem that arises when using Terraform is how to share information\nacross different Terraform configurations (possibly maintained by different\nteams). Generally, information can be shared between configurations without\nrequiring that they be stored in a single configuration directory (or even a\nsingle repository).\n\nThe recommended way to share information between different Terraform\nconfigurations is by using remote state to reference other root modules.\n[Cloud Storage](https://www.terraform.io/docs/backends/types/gcs.html)\nor\n[Terraform Enterprise](https://www.terraform.io/docs/backends/types/terraform-enterprise.html)\nare the preferred state backends.\n\nFor querying resources that are not managed by Terraform, use data sources from\nthe\n[Google provider](https://registry.terraform.io/providers/hashicorp/google/latest/docs).\nFor example, the default Compute Engine service account can be retrieved\n[using a data source](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/compute_default_service_account).\nDon't use data sources to query resources that are managed by another Terraform\nconfiguration. Doing so can create implicit dependencies on resource names and\nstructures that normal Terraform operations might unintentionally break.\n\nWhat's next\n-----------\n\n- Learn about [best practices for version control](/docs/terraform/best-practices/version-control).\n- Learn about [best practices when working with Google Cloud resources](/docs/terraform/best-practices/working-with-resources)."]]