kagarlickij
kagarlickij

Reputation: 8107

Terraform multiple resources with the same monitoring settings

Multiple resources (S3, lambda, etc.) in AWS are created by different teams via Terraform scripts;

I’ve developed my Terraform scripts for CloudWatch monitoring, they require AWS ARN as input;

Is it possible to use my monitoring terraform scripts by each team without copying them to their repos?

Upvotes: 0

Views: 309

Answers (1)

rclement
rclement

Reputation: 1714

Yes you can let each team make use of your terraform scripts by creating them as a module. Then the teams can load them into their own scripts using the module configuration section If you do not use git, or you have all terraform in one repository, there are other ways to load a module

This is how we make and use a large number of modules to have a consistent setup across all teams. We have a git repository for each module like (module_cloudwatch_monitoring). There is nothing special about defining a module, you only need to have variables and outputs defined.

When a team wants to use that module, they can use the module syntax like:

module "cloudwatch_monitoring" {
   source = "git::http://your-git-repository-url.git?ref=latest"
   resource_arn = "${aws_s3_bucket.my_bucket.id}"
}

If the module was in a local path in the same repository, you could do something like:

module "cloudwatch_monitoring" {
   source = "../../modules/cloudwatch_monitoring"
   resource_arn = "${aws_s3_bucket.my_bucket.id}"
}

Upvotes: 1

Related Questions