Why Is My Terraform Script Taking So Long to Create an AWS Lightsail Instance?

I’m running a Terraform script to create an instance on AWS for a Lightsail server with Linux and Gitlab code. However, the script has been running for over an hour, and it seems unlikely that it should be taking this long. Can anyone help me troubleshoot this issue? Here’s the code I’m using:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "4.58.0"
    }
    null = {
      source = "hashicorp/null"
    }
  }
}

provider "aws" {
  region = "eu-central-1"
}

locals {
  public_key = file(pathexpand("~/.ssh/id_rsa.pub"))
}

resource "aws_lightsail_key_pair" "mykeypair" {
  name       = "mykeypair"
  public_key = local.public_key
}

resource "aws_lightsail_instance" "gitlab_instance" {
  name              = "gitlab-instance"
  availability_zone = "eu-central-1a"
  blueprint_id      = "amazon_linux_2"
  bundle_id         = "nano_2_0"
  key_pair_name     = aws_lightsail_key_pair.mykeypair.name

  user_data = <<-EOF
    #!/bin/bash
    curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
    sudo EXTERNAL_URL="http://PLACEHOLDER_IP/" yum install -y gitlab-ce
    sudo gitlab-ctl reconfigure
    sudo gitlab-ctl restart
    touch /tmp/gitlab_ready
    EOF
}

resource "null_resource" "set_external_url" {
  depends_on = [aws_lightsail_instance.gitlab_instance]

  provisioner "local-exec" {
    command = "ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ec2-user@${aws_lightsail_instance.gitlab_instance.public_ip_address} 'while [ ! -f /tmp/gitlab_ready ]; do sleep 5; done; sudo gitlab-ctl reconfigure && sudo gitlab-ctl restart'"
  }
}

output "gitlab_instance_public_ip" {
  value = aws_lightsail_instance.gitlab_instance.public_ip_address
}

It would be helpful to see the actual output of terraform apply and see what’s being created / modified and for how long.
I’d bet it’s your local-exec command.
It seems to me /tmp/gitlab_ready is never being created