Skip to content
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

feat: add datasource for AWS Lambda Layers #19081

Conversation

kayman-mk
Copy link

@kayman-mk kayman-mk commented Nov 24, 2022

Changes

This PR adds a new datasource to update the versioned layer arns for AWS Lambda Layers.

Context

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please tick one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

@kayman-mk kayman-mk changed the title Kayma/add aws versioned arn datasource feat: add datasource for versioned AWS ARNs Nov 24, 2022
@JamieMagee JamieMagee marked this pull request as ready for review November 30, 2022 06:39
@JamieMagee JamieMagee marked this pull request as draft November 30, 2022 06:41
@kayman-mk
Copy link
Author

@HonkingGoose Thanks for your review. I committed your change.

I still have two questions which I can't answer. How does Renovate know what to put into the serializedArnFilter of my datasource (how to get the runtime, architecture and depName from the code into my function)? And how does Renovate know, which part of my string has to be updated? I simply do not understand how it works.

Could you please clarify?

locals {
  # renovate: datasource=aws-versioned-arn architecture=x86_64 runtime=python37
  insight_layer_arn = "arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:21"
}

resource "aws_lambda_function" "example" {
  # ... other configuration ...

  layers = [local.insight_layer_arn]
}
{
  "regexManagers": [
    {
      "fileMatch": ["\\.tf$"],
      "matchStrings": [
        ".*renovate: datasource=aws-versioned-arn architecture=(?<architecture>.*) runtime=(?<runtime>.*)\\s+.* = \"(?<depName>.*):(?<currentValue>\\d+)\""
      ],
      "versioningTemplate": "loose"
    }
  ]
}
 async getReleases({
    packageName: serializedArnFilter,
  }: GetReleasesConfig): Promise<ReleaseResult | null> {
    const lambdaLayerVersions = await this.getSortedLambdaLayerVersions(
      serializedArnFilter
    );
}

@HonkingGoose
Copy link
Collaborator

I'll let the maintainers answer your questions. 😉

@kayman-mk
Copy link
Author

@JamieMagee Could you step in please?

@kayman-mk kayman-mk changed the title feat: add datasource for versioned AWS ARNs feat: add datasource for AWS Lambda Layers Jan 14, 2023
@kayman-mk
Copy link
Author

kayman-mk commented Jan 15, 2023

@viceice I am almost satisfied with the results here. The only problem I have is, that Renovate tries to update the dependency name as well. Let's say the newest version of my lambda is 3 and I have the following file:

locals {
  # renovate: datasource=aws-lambda-layer filter={"name": "my-layer", "architecture": "x86_64", "runtime": "python3.7"}
  my_layer_arn = "arn:aws:lambda:us-east-1:223456789022:layer:my-layer:1"
}

After Renovate ran on my repository, I see the following change: my_layer_arn = "arn:aws:lambda:us-east-3:223456789022:layer:my-layer:3". As you can see, the version number was updated (after the last colon) but us-east-1 was changed to us-east-3. Seems that the RegEx manager replaces every 1 by a 3.

I tried to find some docs explaining the logic here, but didn't found any. Could you shed some light on this, please?

@JamieMagee
Copy link
Contributor

What's your renovate config for that upgrade? It looks like it's finding it somewhere in auto-replace, but you'd need to debug through to see exactly where.

@kayman-mk
Copy link
Author

I am developing with VSCode using the devcontainer option. I followed the steps in the local_development and exported my AWS credentials and the Renovate token. No other special configuration set.

I started renovate with LOG_LEVEL=debug yarn start kayman-mk/renovate-test within this feature branch. The only file I added was .nvmrc as described in the docs.

@protoz
Copy link

protoz commented Feb 24, 2023

Not to derail the current design according to the readme using a specific local variable, but it may be good to support the aws provider's data source aws_lambda_layer_version.

data "aws_lambda_layer_version" "datadog_extension" {
  layer_name = "arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Extension"
  version = 37
}

By specifying aws_lambda_layer_version.datadog_extension.arn it will append the version appropriately as arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Extension:37 in this case. That may simplify the regex issues you are having.

@rarkins rarkins closed this Jun 18, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 19, 2023
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants