Deploy AWS stack using pulumi error: no stack named 'dev' found

60 Views Asked by At

I'm trying to deploy a stack using pulumi in my AWS account. My deploy.yml looks like this:

name: Pushes Glue Scripts to S3

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "main" branch
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Deploy jobs
        uses: pulumi/actions@v5
        id: pulumi
        env:
          PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
        with:
          command: up
          cloud-url: s3://my-bucket/pulumi/
          stack-name: dev

In my repository I have my stack file named Pulumi.dev.yaml. The file itself have just an encryption salt code. It's important to say I configured the pulumi backend into my S3 bucket using the command: pulumi login s3://my-bucket/pulumi.

However, when I run my deploy code, I get the following error:

 StackNotFoundError: code: -2
 stdout: 
 stderr: Command failed with exit code 255: pulumi stack select --stack dev --non-interactive
error: no stack named 'dev' found
 err?: Error: Command failed with exit code 255: pulumi stack select --stack dev --non-interactive
error: no stack named 'dev' found

I believe the container which runs the pulumi up code isn't seeing my stack. So, how can I fix this? Is there any step to check when runing my Github Actions with Pulumi?

1

There are 1 best solutions below

0
Guilherme Noronha On BEST ANSWER

After several days I managed to find a solution, although I believe it's not the best or suitable one. I had to refactor all my deployment script to achieve what I needed. Bellow, follows the script and an explanation:

name: Pushes Glue Scripts to S3

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "main" branch
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

env:
  PULUMI_STACK: dev
  PULUMI_CONFIG_PASSPHRASE:
  GLUE_SCRIPT_LOCATION: ${{  vars.GLUE_SCRIPT_LOCATION }}

jobs:

  deploy-glue-jobs:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./glue_jobs

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
  
      - name: Install Pulumi
        uses: pulumi/[email protected]

      - name: Install Poetry
        run: pip install poetry

      - name: Installing Project Dependencies
        run: |
          poetry config virtualenvs.in-project true
          poetry install

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v2
        with:
          aws-access-key-id: ${{ secrets.GLUE_ACCESS_KEY }}
          aws-secret-access-key: ${{ secrets.GLUE_SECRET_ACCESS_KEY }}
          aws-region: us-east-1
  
      - name: Start Pulumi
        run: |
          poetry run pulumi login s3://my-bucket/pulumi
          poetry run pulumi stack select dev
          poetry run pulumi stack init dev
        continue-on-error: true

      - name: Deploy Pulumi
        run: poetry run pulumi up --yes

The pulumi/actions@v5 didn't work for me. Then I had to split all the process of deploying services using pulumi.

First, I need to install pulumi and configure the AWS credentials. As I'm using poetry to manage my dependencies, I added a step to install, configure, and manage it. Then, I assured to run pulumi from my environment using poetry commands.

Well, as I said, this worked. But it can be improved? I believe so. Therefore, please feel free to add a more suitable answer. For now, I'm keeping this.