diff --git a/modules/forwarder/README.md b/modules/forwarder/README.md
index 6f037c3..bf759d2 100644
--- a/modules/forwarder/README.md
+++ b/modules/forwarder/README.md
@@ -71,7 +71,7 @@ module "forwarder" {
| Name | Source | Version |
|------|--------|---------|
-| [samversion](#module\_samversion) | ../samversion | n/a |
+| [sam\_asset](#module\_sam\_asset) | ../sam_asset | n/a |
## Resources
diff --git a/modules/forwarder/main.tf b/modules/forwarder/main.tf
index f09ce3d..cbab9f8 100644
--- a/modules/forwarder/main.tf
+++ b/modules/forwarder/main.tf
@@ -1,5 +1,5 @@
locals {
- code_uri = var.code_uri != "" ? var.code_uri : module.samversion[0].code_uri
+ code_uri = var.code_uri != "" ? var.code_uri : yamldecode(module.sam_asset[0].body)["Resources"]["Forwarder"]["Properties"]["CodeUri"]
parsed_s3_uri = regex("s3://(?P[^/]+)/(?P.+)", local.code_uri)
destination_uri = var.destination.uri != "" ? var.destination.uri : "s3://${var.destination.bucket}/${var.destination.prefix}"
name_prefix = "${substr(var.name, 0, 37)}-"
@@ -21,10 +21,9 @@ data "aws_region" "current" {}
data "aws_partition" "current" {}
-module "samversion" {
- count = var.code_uri != "" ? 0 : 1
- source = "../samversion"
- app = "forwarder"
- function = "Forwarder"
- release = var.sam_release_version
+module "sam_asset" {
+ count = var.code_uri != "" ? 0 : 1
+ source = "../sam_asset"
+ asset = "forwarder.yaml"
+ release_version = var.sam_release_version
}
diff --git a/modules/sam_asset/README.md b/modules/sam_asset/README.md
new file mode 100644
index 0000000..c4cd95d
--- /dev/null
+++ b/modules/sam_asset/README.md
@@ -0,0 +1,18 @@
+# SAM Asset
+
+This is a helper module to retrieve objects for a given release version from
+https://github.com/observeinc/aws-sam-apps.
+
+If no `release_version` is provided, we will default to a hard-coded value
+which is maintained up to date by `updatecli`. This ensures that a given
+terraform module release produces the same behavior across time.
+
+## Usage
+
+```hcl
+module "sam_asset" {
+ source = "observeinc/collection/aws//modules/sam_asset"
+ asset = "forwarder.yaml"
+ release_version = "1.19.3"
+}
+```
diff --git a/modules/samversion/main.tf b/modules/sam_asset/main.tf
similarity index 50%
rename from modules/samversion/main.tf
rename to modules/sam_asset/main.tf
index eda5463..9261767 100644
--- a/modules/samversion/main.tf
+++ b/modules/sam_asset/main.tf
@@ -1,13 +1,12 @@
locals {
- latest_release = "1.19.3"
- sam_release_version = var.release != "" ? var.release : local.latest_release
- code_uri = yamldecode(data.http.manifest.response_body)["Resources"][var.function]["Properties"]["CodeUri"]
+ latest_release = "1.19.3"
+ release_version = var.release_version != "" ? var.release_version : local.latest_release
}
data "aws_region" "current" {}
data "http" "manifest" {
- url = "https://observeinc-${data.aws_region.current.name}.s3.amazonaws.com/aws-sam-apps/${local.sam_release_version}/${var.app}.yaml"
+ url = "https://observeinc-${data.aws_region.current.name}.s3.amazonaws.com/aws-sam-apps/${local.release_version}/${var.asset}"
lifecycle {
postcondition {
diff --git a/modules/sam_asset/outputs.tf b/modules/sam_asset/outputs.tf
new file mode 100644
index 0000000..0b28946
--- /dev/null
+++ b/modules/sam_asset/outputs.tf
@@ -0,0 +1,4 @@
+output "body" {
+ description = "Response body"
+ value = data.http.manifest.response_body
+}
diff --git a/modules/samversion/variables.tf b/modules/sam_asset/variables.tf
similarity index 50%
rename from modules/samversion/variables.tf
rename to modules/sam_asset/variables.tf
index e744a9b..0a24043 100644
--- a/modules/samversion/variables.tf
+++ b/modules/sam_asset/variables.tf
@@ -1,17 +1,13 @@
-variable "app" {
- description = "App name"
+variable "asset" {
+ description = <<-EOF
+ Asset key. This value is appended to the SAM apps version prefix to form
+ the object key.
+ EOF
type = string
nullable = false
}
-variable "function" {
- description = "Function name"
- type = string
- default = ""
- nullable = false
-}
-
-variable "release" {
+variable "release_version" {
description = "Release version on github.com/observeinc/aws-sam-apps."
type = string
default = ""
diff --git a/modules/samversion/versions.tf b/modules/sam_asset/versions.tf
similarity index 100%
rename from modules/samversion/versions.tf
rename to modules/sam_asset/versions.tf
diff --git a/modules/samversion/README.md b/modules/samversion/README.md
deleted file mode 100644
index 4c31d42..0000000
--- a/modules/samversion/README.md
+++ /dev/null
@@ -1,15 +0,0 @@
-# SAM Version
-
-This is a helper module that given a SAM App name and Lambda function resource ID returns the code URI.
-
-## Usage
-
-```hcl
-module "samversion" {
- app = "forwarder"
- function = "Forwarder"
- release = "1.19.3"
-}
-```
-
-If `release` is omitted, we will default to a value that is updated by `updatecli`.
diff --git a/modules/samversion/outputs.tf b/modules/samversion/outputs.tf
deleted file mode 100644
index 1d29f11..0000000
--- a/modules/samversion/outputs.tf
+++ /dev/null
@@ -1,4 +0,0 @@
-output "code_uri" {
- description = "Code URI for binary."
- value = local.code_uri
-}
diff --git a/modules/subscriber/README.md b/modules/subscriber/README.md
index 36ed2f1..959df65 100644
--- a/modules/subscriber/README.md
+++ b/modules/subscriber/README.md
@@ -21,7 +21,7 @@ This app is specifically to register new cloudwatch log groups for the `logwrite
| Name | Source | Version |
|------|--------|---------|
-| [samversion](#module\_samversion) | ../samversion | n/a |
+| [sam\_asset](#module\_sam\_asset) | ../sam_asset | n/a |
## Resources
diff --git a/modules/subscriber/main.tf b/modules/subscriber/main.tf
index 1a0b16b..b0b5dd6 100644
--- a/modules/subscriber/main.tf
+++ b/modules/subscriber/main.tf
@@ -2,14 +2,13 @@ locals {
has_discovery_rate = var.discovery_rate != ""
name_prefix = "${substr(var.name, 0, 37)}-"
- code_uri = var.code_uri != "" ? var.code_uri : module.samversion[0].code_uri
+ code_uri = var.code_uri != "" ? var.code_uri : yamldecode(module.sam_asset[0].body)["Resources"]["Subscriber"]["Properties"]["CodeUri"]
parsed_s3_uri = regex("s3://(?P[^/]+)/(?P.+)", local.code_uri)
}
-module "samversion" {
- count = var.code_uri != "" ? 0 : 1
- source = "../samversion"
- app = "logwriter"
- function = "Subscriber"
- release = var.sam_release_version
+module "sam_asset" {
+ count = var.code_uri != "" ? 0 : 1
+ source = "../sam_asset"
+ asset = "logwriter.yaml"
+ release_version = var.sam_release_version
}