kotless icon indicating copy to clipboard operation
kotless copied to clipboard

deploy task. error: "A name must start with a letter or underscore and may contain only letters"

Open icehockeystar opened this issue 4 years ago • 1 comments

I have following build.gradle.kts

import io.kotless.plugin.gradle.dsl.kotless
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("jvm") version "1.3.72"
    id("io.kotless") version "0.1.7-beta-4" apply true
}
group = "org.rtu"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
    jcenter()
}
dependencies {
    implementation("io.kotless", "kotless-lang", "0.1.7-beta-4")
    testImplementation(kotlin("test-junit5"))
}

kotless {
    config {
        bucket = "kotless-example-bucket1"
        prefix = "dev"

        terraform {
            profile = "default"
            region = "eu-central-1"
        }
    }

    webapp {
        lambda {
            memoryMb = 1024
            timeoutSec = 120
        }
    }
}

tasks.withType<KotlinCompile>() {
    kotlinOptions.jvmTarget = "11"
}

and following lambda:

@Get("/")
fun root(): String {
    return "root"
}

when I run ./gradlew deploy I get following teraform errors:

./gradlew deploy
There are some problems with the configuration, described below.

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.

Error: Invalid resource name

  on kotless-sample.tf line 51, in resource "aws_iam_role" "1161586659":
  51: resource "aws_iam_role" "1161586659" {

A name must start with a letter or underscore and may contain only letters,
digits, underscores, and dashes.


Error: Missing newline after argument

  on kotless-sample.tf line 53, in resource "aws_iam_role" "1161586659":
  53:   assume_role_policy = data.aws_iam_policy_document.1161586659_assume.json

An argument definition must end with a newline.


Error: Invalid resource name

  on kotless-sample.tf line 61, in resource "aws_iam_role_policy" "1161586659":
  61: resource "aws_iam_role_policy" "1161586659" {

A name must start with a letter or underscore and may contain only letters,
digits, underscores, and dashes.


Error: Invalid resource name

  on kotless-sample.tf line 71, in resource "aws_lambda_function" "1161586659":
  71: resource "aws_lambda_function" "1161586659" {

A name must start with a letter or underscore and may contain only letters,
digits, underscores, and dashes.


Error: Invalid resource name

icehockeystar avatar Nov 21 '20 21:11 icehockeystar

After some investigations I realized that it happens when you have only one lambda function in your code. This not allowed id=1161586659 is generated and set within terraform configs.

icehockeystar avatar Nov 22 '20 19:11 icehockeystar