Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local-exec provisioner error (exit status 127. Output: /bin/sh: 1: gcloud: not found) #10081

Closed
Knoparast opened this issue Sep 15, 2021 · 5 comments
Assignees
Labels
bug forward/review In review; remove label to forward service/container

Comments

@Knoparast
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.
  • Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.
  • If an issue is assigned to the modular-magician user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to hashibot, a community member has claimed the issue already.

Terraform Version

I am using Terraform Cloud with the following config:

terraform {
required_version = ">= 0.14"
required_providers {
google = {
source = "hashicorp/google"
version = ">= 3.50"
} } }

Affected Resource(s)

  • google_container_cluster
  • local-exec

Terraform Configuration Files

# Copy-paste your Terraform configurations here.
resource "google_container_cluster" "default" {
  name               = "dep1"
  location           = "us-central1"
  project            = var.service-dep
  initial_node_count = 1

  network            = google_compute_network.vpc-network-dep.name
  subnetwork         = google_compute_subnetwork.subnet2-vpc-custom-dep.name

  enable_legacy_abac = true
 
  node_config {
    tags = [var.node_tag]
  }
}

# ===========================================================
resource "null_resource" "default" {

  provisioner "local-exec" {
  
    command = "gcloud compute instance-groups set-named-ports ${google_container_cluster.default.instance_group_urls[0]} --named-ports=${var.port_name}:${var.node_port} --format=json"
  }
}

Issue Summary

  • Have added the following Environment Variables in my workspace:
    GOOGLE_CREDENTIALS set to my SA key
    GCLOUD_TF_DOWNLOAD set to always

  • All the resources get created in my project but it fails to run the gcloud command and throws the following error:

Error: local-exec provisioner error
with null_resource.default
on clusters.tf line 35, in resource "null_resource" "default":
provisioner "local-exec" {
Error running command 'gcloud compute instance-groups set-named-ports https://www.googleapis.com/compute/v1/projects/REDACTED/zones/us-central1-c/instanceGroups/gke-REDACTED-grp --named-ports=http:30000 --format=json': exit status 127. Output: /bin/sh: 1: gcloud: not found

Expected Behavior

The terraform runs properly when I apply it locally but in Terraform Cloud it fails running the "local-exec provisioner". I expect the terraform get applied successfully in Terraform Cloud as well.

@Knoparast Knoparast added the bug label Sep 15, 2021
@edwardmedia edwardmedia self-assigned this Sep 15, 2021
@edwardmedia
Copy link
Contributor

edwardmedia commented Sep 15, 2021

@Knoparast This might be a question for Terraform Cloud. Does it have gcloud installed in the environment? To verify, what do you see running below config?

Have you tried terraform apply your config locally?

resource "null_resource" "default" {
  provisioner "local-exec" {
    command = "gcloud compute instances list"
  }
}

@Knoparast
Copy link
Author

@edwardmedia The "terraform apply" runs successfully when I try the terraform locally since I have Cloud SDK on my machine:

......
null_resource.default (local-exec): Listed 0 items.
''''''
''''''
Apply complete! Resources: 24 added, 0 changed, 0 destroyed.

But on Cloud I get the same issue:

Error: local-exec provisioner error
with null_resource.default
on clusters.tf line 37, in resource "null_resource" "default":
provisioner "local-exec" {
Error running command 'gcloud compute instances list': exit status 127. Output: /bin/sh: 1: gcloud: not found

I found similar issues on Google GitHub like[1], so my assumption was that you may have a fix/workaround for it.

[1] terraform-google-modules/terraform-google-kubernetes-engine#721

@edwardmedia
Copy link
Contributor

@Knoparast shouldn't we think this is an Terraform Cloud issue? This is the place where we focus on the google provider. Can you check Terraform Cloud to see if they can help?

The terraform runs properly when I apply it locally but in Terraform Cloud it fails running the "local-exec provisioner". I expect the terraform get applied successfully in Terraform Cloud as well.

@Knoparast
Copy link
Author

It seems Terraform Cloud env doesn't install gcloud. I resolved the issue via using gcloud module:

module "gcloud" {
source = "terraform-google-modules/gcloud/google"
version = "~> 2.0"

use_tf_google_credentials_env_var = true

create_cmd_entrypoint = "gcloud"
create_cmd_body = "compute instance-groups set-named-ports --project=${var.REDACTED} ${google_container_cluster.default.instance_group_urls[0]} --named-ports=${var.port_name}:${var.node_port} --format=json"
}

Posting the resolution here for others may have similar issue. I go ahead and close this ticket. Thanks.

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 17, 2021
@github-actions github-actions bot added service/container forward/review In review; remove label to forward labels Jan 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug forward/review In review; remove label to forward service/container
Projects
None yet
Development

No branches or pull requests

2 participants