Skip to content

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

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

Closed
michaelbrewer opened this issue Mar 8, 2022 · 4 comments
Closed

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

michaelbrewer opened this issue Mar 8, 2022 · 4 comments
Labels
documentation Improvements or additions to documentation

Comments

@michaelbrewer
Copy link
Contributor

michaelbrewer commented Mar 8, 2022

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
@michaelbrewer michaelbrewer added bug Something isn't working triage Pending triage from maintainers labels Mar 8, 2022
@michaelbrewer
Copy link
Contributor Author

Created a pull request which fixes this bug in the docs.

@michaelbrewer michaelbrewer changed the title docs(intro): terraform example is invalid fix(intro): terraform example is invalid Apr 8, 2022
@heitorlessa heitorlessa added documentation Improvements or additions to documentation and removed bug Something isn't working labels Apr 12, 2022
@heitorlessa
Copy link
Contributor

Fixing the labels (documentation, over bug).

michaelbrewer added a commit to gyft/aws-lambda-powertools-python that referenced this issue Apr 12, 2022
Changes:
- Extract all code examples
- Fix yaml, terraform and python
- Add make file to format, lint and validate examples

Related to
- aws-powertools#1064

Fixed
- aws-powertools#1067
- aws-powertools#1069
@michaelbrewer
Copy link
Contributor Author

A fix for is documentation bug is at #1113 which resolved when you try to use the provided example

@michaelbrewer michaelbrewer changed the title fix(intro): terraform example is invalid Bug: terraform example has a syntax error May 17, 2022
@michaelbrewer michaelbrewer changed the title Bug: terraform example has a syntax error Bug: HomePage, terraform example has a syntax error May 18, 2022
@michaelbrewer michaelbrewer changed the title Bug: HomePage, terraform example has a syntax error Bug: HomePage - terraform example has a syntax error May 18, 2022
@sthulb sthulb changed the title Bug: HomePage - terraform example has a syntax error Docs: HomePage - terraform example has a syntax error May 18, 2022
@sthulb sthulb closed this as completed Jun 14, 2022
@github-actions
Copy link
Contributor

Comments on closed issues are hard for our team to see.

@heitorlessa heitorlessa removed the triage Pending triage from maintainers label Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants