0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 13:38:32 +00:00
renovatebot_renovate/lib/modules/datasource/aws-machine-image
2024-08-19 13:15:27 +00:00
..
__snapshots__ build(deps): update aws-sdk-js-v3 monorepo (#28644) 2024-04-25 12:59:19 +00:00
index.spec.ts chore: eslint to enforce for typed imports (#30844) 2024-08-19 13:15:27 +00:00
index.ts chore: eslint to enforce for typed imports (#30844) 2024-08-19 13:15:27 +00:00
readme.md feat(migrate): regexManagers -> customManagers (#24451) 2023-09-24 08:55:56 +00:00
types.ts feat(datasource/aws-machine-image): Add profile and region configuration support (#24086) 2023-08-29 09:24:49 +00:00

!!! warning This datasource is experimental. Its syntax and behavior may change at any time!

This datasource returns the latest Amazon Machine Image via the AWS API.

Because the datasource uses the AWS-SDK for JavaScript, you can configure it like other AWS Tools. You can use common AWS configuration options, for example (partial list):

  • Setting the region via AWS_REGION (environment variable) or your ~/.aws/config file
  • Provide credentials via AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY (environment variable) or your ~/.aws/credentials file
  • Select the profile to use via AWS_PROFILE environment variable

Read the Developer guide for more information on configuration options.

The least IAM privileges required for this datasource are:

{
  "Sid": "AllowEc2ImageLookup",
  "Effect": "Allow",
  "Action": ["ec2:DescribeImages"],
  "Resource": "*"
}

Read the AWS IAM Reference for more information.

Because there is no general packageName, you have to use the describe images filter as minified JSON as a packageName.

Example:

# Getting the latest official EKS image from AWS (account '602401143452' for eu-central-1) for EKS 1.21 (name matches 'amazon-eks-node-1.21-*') would look as a describe images filter like:

[
  {
    "Name": "owner-id",
    "Values": [ "602401143452" ]
  },
  {
    "Name": "name",
    "Values": [ "amazon-eks-node-1.21-*" ]
  }
]

# In order to use it with this datasource, you have to minify it:

[{"Name":"owner-id","Values":["602401143452"]},{"Name":"name","Values":["amazon-eks-node-1.21-*"]}]

At the moment, this datasource has no "manager". You have to use the custom manager for this.

Usage Example

Here's an example of using the custom manager:

module.exports = {
  customManagers: [
    {
      customType: 'regex',
      fileMatch: ['.*'],
      matchStrings: [
        '.*amiFilter=(?<packageName>.*?)\n(.*currentImageName=(?<currentDigest>.*?)\n)?(.*\n)?.*?(?<depName>[a-zA-Z0-9-_:]*)[ ]*?[:|=][ ]*?["|\']?(?<currentValue>ami-[a-z0-9]{17})["|\']?.*',
      ],
      datasourceTemplate: 'aws-machine-image',
      versioningTemplate: 'aws-machine-image',
    },
  ],
};

Or as JSON:

{
  'customManagers':
    [
      {
        'customType': 'regex',
        'fileMatch': ['.*'],
        'matchStrings':
          [
            ".*amiFilter=(?<packageName>.*?)\n(.*currentImageName=(?<currentDigest>.*?)\n)?(.*\n)?.*?(?<depName>[a-zA-Z0-9-_:]*)[ ]*?[:|=][ ]*?[\"|']?(?<currentValue>ami-[a-z0-9]{17})[\"|']?.*",
          ],
        'datasourceTemplate': 'aws-machine-image',
        'versioningTemplate': 'aws-machine-image',
      },
    ],
}

This would match every file, and would recognize the following lines:

# With AMI name mentioned in the comments
# amiFilter=[{"Name":"owner-id","Values":["602401143452"]},{"Name":"name","Values":["amazon-eks-node-1.21-*"]}]
# currentImageName=unknown
my_ami1: ami-02ce3d9008cab69cb
# Only AMI, no name mentioned
# amiFilter=[{"Name":"owner-id","Values":["602401143452"]},{"Name":"name","Values":["amazon-eks-node-1.20-*"]}]
# currentImageName=unknown
my_ami2: ami-0083e9407e275acf2

# Using custom aws profile and region
# amiFilter=[{"Name":"owner-id","Values":["602401143452"]},{"Name":"name","Values":["amazon-eks-node-1.20-*"]},{"profile":"test","region":"eu-central-1"}]
# currentImageName=unknown
ami = "ami-0083e9407e275acf2"
const myConfigObject = {
  // With AMI name mentioned in the comments
  // amiFilter=[{"Name":"owner-id","Values":["602401143452"]},{"Name":"name","Values":["amazon-eks-node-1.21-*"]}]
  // currentImageName=unknown
  my_ami1: 'ami-02ce3d9008cab69cb',
};

/**
 * Only AMI, no AMI name mentioned
 * amiFilter=[{"Name":"owner-id","Values":["602401143452"]},{"Name":"name","Values":["amazon-eks-node-1.20-*"]}]
 * currentImageName=unknown
 */
const my_ami2 = 'ami-0083e9407e275acf2';
resource "aws_instance" "web" {

    # Only AMI, no name mentioned
    # amiFilter=[{"Name":"owner-id","Values":["602401143452"]},{"Name":"name","Values":["amazon-eks-node-1.20-*"]}]
    # currentImageName=unknown
    ami = "ami-0083e9407e275acf2"

    count = 2
    source_dest_check = false

    connection {
        user = "root"
    }
}