Skip to content

Docs: HomePage - terraform example has a syntax error #1067

Closed
@michaelbrewer

Description

@michaelbrewer

What were you trying to accomplish?

Our company used terraform to provision most resources, and the example provides fails

Expected Behavior

Terraform init and tflint should work.

Current Behavior

Current template renders like this:

terraform {
  required_version = "~> 1.0.5"
  required_providers {
    aws = "~> 3.50.0"
  }
}

provider "aws" {
  region  = "{region}"
}

resource "aws_iam_role" "iam_for_lambda" {
  name = "iam_for_lambda"

  assume_role_policy = <<EOF
    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Action": "sts:AssumeRole",
          "Principal": {
            "Service": "lambda.amazonaws.com"
          },
          "Effect": "Allow"
        }
      ]
    }
    EOF
}

resource "aws_lambda_function" "test_lambda" {
  filename      = "lambda_function_payload.zip"
  function_name = "lambda_function_name"
  role          = aws_iam_role.iam_for_lambda.arn
  handler       = "index.test"
  runtime       = "python3.9"
  layers        = ["arn:aws:lambda:{region}:017000801446:layer:AWSLambdaPowertoolsPython:13"]

  source_code_hash = filebase64sha256("lambda_function_payload.zip")
}
    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Action": "sts:AssumeRole",
          "Principal": {
            "Service": "lambda.amazonaws.com"
          },
          "Effect": "Allow"
        }
      ]
    }
    EOF
}

resource "aws_lambda_function" "test_lambda" {
  filename      = "lambda_function_payload.zip"
  function_name = "lambda_function_name"
  role          = aws_iam_role.iam_for_lambda.arn
  handler       = "index.test"
  runtime       = "python3.9"
  layers        = ["arn:aws:lambda:{region}:017000801446:layer:AWSLambdaPowertoolsPython:13"]

  source_code_hash = filebase64sha256("lambda_function_payload.zip")
}

Both teraform init and tflint fails, even after replacing {region}

terraform init
tflint

producing the following error:

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: Argument or block definition required
│ 
│ On main.tf line 41: An argument or block definition is required here.
╵

Possible Solution

Update the supplied terraform example as part of PR #1113

terraform {
  required_version = "~> 1.1.7"
  required_providers {
    aws = "~> 4.4.0"
  }
}

provider "aws" {
  region = "{region}"
}

resource "aws_iam_role" "iam_for_lambda" {
  name = "iam_for_lambda"

  assume_role_policy = jsonencode({
    Version = "2012-10-17",
    Statement = [
      {
        Action = "sts:AssumeRole",
        Principal = {
          Service = "lambda.amazonaws.com"
        },
        Effect = "Allow"
      }
    ]
  })
}

resource "aws_lambda_function" "test_lambda" {
  filename      = "lambda_function_payload.zip"
  function_name = "lambda_function_name"
  role          = aws_iam_role.iam_for_lambda.arn
  handler       = "index.test"
  runtime       = "python3.9"
  layers        = ["arn:aws:lambda:{region}:017000801446:layer:AWSLambdaPowertoolsPython:13"]

  source_code_hash = filebase64sha256("lambda_function_payload.zip")
}

Steps to Reproduce (for bugs)

  1. Copy terraform example from https://awslabs.github.io/aws-lambda-powertools-python/latest/#lambda-layer
  2. run terraform init
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: Argument or block definition required
│ 
│ On main.tf line 41: An argument or block definition is required here.
╵

Environment

  • Powertools version used: current docs
  • Packaging format (Layers, PyPi):
  • AWS Lambda function runtime:
  • Debugging logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions