Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google: Cannot create a SQLDb instance because of a badRequest - not enough logs #3720

Open
1 task done
eduardosanzb opened this issue Sep 3, 2024 · 0 comments
Open
1 task done
Labels
bug Something isn't working new Un-triaged issue pre-built providers Issues around pre-built providers managed at https://github.com/hashicorp/cdktf-repository-manager

Comments

@eduardosanzb
Copy link

eduardosanzb commented Sep 3, 2024

Expected Behavior

SQL DB should be created. I'm using the same configuration as I"d use with HCL.

I redacted the company name from the logs

Actual Behavior

THe debug message from why is the request badly done is not enough to continue. I'm not able to create a SQLdb in GCP

Steps to Reproduce

With the next code, just run cdtfk deploy.
The plan went fine.

import { App, TerraformStack } from 'cdktf'
import { Construct } from 'constructs'
import { GoogleProvider } from '@cdktf/provider-google/lib/provider'
import * as path from 'path'
import * as fs from 'fs'
import { SqlDatabaseInstance } from '@cdktf/provider-google/lib/sql-database-instance'
import { DataGoogleProject } from '@cdktf/provider-google/lib/data-google-project'
import { SqlDatabase } from '@cdktf/provider-google/lib/sql-database'
import { password } from './.gen/providers/random'
import { SqlUser } from '@cdktf/provider-google/lib/sql-user'
import { RandomProvider } from './.gen/providers/random/provider'

class MyStack extends TerraformStack {
  constructor(scope: Construct, name: string) {
    super(scope, name)

    const credentialsPath = path.join(process.cwd(), 'google.json')
    const credentials = fs.existsSync(credentialsPath)
      ? fs.readFileSync(credentialsPath).toString()
      : '{}'

    console.log('credentialsPath', credentialsPath)
    console.log('credentials', credentials)
    const region = 'europe-west4'
    const projectId = 'company-development'
    new GoogleProvider(this, 'Google', {
      region,
      project: projectId,
      // credentials, //using the ones from ADC
    })

    new RandomProvider(this, 'random', {})

    const googleProject = new DataGoogleProject(this, 'project', {
      projectId,
    })

    const dbInstance = new SqlDatabaseInstance(this, 'db-instance', {
      project: googleProject.id,
      region,
      name: 'db-instance',
      databaseVersion: 'POSTGRES_13',

      settings: {
        tier: 'db-f1-micro',
        diskSize: 10,
        diskType: 'PD_SSD',
        availabilityType: 'REGIONAL',

        databaseFlags: [
          {
            name: 'autovacuum',
            value: 'on',
          },
          {
            name: 'max_connections',
            value: '100',
          },
          {
            name: 'max_wal_size',
            value: '1GB',
          },
        ],

        deletionProtectionEnabled: false,

        ipConfiguration: {
          ipv4Enabled: true,
          // requireSsl: true,
        },
        maintenanceWindow: {
          day: 1,
          hour: 4,
          updateTrack: 'stable',
        },
        backupConfiguration: {
          enabled: true,
          binaryLogEnabled: true,
          pointInTimeRecoveryEnabled: true,
          startTime: '05:00',
          location: 'EU',
        },
        insightsConfig: {
          queryInsightsEnabled: true,
          queryStringLength: 4500,
          recordApplicationTags: true,
        },
      },

      lifecycle: {
        ignoreChanges: [],
      },
    })

    new SqlDatabase(this, 'name-db', {
      project: googleProject.id,
      instance: dbInstance.name,
      name: 'name-db',
    })

    new SqlUser(this, 'name-db-user', {
      project: googleProject.id,
      instance: dbInstance.name,
      name: 'name-db-user',
      password: new password.Password(this, 'name-db-user-password', {
        length: 16,
      }).result,
      host: '%',
    })

    // lets do the service api
    // 1. service account
    // 2. iam to cloudsql
  }
}

const app = new App()
new MyStack(app, 'name-app-dev')
app.synth()

Versions

language: typescript
cdktf-cli: 0.20.8
node: v20.16.0
cdktf: 0.20.8
constructs: 10.3.0
jsii: null
terraform: 1.9.5
arch: arm64
os: darwin 23.5.0
providers
random@undefined (LOCAL)
terraform provider version: 3.6.2
@cdktf/provider-google (PREBUILT)
terraform provider version: 5.43.1
prebuilt provider version: 13.32.1
cdktf version: ^0.20.0
@cdktf/provider-kubernetes (PREBUILT)
terraform provider version: 2.32.0
prebuilt provider version: 11.7.0
cdktf version: ^0.20.0
cdktf debug 14.17s user 1.98s system 178% cpu 9.070 total

Providers

──────────────────────────┬──────┬─────────┬─────────────────────┬─────────────┐
──          ───            ──     ──        ──────                ───
 Provider    Provider     │ CDKTF│         │ Package Name        │ Package     │
Name        Version               Constraint                      Version

──────────────────────────┼──────┼─────────┼─────────────────────┼─────────────┤
──          ───            ──     ──        ──────                ───
 random      3.6.2        │      │         │                     │             │

──────────────────────────┼──────┼─────────┼─────────────────────┼─────────────┤
──          ───            ──     ──        ──────                ───
 google      5.43.1       │      │         │                     │ 13.32.1     │
                           ^0.20.0          @cdktf/provider-google

──────────────────────────┼──────┼─────────┼─────────────────────┼─────────────┤
──          ───            ──     ──        ──────                ───
 kubernetes  2.32.0       │      │         │ @cdktf/provider-kube│ 11.7.0      │
                           ^0.20.0          netes

──────────────────────────┴──────┴─────────┴─────────────────────┴─────────────┘
──          ───            ──     ──        ──────                ───

Gist

https://gist.github.com/eduardosanzb/a85bba69ef2eb4067ac079a07d8b45db

Possible Solutions

No response

Workarounds

No response

Anything Else?

No response

References

No response

Help Wanted

  • I'm interested in contributing a fix myself

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@eduardosanzb eduardosanzb added bug Something isn't working new Un-triaged issue pre-built providers Issues around pre-built providers managed at https://github.com/hashicorp/cdktf-repository-manager labels Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working new Un-triaged issue pre-built providers Issues around pre-built providers managed at https://github.com/hashicorp/cdktf-repository-manager
Projects
None yet
Development

No branches or pull requests

1 participant