-1

I'm new to Terraform world. I'm trying to execute the shell script using terraform. However, I'm getting permission denied error.

Below is the main.tf file which executes the shell script

#Executing shell script via Null Resource

resource "null_resource" "install_istio" {
 provisioner "local-exec" {
    command = "${path.module}/install-istio.sh"
  }
}

Below is the install-istio.sh file

#!/bin/sh

# Download and install the Istio istioctl client binary

# Specify the Istio version that will be leveraged throughout these instructions
ISTIO_VERSION=1.7.3

curl -sL "https://github.com/istio/istio/releases/download/$ISTIO_VERSION/istioctl-$ISTIO_VERSION-linux-amd64.tar.gz" | tar xz

sudo mv ./istioctl /usr/local/bin/istioctl
sudo chmod +x /usr/local/bin/istioctl

# Install the Istio Operator on EKS
istioctl operator init

# The Istio Operator is installed into the istio-operator namespace. Query the namespace.
kubectl get all -n istio-operator

# Install Istio components
istioctl profile dump default

# Create the istio-system namespace and deploy the Istio Operator Spec to that namespace.
kubectl create ns istio-system
kubectl apply -f istio-eks.yaml

# Validate the Istio installation
kubectl get all -n istio-system

Below is the error:

module.istio_module.null_resource.install_istio (local-exec): Executing: ["/bin/sh" "-c" ".terraform/modules/istio_module/Istio-Operator/install-istio.sh"]
module.istio_module.null_resource.install_istio (local-exec): /bin/sh: .terraform/modules/istio_module/Istio-Operator/install-istio.sh: Permission denied
module.cluster.data.aws_eks_cluster_auth.auth: Refreshing state...
Error: Error running command '.terraform/modules/istio_module/Istio-Operator/install-istio.sh': exit status 126. Output: /bin/sh: .terraform/modules/istio_module/Istio-Operator/install-istio.sh: Permission denied

Can someone help me with the missing part? Appreciate all your help! Thanks!

Sweta Sharma
  • 2,404
  • 4
  • 21
  • 36

1 Answers1

1

I added chmod +x in the command section and it worked.

Sweta Sharma
  • 2,404
  • 4
  • 21
  • 36
  • Depending on the filesystem and pipeline you're using it can happend that the File permission are getting removed. To reensure that the permission are set, you can set the chmod before executing the script right in the same command string like following: command = "chmod +x ${path.cwd}/your_script_name.sh; ${path.cwd}/your_script_name.sh" – Flavio Caduff Jan 04 '23 at 10:37