Error while installing hashicorp/alicloud v1.172.0: stream error: stream ID │ 1; PROTOCOL_ERROR

I am new to GitLab and Terraform, currently trying to run terraform script using GitLab CI/CD. Appreciate if someone can help me understand this error and how to solve it.

Terraform Version

Terraform v1.1.9
on linux_amd64

Terraform Configuration Files

image: registry.gitlab.com/gitlab-org/terraform-images/stable:latest

variables:
  TF_ROOT: ${CI_PROJECT_DIR}
  TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${CI_PROJECT_NAME}

cache:
  key: terraform-kubernetes-poc
  paths:
    - ${TF_ROOT}/.terraform

before_script:
  - export ALICLOUD_ACCESS_KEY=${ALICLOUD_ACCESS_KEY}
  - export ALICLOUD_SECRET_ACCESS_KEY=${ALICLOUD_SECRET_KEY}
  - export ALICLOUD_REGION=${ALICLOUD_REGION}
  - export TF_LOG="TRACE"
  - cd ${TF_ROOT}
  - gitlab-terraform --version

stages:
  - prepare
  - validate
  - build
  - deploy
  - cleanup

init:
  stage: prepare
  script:
    - gitlab-terraform init

validate:
  stage: validate
  script:
    - gitlab-terraform validate

plan:
  stage: build
  script:
    - gitlab-terraform plan -lock=false
    - gitlab-terraform plan -json
  artifacts:
    name: plan
    paths:
      - ${TF_ROOT}/plan.cache
    reports:
      terraform: ${TF_ROOT}/plan.json

apply:
  stage: deploy
  environment:
    name: production
  script:
    - gitlab-terraform apply
  dependencies:
    - plan
  only:
    - main

destroy:
  stage: cleanup
  script:
    - gitlab-terraform destroy
  when: manual

Expected Behavior

Initializing the backend…
Successfully configured the backend “http”! Terraform will automatically
use this backend unless the backend configuration changes.
Initializing provider plugins…

  • Finding latest version of hashicorp/alicloud…
  • Installing hashicorp/alicloud v1.172.0…
  • Installed hashicorp/alicloud v1.172.0 (signed by HashiCorp)
    Terraform has created a lock file .terraform.lock.hcl to record the provider
    selections it made above. Include this file in your version control repository
    so that Terraform can guarantee to make the same selections by default when
    you run “terraform init” in the future.

    │ Warning: Additional provider information from registry

    │ The remote registry returned warnings for
    Terraform Registry
    │ - For users on Terraform 0.13 or greater, this provider has moved to
    │ aliyun/alicloud. Please update your source in required_providers.

    Terraform has been successfully initialized!

Actual Behavior

Initializing the backend…
Successfully configured the backend “http”! Terraform will automatically
use this backend unless the backend configuration changes.
Initializing provider plugins…

  • Finding latest version of hashicorp/alicloud…
  • Installing hashicorp/alicloud v1.172.0…

    │ Warning: Additional provider information from registry

    │ The remote registry returned warnings for
    Terraform Registry
    │ - For users on Terraform 0.13 or greater, this provider has moved to
    │ aliyun/alicloud. Please update your source in required_providers.


    │ Error: Failed to install provider

    │ Error while installing hashicorp/alicloud v1.172.0: stream error: stream ID
    │ 1; PROTOCOL_ERROR

Steps to Reproduce

  1. terraform init
  2. terraform validate
  3. terraform plan

Additional Context

  • I have a separate provider.tf with just 1 line provider "alicloud" {}
  • Stored my Alicloud Keys in GitLab’s CICD Variables
  • My .gitlab-ci.yml is more or less similar to the template here.
  • Using a Docker executor for the GitLab CI.
  • The error seems quite random, it could happen in terraform init or terraform plan job.
  • Rerunning the job seems to get around the issue but it has happened way too many times to ignore it.