My latest and complete articles are on pumpkin slow www.pkslow.com Welcome to tea. Com!
brief introduction
Yuan Shuang novel network https://www.2173.infoTerraform has been used in recent work. You can learn and record it. I hope it can help others.
Terraform series articles are as follows:
Terraform introductory tutorial, sample shows managing Docker and Kubernetes resources
Terraform plug-in Provider management, search, definition and download
Terraform State management to record changes
Terraform Module management, aggregation resource extraction and reuse
Terraform common commands
Provider is a plug-in
Provider can be understood as a plug-in. Terraform supports multi cloud infrastructure orchestration, but the optical terraform program is only a core function. Different providers are required to support different cloud platforms. In this way, platforms can be added flexibly. If AWS deployment is required, AWS providers can be added; If you need Kubernetes, add the function of Kubernetes.
In fact, a Provider is just a program. It is an independent process. Terrain from will communicate with the Provider to complete all functions.
Search Provider
There are four types of providers:
- Official: officially provided;
- Verified: officially certified;
- Community: provided by the community;
- Custom: custom;
We can get there( https://registry.terraform.io/browse/providers )To search, there are already very rich providers, which are basically enough.
Moreover, each Provider provides good documentation, such as GCP: https://registry.terraform.io/providers/hashicorp/google/latest/docs
˛
Define Provider
We can define which providers and corresponding versions to use, and create a new version TF file, as follows:
terraform { required_version = "= v0.15.4" required_providers { kubernetes = { source = "hashicorp/kubernetes" version = "= 2.2.0" } docker = { source = "kreuzwerker/docker" version = "= 2.12.2" } } }
The version number can be = or > = and so on, which is flexible and convenient.
Download Provider
After defining the Provider and the corresponding version number, you can download it through the terrain init command. As follows:
$ terraform init Initializing provider plugins... - Finding hashicorp/kubernetes versions matching "2.2.0"... - Finding kreuzwerker/docker versions matching "2.12.2"... - Installing kreuzwerker/docker v2.12.2... - Installed kreuzwerker/docker v2.12.2 (self-signed, key ID 24E54F214569A8A5) - Installing hashicorp/kubernetes v2.2.0... - Installed hashicorp/kubernetes v2.2.0 (signed by HashiCorp)
There are two problems to be solved:
(1) Where does it download from?
(2) Where has it been downloaded?
For the definition of Provider, there is a source value. The format is as follows:
[<HOSTNAME>]<NAMESPACE>/<TYPE>
HostName is optional. The default is the official registry Terraform. IO, so it is downloaded from this address. Of course, it can also build its own terrain warehouse, especially many large companies, which will not directly connect to the Internet.
Where will it be downloaded? In version terraform v0 15.4 on darwin_ Taking AMD64 as an example, it will be downloaded in the current directory of the project:
$ tree -a . ├── .terraform │ ├── modules │ │ └── modules.json │ └── providers │ └── registry.terraform.io │ ├── hashicorp │ │ └── kubernetes │ │ └── 2.2.0 │ │ └── darwin_amd64 │ │ └── terraform-provider-kubernetes_v2.2.0_x5 │ └── kreuzwerker │ └── docker │ └── 2.12.2 │ └── darwin_amd64 │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ └── terraform-provider-docker_v2.12.2 ├── .terraform.lock.hcl ├── main.tf ├── nginx │ ├── main.tf │ └── variables.tf └── versions.tf 13 directories, 11 files
But if each project has to be downloaded separately, it's too troublesome. We can put all plug-ins in the same place and specify them through - plugin dir, as follows:
$ rm -rf ./.terraform* $ terraform init -plugin-dir=/Users/larry/Software/terraform/plugins Initializing provider plugins... - Finding kreuzwerker/docker versions matching "2.12.2"... - Finding hashicorp/kubernetes versions matching "2.2.0"... - Installing kreuzwerker/docker v2.12.2... - Installed kreuzwerker/docker v2.12.2 (unauthenticated) - Installing hashicorp/kubernetes v2.2.0... - Installed hashicorp/kubernetes v2.2.0 (unauthenticated) $ tree -a . ├── .terraform │ ├── modules │ │ └── modules.json │ ├── plugin_path │ └── providers │ └── registry.terraform.io │ ├── hashicorp │ │ └── kubernetes │ │ └── 2.2.0 │ │ └── darwin_amd64 -> /Users/larry/Software/terraform/plugins/registry.terraform.io/hashicorp/kubernetes/2.2.0/darwin_amd64 │ └── kreuzwerker │ └── docker │ └── 2.12.2 │ └── darwin_amd64 -> /Users/larry/Software/terraform/plugins/registry.terraform.io/kreuzwerker/docker/2.12.2/darwin_amd64 ├── .terraform.lock.hcl ├── main.tf ├── nginx │ ├── main.tf │ └── variables.tf └── versions.tf 13 directories, 7 files
You can see that it only creates a Provider linked to the specified plugin directory in the current directory.
If you want to download it manually, you can go to this website: https://releases.hashicorp.com/
In fact, there are only a few providers used in work. You can download them directly and put them in the plugin directory.
Welcome to WeChat official account, "pumpkin slow talk", which will continue to update for you.
Read more and share more; Write more and organize more.