diff --git a/docs/installation.md b/docs/installation.md index ae7af977..a286d2be 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -3,7 +3,7 @@ ### On Linux/MacOS ``` -export PROTOCONF_VERSION="0.1.4" +export PROTOCONF_VERSION="0.1.5" export PROTOCONF_OS=$(uname | tr '[A-Z]' '[a-z]') # change to "arm64" if needed export PROTOCONF_ARCH="amd64" diff --git a/docs/integrations/terraform.md b/docs/integrations/terraform.md index ea2dc244..9c3a03cc 100644 --- a/docs/integrations/terraform.md +++ b/docs/integrations/terraform.md @@ -20,33 +20,47 @@ provider "tls" {} $ terraform init ``` -### Copy all providers binaries to same directory - -```shell -$ find .terraform -type f -exec cp {} .terraform \; -``` - ### Generate the terraform protos ```shell -$ protoconf import terraform -import_path .terraform +$ protoconf import terraform ``` -Validate the outpus +Validate the outputs ```shell -$ ll src/terraform -total 48K -drwxr-xr-x 10 smintz 320 May 23 10:46 . -drwxr-xr-x 3 smintz 96 May 23 10:39 .. --rw-r--r-- 1 smintz 461 May 23 10:46 meta.proto --rw-r--r-- 1 smintz 51 May 23 10:46 random-data.proto --rw-r--r-- 1 smintz 371 May 23 10:46 random-provider.proto --rw-r--r-- 1 smintz 8.1K May 23 10:46 random-resources.proto --rw-r--r-- 1 smintz 4.5K May 23 10:46 terraform.proto --rw-r--r-- 1 smintz 1.9K May 23 10:46 tls-data.proto --rw-r--r-- 1 smintz 362 May 23 10:46 tls-provider.proto --rw-r--r-- 1 smintz 6.1K May 23 10:46 tls-resources.proto +$ find src/terraform +src/terraform +src/terraform/v1 +src/terraform/v1/terraform.proto +src/terraform/v1/meta.proto +src/terraform/tls +src/terraform/tls/datasources +src/terraform/tls/datasources/v3 +src/terraform/tls/datasources/v3/public.proto +src/terraform/tls/datasources/v3/certificate.proto +src/terraform/tls/resources +src/terraform/tls/resources/v3 +src/terraform/tls/resources/v3/private.proto +src/terraform/tls/resources/v3/self.proto +src/terraform/tls/resources/v3/cert.proto +src/terraform/tls/resources/v3/locally.proto +src/terraform/tls/provider +src/terraform/tls/provider/v3 +src/terraform/tls/provider/v3/tls.proto +src/terraform/random +src/terraform/random/resources +src/terraform/random/resources/v3 +src/terraform/random/resources/v3/password.proto +src/terraform/random/resources/v3/integer.proto +src/terraform/random/resources/v3/string.proto +src/terraform/random/resources/v3/pet.proto +src/terraform/random/resources/v3/shuffle.proto +src/terraform/random/resources/v3/id.proto +src/terraform/random/resources/v3/uuid.proto +src/terraform/random/provider +src/terraform/random/provider/v3 +src/terraform/random/provider/v3/random.proto ``` The `src/terraform/terraform.proto` should looks like this: @@ -54,17 +68,37 @@ The `src/terraform/terraform.proto` should looks like this: ```proto syntax = "proto3"; -package terraform; +package terraform.v1; + +import "terraform/random/provider/v3/random.proto"; + +import "terraform/random/resources/v3/id.proto"; + +import "terraform/random/resources/v3/integer.proto"; + +import "terraform/random/resources/v3/password.proto"; + +import "terraform/random/resources/v3/pet.proto"; + +import "terraform/random/resources/v3/shuffle.proto"; + +import "terraform/random/resources/v3/string.proto"; + +import "terraform/random/resources/v3/uuid.proto"; + +import "terraform/tls/datasources/v3/certificate.proto"; -import "terraform/random-provider.proto"; +import "terraform/tls/datasources/v3/public.proto"; -import "terraform/random-resources.proto"; +import "terraform/tls/provider/v3/tls.proto"; -import "terraform/tls-data.proto"; +import "terraform/tls/resources/v3/cert.proto"; -import "terraform/tls-provider.proto"; +import "terraform/tls/resources/v3/locally.proto"; -import "terraform/tls-resources.proto"; +import "terraform/tls/resources/v3/private.proto"; + +import "terraform/tls/resources/v3/self.proto"; message Terraform { Resources resource = 1; @@ -84,39 +118,39 @@ message Terraform { TerraformSettings terraform = 8; message Resources { - map random_id = 1 [json_name = "random_id"]; + map random_id = 1 [json_name = "random_id"]; - map random_integer = 2 [json_name = "random_integer"]; + map random_integer = 2 [json_name = "random_integer"]; - map random_password = 3 [json_name = "random_password"]; + map random_password = 3 [json_name = "random_password"]; - map random_pet = 4 [json_name = "random_pet"]; + map random_pet = 4 [json_name = "random_pet"]; - map random_shuffle = 5 [json_name = "random_shuffle"]; + map random_shuffle = 5 [json_name = "random_shuffle"]; - map random_string = 6 [json_name = "random_string"]; + map random_string = 6 [json_name = "random_string"]; - map random_uuid = 7 [json_name = "random_uuid"]; + map random_uuid = 7 [json_name = "random_uuid"]; - map tls_cert_request = 8 [json_name = "tls_cert_request"]; + map tls_cert_request = 8 [json_name = "tls_cert_request"]; - map tls_locally_signed_cert = 9 [json_name = "tls_locally_signed_cert"]; + map tls_locally_signed_cert = 9 [json_name = "tls_locally_signed_cert"]; - map tls_private_key = 10 [json_name = "tls_private_key"]; + map tls_private_key = 10 [json_name = "tls_private_key"]; - map tls_self_signed_cert = 11 [json_name = "tls_self_signed_cert"]; + map tls_self_signed_cert = 11 [json_name = "tls_self_signed_cert"]; } message Datasources { - map tls_certificate = 1 [json_name = "tls_certificate"]; + map tls_certificate = 1 [json_name = "tls_certificate"]; - map tls_public_key = 2 [json_name = "tls_public_key"]; + map tls_public_key = 2 [json_name = "tls_public_key"]; } message Providers { - repeated random.provider.Random random = 1; + repeated terraform.random.provider.v3.Random random = 1; - repeated tls.provider.Tls tls = 2; + repeated terraform.tls.provider.v3.Tls tls = 2; } message Variable { @@ -137,7 +171,7 @@ message Terraform { message TerraformSettings { string required_version = 1 [json_name = "required_version"]; - map required_providers = 2; + map required_providers = 2 [json_name = "required_providers"]; Backend backend = 3; @@ -151,7 +185,9 @@ message Terraform { oneof config { BackendLocal local = 1; - BackendS3 s3 = 2; + BackendRemote remote = 2; + + BackendS3 s3 = 3; } message BackendLocal { @@ -160,6 +196,28 @@ message Terraform { string workspace_dir = 2 [json_name = "workspace_dir"]; } + message BackendRemote { + //(Optional) The remote backend hostname to connect to. Defaults to app.terraform.io. + string hostname = 1; + + //(Required) The name of the organization containing the targeted workspace(s). + string organization = 2; + + //(Optional) The token used to authenticate with the remote backend. We recommend omitting the token from the configuration, and instead using `terraform login` or manually configuring `credentials` in the CLI config file. + string token = 3; + + //(Required) A block specifying which remote workspace(s) to use. The workspaces block supports the following keys + Workspace workspaces = 4; + + message Workspace { + //(Optional) The full name of one remote workspace. When configured, only the default workspace can be used. This option conflicts with prefix. + string name = 1; + + //(Optional) A prefix used in the names of one or more remote workspaces, all of which can be used with this configuration. The full workspace names are used in Terraform Cloud, and the short names (minus the prefix) are used on the command line for Terraform CLI workspaces. If omitted, only the default workspace can be used. This option conflicts with name. + string prefix = 2; + } + } + message BackendS3 { string region = 1; @@ -233,9 +291,9 @@ message Terraform { ```python # vim: filetype=python # ./src/tfdemo/tfdemo.tf.pconf -load("//terraform/terraform.proto", "Terraform") -load("//terraform/random-provider.proto", "Random") -load("//terraform/random-resources.proto", "RandomPet") +load("//terraform/v1/terraform.proto", "Terraform") +load("//terraform/random/provider/v3/random.proto", "Random") +load("//terraform/random/resources/v3/pet.proto", "RandomPet") tf = Terraform( provider=Terraform.Providers(random=[Random()]), @@ -260,7 +318,7 @@ $ protoconf compile . Check the output ```shell -cat materialized_config/tfdemo/tfdemo.tf.materialized_JSON| jq +cat materialized_config/tfdemo/tfdemo.tf.materialized_JSON ``` ```json @@ -274,9 +332,7 @@ cat materialized_config/tfdemo/tfdemo.tf.materialized_JSON| jq } }, "provider": { - "random": [ - {} - ] + "random": [{}] }, "resource": { "random_pet": { @@ -292,11 +348,11 @@ cat materialized_config/tfdemo/tfdemo.tf.materialized_JSON| jq ```shell $ mkdir tf $ cat materialized_config/tfdemo/tfdemo.tf.materialized_JSON | jq '.value | del(.["@type"])' > tf/test.tf.json -$ cd tf -$ terraform init +$ terraform -chdir=tf init ``` + ```shell -$ terraform plan +$ terraform -chdir=tf plan An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: @@ -322,8 +378,9 @@ Note: You didn't specify an "-out" parameter to save this plan, so Terraform can't guarantee that exactly these actions will be performed if "terraform apply" is subsequently run. ``` + ```shell -$ terraform apply -auto-approve +$ terraform -chdir=tf apply -auto-approve random_pet.my_dog_name: Creating... random_pet.my_dog_name: Creation complete after 0s [id=key-zebra] @@ -333,4 +390,3 @@ Outputs: my_dog_name = "key-zebra" ``` - diff --git a/docs/integrations/terraform_kubernetes.md b/docs/integrations/terraform_kubernetes.md index 2d6e57c2..28acaf12 100644 --- a/docs/integrations/terraform_kubernetes.md +++ b/docs/integrations/terraform_kubernetes.md @@ -19,28 +19,67 @@ provider "kubernetes" {} $ terraform init ``` -### Copy all providers binaries to same directory - -```shell -$ find .terraform -type f -exec cp {} .terraform \; -``` - ### Generate the terraform protos ```shell -$ protoconf import terraform -import_path .terraform +$ protoconf import terraform ``` Validate the outpus ```shell -$ ls -l src/terraform/ -total 992 --rw-r--r--. 1 marius marius 81687 Jun 25 12:39 kubernetes-data.proto --rw-r--r--. 1 marius marius 1963 Jun 25 12:39 kubernetes-provider.proto --rw-r--r--. 1 marius marius 911814 Jun 25 12:39 kubernetes-resources.proto --rw-r--r--. 1 marius marius 461 Jun 25 12:39 meta.proto --rw-r--r--. 1 marius marius 9100 Jun 25 12:39 terraform.proto +$ find src/terraform +src/terraform +src/terraform/v1 +src/terraform/v1/terraform.proto +src/terraform/v1/meta.proto +src/terraform/kubernetes +src/terraform/kubernetes/datasources +src/terraform/kubernetes/datasources/v2 +src/terraform/kubernetes/datasources/v2/namespace.proto +src/terraform/kubernetes/datasources/v2/all.proto +src/terraform/kubernetes/datasources/v2/persistent.proto +src/terraform/kubernetes/datasources/v2/storage.proto +src/terraform/kubernetes/datasources/v2/service.proto +src/terraform/kubernetes/datasources/v2/ingress.proto +src/terraform/kubernetes/datasources/v2/config.proto +src/terraform/kubernetes/datasources/v2/pod.proto +src/terraform/kubernetes/datasources/v2/secret.proto +src/terraform/kubernetes/resources +src/terraform/kubernetes/resources/v2 +src/terraform/kubernetes/resources/v2/mutating.proto +src/terraform/kubernetes/resources/v2/priority.proto +src/terraform/kubernetes/resources/v2/namespace.proto +src/terraform/kubernetes/resources/v2/validating.proto +src/terraform/kubernetes/resources/v2/stateful.proto +src/terraform/kubernetes/resources/v2/manifest.proto +src/terraform/kubernetes/resources/v2/cluster.proto +src/terraform/kubernetes/resources/v2/api.proto +src/terraform/kubernetes/resources/v2/job.proto +src/terraform/kubernetes/resources/v2/persistent.proto +src/terraform/kubernetes/resources/v2/daemonset.proto +src/terraform/kubernetes/resources/v2/cron.proto +src/terraform/kubernetes/resources/v2/role.proto +src/terraform/kubernetes/resources/v2/deployment.proto +src/terraform/kubernetes/resources/v2/storage.proto +src/terraform/kubernetes/resources/v2/csi.proto +src/terraform/kubernetes/resources/v2/endpoints.proto +src/terraform/kubernetes/resources/v2/service.proto +src/terraform/kubernetes/resources/v2/ingress.proto +src/terraform/kubernetes/resources/v2/default.proto +src/terraform/kubernetes/resources/v2/certificate.proto +src/terraform/kubernetes/resources/v2/replication.proto +src/terraform/kubernetes/resources/v2/limit.proto +src/terraform/kubernetes/resources/v2/horizontal.proto +src/terraform/kubernetes/resources/v2/resource.proto +src/terraform/kubernetes/resources/v2/network.proto +src/terraform/kubernetes/resources/v2/config.proto +src/terraform/kubernetes/resources/v2/daemon.proto +src/terraform/kubernetes/resources/v2/pod.proto +src/terraform/kubernetes/resources/v2/secret.proto +src/terraform/kubernetes/provider +src/terraform/kubernetes/provider/v2 +src/terraform/kubernetes/provider/v2/kubernetes.proto ``` ### Create directory for the Starlark configuration file (.pconf) @@ -55,9 +94,9 @@ $ mkdir src/proto-kube/ # vim: filetype=python # ./src/proto-kube/kube-pod.pconf -load("//terraform/terraform.proto", "Terraform") -load("//terraform/kubernetes-provider.proto", "Kubernetes") -load("//terraform/kubernetes-resources.proto", "KubernetesPod") +load("//terraform/v1/terraform.proto", "Terraform") +load("//terraform/kubernetes/provider/v2/kubernetes.proto", "Kubernetes") +load("//terraform/kubernetes/resources/v2/pod.proto", "KubernetesPod") tf = Terraform( provider=Terraform.Providers( @@ -93,7 +132,7 @@ $ protoconf compile . ### Check the json output ```shell -cat materialized_config/proto-kube/kube-pod.materialized_JSON | jq . +cat materialized_config/proto-kube/kube-pod.materialized_JSON ``` ```json @@ -116,11 +155,7 @@ cat materialized_config/proto-kube/kube-pod.materialized_JSON | jq . }, "spec": { "container": { - "command": [ - "/bin/bash", - "-c", - "sleep 2000000000000" - ], + "command": ["/bin/bash", "-c", "sleep 2000000000000"], "image": "centos/tools", "name": "test-container" } @@ -141,12 +176,14 @@ $ mkdir tf ``` ### Process json required by Terraform + ```shell $ cat materialized_config/proto-kube/kube-pod.materialized_JSON | \ jq '.value | del(.["@type"])' > tf/proto-kube.tf.json ``` ### Check the json required by Terraform + ```shell $ cat tf/proto-kube.tf.json { @@ -182,6 +219,7 @@ $ cat tf/proto-kube.tf.json ``` ### Run Terraform init + ```shell $ cd tf ~/tf $ terraform init @@ -211,6 +249,7 @@ commands will detect it and remind you to do so if necessary. ``` ### Run Terraform plan + ```shell ~/tf $ terraform plan Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: @@ -223,6 +262,7 @@ Plan: 1 to add, 0 to change, 0 to destroy. ``` ### Run Terraform apply + ```shell ~/tf $ terraform apply -auto-approve