You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Need the ability to check to see if an object already exists and then be able to use it else create a new object.
Current Terraform Version
0.12.12
...
Use-cases
Example, in AWS, if a security group name xyz_sg already exists get the id of that security group for use in other parts of the terraform scripts. If the group doesn't exist, create the xyz_sg group to be used.
This pattern is intentionally not supported in Terraform because it would make it unclear to future readers of the configuration whether a particular object is managed by Terraform or not. Instead, you should decide for each situation whether the object is expected to exist already or whether it needs to be created and state that decision explicitly in your configuration.
Since the capability you are describing is intentionally not supported, we're going to close this. Thanks for taking the time to share it, though! If you have any questions about the module composition patterns, please feel free to start a new topic on the community forum. Thanks!
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Feature Request
Need the ability to check to see if an object already exists and then be able to use it else create a new object.
Current Terraform Version
0.12.12
Use-cases
Example, in AWS, if a security group name xyz_sg already exists get the id of that security group for use in other parts of the terraform scripts. If the group doesn't exist, create the xyz_sg group to be used.
Attempted Solutions
Data aws_security_group sg {
name = "xyz_sg"
}
resource aws_security_group sg {
name = xyz_sg
count = data.aws_security_group.sg.id == "" ? 1 : 0
}
Unfortunately the data.aws_security_group throws an error
Proposal
References
The text was updated successfully, but these errors were encountered: