Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use JFrog Artifactory as Terraform Data Source

I'm desiring to pull a jar file from JFrog artifactory and use it as the source to deploy to an AWS Lambda function using Terraform. I am currently doing this by pulling from an S3 bucket using the code below:

data "aws_s3_bucket_object" "function-lambda-file-hash" {
  bucket = "<MYBUCKET>
  key    = "<MYKEY.sha1>"

  tags {
    Name = "${var.<MYTAG>}"
  }
}

# Create the Lambda function itself
resource "aws_lambda_function" "function-lambda" {
  function_name = "function-lambda"

  handler = "com.example.MyFunction::handleRequest"
  runtime = "java8"
  s3_bucket="<MYBUCKET>"
  s3_key="<MYKEY.jar>"
  source_code_hash = "${data.aws_s3_bucket_object.function-lambda-file-hash.body}"
  role = "${aws_iam_role.function-lambda-exec-role.arn}"
  timeout = 30
  memory_size = 256

  tags {
    Name = "${var.<MYTAG>}"
  }
}

I would like to do something identical but pulling from Artifactory, an instance that requires authentication (which it appears that the HTTP module cannot do), instead but have not been able to find any information regarding doing this. Does anyone know if this is possible? And if so, how?

Any help would be appreciated.

Thanks,

Chris

like image 836
Chris Slack Avatar asked Apr 30 '18 13:04

Chris Slack


People also ask

Is JFrog Artifactory open source?

JFrog Artifactory Open Source is a repository manager designed to store internally-created and third-party binary artifacts in a centralized location. It works as a version control system for binaries allowing developers to create their solutions using the same set of binaries.

What is JFrog Artifactory used for?

JFrog Artifactory is a universal DevOps solution providing end-to-end automation and management of binaries and artifacts through the application delivery process that improves productivity across your development ecosystem.

Is JFrog the same as Artifactory?

JFrog's Artifactory is a universal artifact repository manager that supports all major package formats (20+ languages including Go and Helm). It's also integrated with all major build tools and CI servers currently available.


1 Answers

Use the data source artifactory_file to get the sha256, then base64 encode it, and pass it to the aws_lambda_function resource.

# Configure the Artifactory provider
provider "artifactory" {
  url      = "${var.artifactory_url}/artifactory"
  username = var.artifactory_username
  password = var.artifactory_password
}

data "artifactory_file" "jar" {
   repository  = "repo-key"
   path        = "/path/to/the/artifact.jar"
   output_path = "artifact.jar"
}

resource "aws_lambda_function" "function-lambda" {
  function_name = "function-lambda"

  source_code_hash = filebase64sha256(data.artifactory_file.jar)

  # ...
}
like image 58
SomeGuyOnAComputer Avatar answered Sep 19 '22 15:09

SomeGuyOnAComputer