Create multiple resources terraformTerraform forcing new resources on every applyWhy Terraform is updating volume attachment resources?How to create temporary one-off terraform resources?can I use same state file in terraform for multiple terraform filesDeploying to multiple accounts with Terraform?Terraform multiple environments on awsTerraform - how to use multiple modules to create temporary ressourcesCreate TPU instance using TerraformUnable to create Kubernetes resources with terraform
How can I find where certain bash function is defined?
Why are C64 games inconsistent with which joystick port they use?
Does linking adjectives allow you to talk about multiple variations of something?
Looking for a soft substance that doesn't dissolve underwater
Does revoking a certificate result in revocation of its key?
Is CD audio quality good enough for the final delivery of music?
Rename photos to match video titles
What are these arcade games in Ghostbusters 1984?
Identify this in soil?
Can a wire having 610-670 THz (frequency of blue light) A.C frequency supply, generate blue light?
Why do airplanes use an axial flow jet engine instead of a more compact centrifugal jet engine?
What is the most important source of natural gas? coal, oil or other?
What is the object moving across the ceiling in this stock footage?
How many chess players are over 2500 Elo?
How can I get exact maximal value of this expression?
Would jet fuel for an F-16 or F-35 be producible during WW2?
Canon 70D often overexposing or underexposing shots
Why does the 'metric Lagrangian' approach appear to fail in Newtonian mechanics?
What does the view outside my ship traveling at light speed look like?
Python program to convert a 24 hour format to 12 hour format
analysis of BJT PNP type - why they can use voltage divider?
Is there a way to make it so the cursor is included when I prtscr key?
Is there a public standard for 8 and 10 character grid locators?
How can people dance around bonfires on Lag Lo'Omer - it's darchei emori?
Create multiple resources terraform
Terraform forcing new resources on every applyWhy Terraform is updating volume attachment resources?How to create temporary one-off terraform resources?can I use same state file in terraform for multiple terraform filesDeploying to multiple accounts with Terraform?Terraform multiple environments on awsTerraform - how to use multiple modules to create temporary ressourcesCreate TPU instance using TerraformUnable to create Kubernetes resources with terraform
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
First time asking a question so if I've left anything important out let me know!
Terraform v0.11.1
provider.aws v0.1.4
I'm trying to create multiple cloudwatch alarms for multiple instances. I was wondering if there was a way to have the config iterating though a list. I have tried using the following code, but I get "Error: variable "instances": default may not contain interpolations".
variable "instances"
description = "Run the EC2 Instances in these Availability Zones"
type = "list"
default = ["$aws_instance.my_instance1.id", "$aws_instance.my_instance2.id", "$aws_instance.my_instance3.id", "$aws_instance.my_instance4.id", "$aws_instance.my_instance5.id"]
############ Cloudwatch monitoring
resource "aws_cloudwatch_metric_alarm" "cpu"
count = 5
alarm_name = "terraform-cpu-high-test"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "180"
statistic = "Average"
threshold = "80"
alarm_description = "This metric monitors ec2 cpu utilization"
insufficient_data_actions = []
dimensions
InstanceId = "$element(var.instances, count.index)"
Is something like this even possible with terraform and if so what's the best way to do it?
Thanks!
terraform
add a comment |
First time asking a question so if I've left anything important out let me know!
Terraform v0.11.1
provider.aws v0.1.4
I'm trying to create multiple cloudwatch alarms for multiple instances. I was wondering if there was a way to have the config iterating though a list. I have tried using the following code, but I get "Error: variable "instances": default may not contain interpolations".
variable "instances"
description = "Run the EC2 Instances in these Availability Zones"
type = "list"
default = ["$aws_instance.my_instance1.id", "$aws_instance.my_instance2.id", "$aws_instance.my_instance3.id", "$aws_instance.my_instance4.id", "$aws_instance.my_instance5.id"]
############ Cloudwatch monitoring
resource "aws_cloudwatch_metric_alarm" "cpu"
count = 5
alarm_name = "terraform-cpu-high-test"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "180"
statistic = "Average"
threshold = "80"
alarm_description = "This metric monitors ec2 cpu utilization"
insufficient_data_actions = []
dimensions
InstanceId = "$element(var.instances, count.index)"
Is something like this even possible with terraform and if so what's the best way to do it?
Thanks!
terraform
add a comment |
First time asking a question so if I've left anything important out let me know!
Terraform v0.11.1
provider.aws v0.1.4
I'm trying to create multiple cloudwatch alarms for multiple instances. I was wondering if there was a way to have the config iterating though a list. I have tried using the following code, but I get "Error: variable "instances": default may not contain interpolations".
variable "instances"
description = "Run the EC2 Instances in these Availability Zones"
type = "list"
default = ["$aws_instance.my_instance1.id", "$aws_instance.my_instance2.id", "$aws_instance.my_instance3.id", "$aws_instance.my_instance4.id", "$aws_instance.my_instance5.id"]
############ Cloudwatch monitoring
resource "aws_cloudwatch_metric_alarm" "cpu"
count = 5
alarm_name = "terraform-cpu-high-test"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "180"
statistic = "Average"
threshold = "80"
alarm_description = "This metric monitors ec2 cpu utilization"
insufficient_data_actions = []
dimensions
InstanceId = "$element(var.instances, count.index)"
Is something like this even possible with terraform and if so what's the best way to do it?
Thanks!
terraform
First time asking a question so if I've left anything important out let me know!
Terraform v0.11.1
provider.aws v0.1.4
I'm trying to create multiple cloudwatch alarms for multiple instances. I was wondering if there was a way to have the config iterating though a list. I have tried using the following code, but I get "Error: variable "instances": default may not contain interpolations".
variable "instances"
description = "Run the EC2 Instances in these Availability Zones"
type = "list"
default = ["$aws_instance.my_instance1.id", "$aws_instance.my_instance2.id", "$aws_instance.my_instance3.id", "$aws_instance.my_instance4.id", "$aws_instance.my_instance5.id"]
############ Cloudwatch monitoring
resource "aws_cloudwatch_metric_alarm" "cpu"
count = 5
alarm_name = "terraform-cpu-high-test"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "2"
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = "180"
statistic = "Average"
threshold = "80"
alarm_description = "This metric monitors ec2 cpu utilization"
insufficient_data_actions = []
dimensions
InstanceId = "$element(var.instances, count.index)"
Is something like this even possible with terraform and if so what's the best way to do it?
Thanks!
terraform
terraform
asked Dec 11 '17 at 17:49
Matthew SlaterMatthew Slater
83
83
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Your issue is
default = ["$aws_instance.my_instance1.id", "$aws_instance.my_instance2.id", "$aws_instance.my_instance3.id", "$aws_instance.my_instance4.id", "$aws_instance.my_instance5.id"]
That either has to be passed in or set statically.
If my_instance1-5 are the same and can be set with a count in them like above. Then its better to do
InstanceId = "$element(aws_instance.my_instance.*.id, count.index)"
Thanks Mike, that’s a shame. So every time I destroy and recreate servers I would have to manually update those values?
– Matthew Slater
Dec 12 '17 at 7:44
add a comment |
It would help if you show us the code on how you're creating the EC2 instances. If they are created with a count then this should be easier. If they are created in the same template as this Cloudwatch code, then again even easier.
If it's not in the same template, then you will need to use outputs. https://www.terraform.io/docs/configuration/outputs.html
This allows a module to output information for other modules to use.
To gain information from an output, you need a data source that will allow you to look inside the state file and abstract the EC2 instance ID's. This helps if you're using a remote backend, such as S3.
If it's in the same module and it's using a count to build the instances, then as Mike said, you can use
InstanceId = "$element(aws_instance.my_instance.*.id, count.index)"
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f887563%2fcreate-multiple-resources-terraform%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your issue is
default = ["$aws_instance.my_instance1.id", "$aws_instance.my_instance2.id", "$aws_instance.my_instance3.id", "$aws_instance.my_instance4.id", "$aws_instance.my_instance5.id"]
That either has to be passed in or set statically.
If my_instance1-5 are the same and can be set with a count in them like above. Then its better to do
InstanceId = "$element(aws_instance.my_instance.*.id, count.index)"
Thanks Mike, that’s a shame. So every time I destroy and recreate servers I would have to manually update those values?
– Matthew Slater
Dec 12 '17 at 7:44
add a comment |
Your issue is
default = ["$aws_instance.my_instance1.id", "$aws_instance.my_instance2.id", "$aws_instance.my_instance3.id", "$aws_instance.my_instance4.id", "$aws_instance.my_instance5.id"]
That either has to be passed in or set statically.
If my_instance1-5 are the same and can be set with a count in them like above. Then its better to do
InstanceId = "$element(aws_instance.my_instance.*.id, count.index)"
Thanks Mike, that’s a shame. So every time I destroy and recreate servers I would have to manually update those values?
– Matthew Slater
Dec 12 '17 at 7:44
add a comment |
Your issue is
default = ["$aws_instance.my_instance1.id", "$aws_instance.my_instance2.id", "$aws_instance.my_instance3.id", "$aws_instance.my_instance4.id", "$aws_instance.my_instance5.id"]
That either has to be passed in or set statically.
If my_instance1-5 are the same and can be set with a count in them like above. Then its better to do
InstanceId = "$element(aws_instance.my_instance.*.id, count.index)"
Your issue is
default = ["$aws_instance.my_instance1.id", "$aws_instance.my_instance2.id", "$aws_instance.my_instance3.id", "$aws_instance.my_instance4.id", "$aws_instance.my_instance5.id"]
That either has to be passed in or set statically.
If my_instance1-5 are the same and can be set with a count in them like above. Then its better to do
InstanceId = "$element(aws_instance.my_instance.*.id, count.index)"
answered Dec 11 '17 at 21:15
MikeMike
18.9k44270
18.9k44270
Thanks Mike, that’s a shame. So every time I destroy and recreate servers I would have to manually update those values?
– Matthew Slater
Dec 12 '17 at 7:44
add a comment |
Thanks Mike, that’s a shame. So every time I destroy and recreate servers I would have to manually update those values?
– Matthew Slater
Dec 12 '17 at 7:44
Thanks Mike, that’s a shame. So every time I destroy and recreate servers I would have to manually update those values?
– Matthew Slater
Dec 12 '17 at 7:44
Thanks Mike, that’s a shame. So every time I destroy and recreate servers I would have to manually update those values?
– Matthew Slater
Dec 12 '17 at 7:44
add a comment |
It would help if you show us the code on how you're creating the EC2 instances. If they are created with a count then this should be easier. If they are created in the same template as this Cloudwatch code, then again even easier.
If it's not in the same template, then you will need to use outputs. https://www.terraform.io/docs/configuration/outputs.html
This allows a module to output information for other modules to use.
To gain information from an output, you need a data source that will allow you to look inside the state file and abstract the EC2 instance ID's. This helps if you're using a remote backend, such as S3.
If it's in the same module and it's using a count to build the instances, then as Mike said, you can use
InstanceId = "$element(aws_instance.my_instance.*.id, count.index)"
add a comment |
It would help if you show us the code on how you're creating the EC2 instances. If they are created with a count then this should be easier. If they are created in the same template as this Cloudwatch code, then again even easier.
If it's not in the same template, then you will need to use outputs. https://www.terraform.io/docs/configuration/outputs.html
This allows a module to output information for other modules to use.
To gain information from an output, you need a data source that will allow you to look inside the state file and abstract the EC2 instance ID's. This helps if you're using a remote backend, such as S3.
If it's in the same module and it's using a count to build the instances, then as Mike said, you can use
InstanceId = "$element(aws_instance.my_instance.*.id, count.index)"
add a comment |
It would help if you show us the code on how you're creating the EC2 instances. If they are created with a count then this should be easier. If they are created in the same template as this Cloudwatch code, then again even easier.
If it's not in the same template, then you will need to use outputs. https://www.terraform.io/docs/configuration/outputs.html
This allows a module to output information for other modules to use.
To gain information from an output, you need a data source that will allow you to look inside the state file and abstract the EC2 instance ID's. This helps if you're using a remote backend, such as S3.
If it's in the same module and it's using a count to build the instances, then as Mike said, you can use
InstanceId = "$element(aws_instance.my_instance.*.id, count.index)"
It would help if you show us the code on how you're creating the EC2 instances. If they are created with a count then this should be easier. If they are created in the same template as this Cloudwatch code, then again even easier.
If it's not in the same template, then you will need to use outputs. https://www.terraform.io/docs/configuration/outputs.html
This allows a module to output information for other modules to use.
To gain information from an output, you need a data source that will allow you to look inside the state file and abstract the EC2 instance ID's. This helps if you're using a remote backend, such as S3.
If it's in the same module and it's using a count to build the instances, then as Mike said, you can use
InstanceId = "$element(aws_instance.my_instance.*.id, count.index)"
answered May 14 at 13:21
Steve TownsendSteve Townsend
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f887563%2fcreate-multiple-resources-terraform%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown