Skip to content

Commit

Permalink
version upgrades for terraform aws and lambda python runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethjmyers committed Apr 13, 2024
1 parent f02a0ae commit fcf5e45
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Python
uses: actions/[email protected]
with:
python-version: '3.7'
python-version: '3.12'

- name: Install requirements
run: pip install -r requirements.txt
Expand Down
86 changes: 43 additions & 43 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ The purpose of this repo is to deploy AWS Lambda function that scrapes rising an

```sh
terraform init
terraform plan -var-file="dev.tfvars"
terraform apply -var-file="dev.tfvars"
terraform workspace new dev # this should switch you to the dev workspace
terraform plan -var-file="dev.tfvars" -out=dev-plan.out
terraform apply -var-file="dev.tfvars" dev-plan.out
```
If you don't want to apply the changes to your aws account then just run the `terraform plan` command to see what changes would be applied.

For deploying to prd

```sh
terraform workspace new prd # or terraform workspace select prd if already created
terraform plan -var-file="prd.tfvars" -out=prd-plan.out
terraform apply -var-file="prd.tfvars" prd-plan.out
```

On subsequent updates you don't need to `init` or make a new workspace again.
8 changes: 4 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.16"
version = "< 6.0"
}
}

Expand All @@ -18,7 +18,7 @@ variable "info" {
default = {
name = "viralredditposts"
region = "us-east-2"
pyversion = "3.7"
pyversion = "3.12"
}
}

Expand Down Expand Up @@ -139,7 +139,7 @@ data "aws_iam_policy_document" "inline_policy" {
# create role
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role
resource "aws_iam_role" "iam_for_lambda" {
name = "iam-for-lambda"
name = "iam-for-lambda-${var.env}"
assume_role_policy = data.aws_iam_policy_document.assume_role.json # Policy that grants an entity permission to assume the role.

inline_policy {
Expand Down Expand Up @@ -233,7 +233,7 @@ resource "aws_cloudwatch_event_rule" "every_one_minute" {
name = "every-one-minute"
description = "Fires every one minute"
schedule_expression = "rate(1 minute)"
is_enabled = var.enable_schedule
state=var.cloudwatch_state
}

resource "aws_cloudwatch_event_target" "scrape_reddit_every_minute" {
Expand Down
8 changes: 4 additions & 4 deletions variable.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ variable "env" {
description = "environment to deploy to"
}

variable "enable_schedule" {
type = bool
default = false
description = "whether or not the lambda function schedule is enabled or not"
variable "cloudwatch_state" {
type = string
default = "DISABLED"
description = "Whether or not the lambda function schedule is enabled or not. Valid values are DISABLED, ENABLED, and ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENT"
}

0 comments on commit fcf5e45

Please sign in to comment.