Tuesday, June 07, 2022

terraform import: module + for_each

very useful info!

Terraform Imports: Resources, Modules, for_each, and Count | by Tyler DeKnecht | The Startup | Medium

"child" module


variable "user_name" {}

resource "aws_iam_user" "user" {
  for_each = toset(var.user_name) # receiving var values list
  name = each.value # "iterator", creating iam users from list 
  # ...

"parent" block, "calling" child module medium_demo.tf


module "iam" {
  source = "../modules/iam/medium_demo" 
  user_name = ["bill"] # defines list of values passed to module
  # ...

Here is the actual import command; notice escaped double quote \" that is required.
Final "bill" is AWS IAM ID of resource being imported, in this case username

> terraform import module.iam.aws_iam_user.user[\"bill\"] bill

GoLang blockchain service, by William Kennedy

ardanlabs/blockchain @GitHub by William Kennedy

Blockchain In Go: Part I: Digital Accounts, Signatures and Verification

Blockchain In Go: Part II: Transaction Distribution and Synchronization

Blockchain In Go: Part III: Redundant Storage And Consensus

Blockchain In Go: Part IV: Fraud Detection