{"action":"created","issue":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/3646","repository_url":"https://api.github.com/repos/hashicorp/terraform","labels_url":"https://api.github.com/repos/hashicorp/terraform/issues/3646/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/terraform/issues/3646/comments","events_url":"https://api.github.com/repos/hashicorp/terraform/issues/3646/events","html_url":"https://github.com/hashicorp/terraform/issues/3646","id":113478833,"number":3646,"title":"Allow providing stub resources / read-only resources to improve modularity.","user":{"login":"preflightsiren","id":1064728,"avatar_url":"https://avatars.githubusercontent.com/u/1064728?v=3","gravatar_id":"","url":"https://api.github.com/users/preflightsiren","html_url":"https://github.com/preflightsiren","followers_url":"https://api.github.com/users/preflightsiren/followers","following_url":"https://api.github.com/users/preflightsiren/following{/other_user}","gists_url":"https://api.github.com/users/preflightsiren/gists{/gist_id}","starred_url":"https://api.github.com/users/preflightsiren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/preflightsiren/subscriptions","organizations_url":"https://api.github.com/users/preflightsiren/orgs","repos_url":"https://api.github.com/users/preflightsiren/repos","events_url":"https://api.github.com/users/preflightsiren/events{/privacy}","received_events_url":"https://api.github.com/users/preflightsiren/received_events","type":"User","site_admin":false},"labels":[{"id":127939292,"url":"https://api.github.com/repos/hashicorp/terraform/labels/core","name":"core","color":"cccccc","default":false},{"id":225743935,"url":"https://api.github.com/repos/hashicorp/terraform/labels/proposal","name":"proposal","color":"fbca04","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2015-10-27T00:24:56Z","updated_at":"2016-12-04T16:46:25Z","closed_at":"2016-12-04T16:46:25Z","body":"I've found with my use of terraform you often need to provide a mixture of environment details from computed information (eg. instance id's) and often pre-generated resources (eg. vpc id's or subnet id's).\n\nThis becomes an issue for terraform to manage such a core/common/reused resource like VPCs, if you have a mixture of managed/unmanaged resources. The issue comes about when terraform wants to teardown the whole VPC and rebuild it, but there's an unmanaged resource in there preventing the VPC from being destroyed. Now you're stuck. Either teardown the instance manually or separate out the VPC from your application and include more process.\n\n**My braindump solution:**\nusing https://github.com/hashicorp/terraform/tree/master/examples/aws-two-tier as an example, if you need to move the app into a VPC environment it ends up looking like:\n\n```\nresource \"aws_security_group\" \"default\" {\n  name = \"terraform_example\"\n  description = \"Used in the terraform\"\n  vpc_id = \"vpc-123456789\"\n```\n\nor if you use variables extensively like this:\n\n```\nresource \"aws_security_group\" \"default\" {\n  name = \"terraform_example\"\n  description = \"Used in the terraform\"\n  vpc_id = \"${var.vpc_id}\"\n}\n```\n\nbut wouldn't it be nicer to refer to an actual aws resource and be able to reference all the properties, but without having terraform try to apply configuration changes to it?\n\n**very rough solution**\n\n```\nresource \"aws_vpc\" \"main\" {\n    id = \"vpc-123456789\"\n}\n\nresource \"aws_security_group\" \"default\" {\n  name = \"terraform_example\"\n  description = \"Used in the terraform\"\n  vpc_id = \"${aws_vpc.main.vpc_id}\"\n}\n```\n\nthen terraform can provide feedback like: \"Hey that vpc with id: vpc-123456789 doesn't exist!\"\nand your security group gets configured based upon computed values, but without any of the headache of terraform plans deciding the only way to solve this plan is to burn it all down and start over.\n\nLove to hear your thoughts\n\n-Seb\n"},"comment":{"url":"https://api.github.com/repos/hashicorp/terraform/issues/comments/264714707","html_url":"https://github.com/hashicorp/terraform/issues/3646#issuecomment-264714707","issue_url":"https://api.github.com/repos/hashicorp/terraform/issues/3646","id":264714707,"user":{"login":"apparentlymart","id":20180,"avatar_url":"https://avatars.githubusercontent.com/u/20180?v=3","gravatar_id":"","url":"https://api.github.com/users/apparentlymart","html_url":"https://github.com/apparentlymart","followers_url":"https://api.github.com/users/apparentlymart/followers","following_url":"https://api.github.com/users/apparentlymart/following{/other_user}","gists_url":"https://api.github.com/users/apparentlymart/gists{/gist_id}","starred_url":"https://api.github.com/users/apparentlymart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apparentlymart/subscriptions","organizations_url":"https://api.github.com/users/apparentlymart/orgs","repos_url":"https://api.github.com/users/apparentlymart/repos","events_url":"https://api.github.com/users/apparentlymart/events{/privacy}","received_events_url":"https://api.github.com/users/apparentlymart/received_events","type":"User","site_admin":false},"created_at":"2016-12-04T16:46:25Z","updated_at":"2016-12-04T16:46:25Z","body":"Hi @preflightsiren! I just stumbled across this old issue while looking for something else.\r\n\r\nAs of one of the Terraform 0.7 releases (I forget exactly which one) we have an `aws_vpc` *data source* which I think should meet the use-case you were looking for here, with some slightly different syntax:\r\n\r\n```\r\ndata \"aws_vpc\" \"main\" {\r\n    id = \"vpc-123456789\"\r\n}\r\n\r\nresource \"aws_security_group\" \"default\" {\r\n  name = \"terraform_example\"\r\n  description = \"Used in the terraform\"\r\n  vpc_id = \"${data.aws_vpc.main.vpc_id}\"\r\n}\r\n```\r\n\r\nThe `data` block creates a \"data resource\", which is like a read-only resource (as you proposed) that fetches data from some data source; in this case, [the aws_vpc data source](https://www.terraform.io/docs/providers/aws/d/vpc.html).\r\n\r\nAnd just as you suggested, if a matching VPC isn't found then that's a fatal error that prevents the `aws_security_group` from being planned, rather than waiting and failing at apply time.\r\n\r\n[The newer aws-networking example](https://github.com/hashicorp/terraform/tree/master/examples/aws-networking) elaborates on this idea, showing how one might create a set of AWS networking resources in a modular way using a mixture of Terraform modules and data resources.\r\n\r\nSince I think this is now possible -- albeit not *exactly* as you proposed -- I'm going to close this now; please do let me know if you think there's more here that hasn't been implemented yet, and we can figure out whether to reopen this or create a more focused issue to capture the remaining proposal."}}
{"actor":{"display_login":"apparentlymart"}}