'Error creating StandardAppVersion: googleapi: Error 404: App does not exist

Hi i am trying to create a simple node app on google app standard app engine using this terraform code. This code used to work before but today i was trying to restart the whole project and re-deploy everything again and i see that i am getting an error.

compute_engine.tf

resource "google_app_engine_standard_app_version" "nodetest" {
  version_id = "v1"
  service    = "mainApp"
  runtime    = "nodejs10"

  instance_class = "B1"

  basic_scaling {
    max_instances = 1
  }

  entrypoint {
    shell = "node test.js"
  }

  deployment {
    files {
      name       = google_storage_bucket_object.object.name
      source_url = "https://storage.googleapis.com/${google_storage_bucket.bucket.name}/${google_storage_bucket_object.object.name}"
    }
  }

  delete_service_on_destroy = true

  depends_on = [
    google_project_service.appengine_api
  ]
}

resource "google_storage_bucket" "bucket" {
  project  = var.project_id
  name     = var.bucket_name
  location = var.region
}

resource "google_storage_bucket_object" "object" {
  name    = "test.js"
  bucket  = google_storage_bucket.bucket.name
  source = "test.js"
}

My test.js is located in the same directory as where tf is located.

test.js

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

I see that the files have already been deployed correctly

enter image description here

And the error i am getting

enter image description here

I tried changing the url from

"https://storage.googleapis.com/${google_storage_bucket.bucket.name}/${google_storage_bucket_object.object.name}"

To

"https://storage.cloud.com/${google_storage_bucket.bucket.name}/${google_storage_bucket_object.object.name}"

Try changing the shell = "node test.js" to shell = "node ./test.js"

Also i did take a look at GitHub Issue 4974 but is doesnt solve my problem. I did notice that when i try to terraform apply the error pretty much pop up quite fast so it seem that is stuck on a very first validation error.



Solution 1:[1]

Does the user that runs compute_engine.tf has "appengine.applications.create" and deploy permissions?

Also check if you set project and region in your google provider.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Veronika B