How many grpc servers are there?

Suppose I have this terraform script:

# S3 Backend Configuration
terraform {
  backend "s3" {
    bucket         = "my-terraform-state-bucket"
    key            = "iam/user/terraform.tfstate"
    region         = "us-west-2"
    encrypt        = true
    dynamodb_table = "terraform-state-lock"
  }

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

# Configure AWS Provider
provider "aws" {
  region = "us-west-2"
}

# Create IAM User
resource "aws_iam_user" "example_iam_user" {
  name = "example-user"
  path = "/users/"
}

Assume this script is run by 5 different users concurrently. Each user creates a different IAM user ie user1 creates example_iam_user_1 etc

My understanding is a plugin is a grpc server.

Dumb questions, is there a 1 grpc server for every user that runs the script (5 in my example) ? Is there 1 grpc server for all users ?

If I’m way off base, please correct me.

Assume this script is run by 5 different users concurrently

You mean there are 5 different users executing Terraform on different hosts? From Terraform’s perspective there is only ever one “user”, the user currently executing the Terraform binary. It does not know what other process may exist elsewhere, nor does it know what an aws_iam_user is, that is just like any other resource as far as Terraform is concerned.

Terraform communicates with a plugin (a provider) using grpc, and the plugin process is what runs the server side of the connection. There is no defined number of processes being run, Terraform will start and stop them as needed for various purposes during execution.

Your example here will use only a single configured AWS provider at a time, since you have only a single provider configuration.

You mean there are 5 different users executing Terraform on different hosts?

Yes. Sorry I wasn’t clear.

Terraform communicates with a plugin (a provider) using grpc

I’m not very familiar with grpc, but is there a way to find the grpc server address that the terraform client is using ?

By terraform client, I mean when user runs, say, terraform apply ?

Using TF_LOG=debug will output the PID and address of the plugins as they are started. Example output would look like:

[DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/hashicorp/null/3.2.3/darwin_arm64/terraform-provider-null_v3.2.3_x5 pid=14053
[DEBUG] provider.terraform-provider-null_v3.2.3_x5: plugin address: address=/var/folders/v_/nvx0gdtd3x9g03ym960qw9j80000gn/T/plugin3206092041
1 Like