File size: 1,759 Bytes
034ba67
 
 
 
1
2
3
4
5
{"type": "session", "harness": "deepseek-harness", "id": "sys-0011", "name": "Terraform modules and state"}
{"type": "message", "message": {"role": "system", "content": "You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies."}}
{"type": "message", "message": {"role": "user", "content": "How do I organize Terraform with modules?"}}
{"type": "message", "message": {"role": "assistant", "content": "```hcl\n# modules/vpc/main.tf\nresource \"aws_vpc\" \"this\" {\n  cidr_block = var.cidr_block\n}\n\nresource \"aws_subnet\" \"public\" {\n  for_each = var.public_subnets\n  vpc_id   = aws_vpc.this.id\n  cidr_block = each.value.cidr\n  availability_zone = each.value.az\n}\n\nvariable \"cidr_block\" { type = string }\nvariable \"public_subnets\" {\n  type = map(object({ cidr = string, az = string }))\n}\n\noutput \"vpc_id\" { value = aws_vpc.this.id }\noutput \"subnet_ids\" { value = [for s in aws_subnet.public : s.id] }\n\n# modules/vpc/variables.tf\n# modules/vpc/outputs.tf\n\n# root main.tf\nmodule \"vpc\" {\n  source = \"./modules/vpc\"\n  cidr_block = \"10.0.0.0/16\"\n  public_subnets = {\n    \"pub-1\" = { cidr = \"10.0.1.0/24\", az = \"us-east-1a\" }\n    \"pub-2\" = { cidr = \"10.0.2.0/24\", az = \"us-east-1b\" }\n  }\n}\n```\n\nState management:\n```bash\nterraform state mv aws_instance.old aws_instance.new\nterraform state rm aws_instance.web\nterraform workspace new staging\nterraform workspace select production\n```"}}