GithubHelp home page GithubHelp logo

druids / terraform-aws-asg-instance-refresh Goto Github PK

View Code? Open in Web Editor NEW
8.0 4.0 2.0 56 KB

Terraform module providing a simple AWS Lambda function to update Launch Template for Auto Scaling Group to use the latest AMI stored in SSM Parameter.

License: MIT License

Python 47.00% HCL 53.00%
aws aws-lambda aws-autoscaling-instance-refresh terraform-module terraform-aws python hacktoberfest aws-autoscaling aws-autoscaling-group devops-tools

terraform-aws-asg-instance-refresh's Introduction

Requirements

Name Version
terraform >= 0.13
aws >= 3.0

Providers

Name Version
aws >= 3.0

Modules

No modules.

Resources

Name Type
aws_cloudwatch_event_rule.rule resource
aws_cloudwatch_event_target.refresh_lambda resource
aws_iam_role.lambda resource
aws_iam_role_policy.lambda resource
aws_lambda_function.refresh resource
aws_lambda_permission.allow_cloudwatch_events resource
aws_autoscaling_group.group data source
aws_caller_identity.current data source
aws_iam_policy_document.assume_role data source
aws_iam_policy_document.lambda data source
aws_lambda_layer_version.sentry data source
aws_region.current data source

Inputs

Name Description Type Default Required
ami_ssm_parameter Name of SSM parameter containing the current AMI string "/aws/service/ecs/optimized-ami/amazon-linux-2/recommended" no
ami_ssm_parameter_arm Name of SSM parameter containing the current AMI (ARM) string "/aws/service/ecs/optimized-ami/amazon-linux-2/arm64/recommended" no
auto_scaling_group_is_arm_default Set to true if your ASG uses ARM instances in the default launch template string false no
autoscaling_group_name Name of the auto scaling group to refresh string n/a yes
cloudwatch_event_rule_name Name of the CloudWatch Event Rule string "ASGRefreshInstancesEventRule" no
cloudwatch_event_rule_schedule_expression Schedule expression for CloudWatch Event Rule string "cron(0 0 * * ? *)" no
describe_instance_refreshes_max_records Page size for boto3 when calling autoscaling:DescribeInstanceRefreshes (max is 100) number 100 no
instance_refresh_instance_warmup Instance warmup time for instance refresh number 300 no
instance_refresh_min_healthy_percentage Minimum healthy percentage for instance refresh number 90 no
instance_refresh_skip_matching Skip matching instances for instance refresh bool false no
lambda_architecture Set CPU architecture for the Lambda function. Valid values are "x86_64" and "arm64". string "x86_64" no
lambda_description Description of the Lambda function string "Keeps ASG Launch Template updated with most recent AMI read from SSM Parameter" no
lambda_name Name of the Lambda function string "ASGRefreshInstances" no
lambda_role_description Role description for the Lambda function string "" no
lambda_role_name Role name for the Lambda function string "ASGRefreshInstancesLambdaRole" no
lambda_timeout Timeout for Lambda function in seconds number 60 no
launch_template_source_version Source version for the new launch template string "$Default" no
launch_template_version_description Description of the new launch template version in Python's f-string format string "Automated AMI refresh to \"{image_id}\"" no
launch_templates_arns List of Launch Template ARNs to allow access to list(string)
[
"*"
]
no
sentry_dsn n/a string null no
sentry_environment n/a string null no
sentry_lambda_layer_version n/a number 11 no
update_mixed_instances_policy_overriden_launch_templates If you do not want to also update launch templates that override the default launch template, set this to false bool true no

Outputs

Name Description
asg_arn n/a

terraform-aws-asg-instance-refresh's People

Contributors

baptiste-s avatar radimsuckr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

terraform-aws-asg-instance-refresh's Issues

Lambda failing

Hi,

I use the module as is but I am getting error from the lambda:

{
  "errorMessage": "Expecting value: line 1 column 1 (char 0)",
  "errorType": "JSONDecodeError",
  "stackTrace": [
    "  File \"/var/task/lambda.py\", line 179, in handler\n    return main()\n",
    "  File \"/var/task/lambda.py\", line 156, in main\n    image_id = get_current_image_id()\n",
    "  File \"/var/task/lambda.py\", line 57, in get_current_image_id\n    param_value = json.loads(param['Parameter']['Value'])\n",
    "  File \"/var/lang/lib/python3.8/json/__init__.py\", line 357, in loads\n    return _default_decoder.decode(s)\n",
    "  File \"/var/lang/lib/python3.8/json/decoder.py\", line 337, in decode\n    obj, end = self.raw_decode(s, idx=_w(s, 0).end())\n",
    "  File \"/var/lang/lib/python3.8/json/decoder.py\", line 355, in raw_decode\n    raise JSONDecodeError(\"Expecting value\", s, err.value) from None\n"
  ]
}

looks like it cannot get the imageId from the json for some reason :
param_value = json.loads(param['Parameter']['Value'])

here is my tf code :

module "asg-instance-refresh" {
  source                 = "radimsuckr/asg-instance-refresh/aws"
  version                = "0.2.0"
  autoscaling_group_name = aws_autoscaling_group.BastionInstance.name
  launch_template_name   = aws_launch_template.BastionInstance.name
  ami_ssm_parameter      = "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2"
}

thx for helping :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.