Sending input variables to a terraform module sourced from S3

HI folks,

I ran into a problem when I try to source a terraform module from S3. I have a module api_module that takes a couple of input variables (name, environment) from the caller. I did a zip of this module code and uploaded to S3, so that I can source it from S3 wherever I would like to.

When I source this module into another program from S3, terraform is not accepting setting any input variables. The same program accepts input variables if I source the module from a git repo.

Here is the sample code that I am talking about:

{
source = “s3::http://s3.amazonaws.com/module_bucket/api_module.zip
name = “api_name”
environment = “tst”
}

terraform returns error while running plan stating that the input variables name and environment are not accepted.

The same code works good if I source the module from a git repo:

module “my_module” {
source = “git::ssh://git@wwwin-github.com/api_module.git”
name = “api_name”
environment = “tst”
}

need some help on sending these input parameters to the module getting sourced from S3.

Is the module downloaded? Does it show up in .terraform as unzipped version?

Sometimes error messages can be misleading, not reporting what’s actually wrong

How does the zipfile look, myabe there’s a folder layer too much? Ie when you clone api_module.git it contains variables.tf in the api_module folder but the zip-file should contain variables.tf and not api_module/variables.tf

Hello,

Thanks a lot for the quick reply. The module got download and showing up in “.terraform/modules/my_module/api_module/*”. The api_module contains
main.tf , variables.tf and outputs.tf.

There is no error while doing “terraform init”. The module is getting downloaded as above. When I run “terraform plan”, the terraform plan is stating the input variables as unsupported arguments.

Let me elaborate this little more. Initially I had the code pulling this module from “git” repo. I ran terraform plan and apply on it. This has created a resource of following name “tst_api_name_log_report” (<var.environment>_<var.name>_log_report). Now I converted the sourcing from “git” to “s3”. When I run terraform plan , terraform throwing an error stating that the input variables as “unsupported arguments”.

terraform plan

Error: Unsupported argument

on my_program.tf line 10, in module “my_Module”:
10: name = “ap_name”

An argument named “name” is not expected here.

Error: Unsupported argument

on my_program.tf line 11, in module “my_module”:
11: environment = “test”

An argument named “environment” is not expected here.

I made sure to delete the .terraform folder before each run so that the modules are downloaded as from the source. I don’t see any difference in the downloaded modules content in both cases. It is same for both git and s3 way of sourcing the module.

Pls let me know if you want to check any outputs. For the module zip file, I have created a new bucket “module_bucket” and placed the “api_module.zip” file containing the 3 files.

Thanks much
-Veera

Hi bent,
You are correct. I just overlooked the directory path. I have an extra layer when I source the module from s3. That extra layer is causing the issue.

The downloaded module looks as below,
From git
.terraform/modules/my_module/*tf

From S3
.terraform/module/my_module/api_module/*tf

I have changed my s3 archieve to zip only the files and things are working good now.

Thanks a lot for your help.

  • Veera
1 Like