generated from seal-io/walrus-template-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.tf
119 lines (93 loc) · 2.26 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
terraform {
required_version = ">= 1.0"
required_providers {
random = {
source = "hashicorp/random"
version = ">= 3.5.1"
}
aws = {
source = "hashicorp/aws"
version = ">= 5.24.0"
}
}
}
provider "aws" {}
data "aws_availability_zones" "selected" {
state = "available"
lifecycle {
postcondition {
condition = length(self.names) > 0
error_message = "Failed to get Avaialbe Zones"
}
}
}
# create vpc.
resource "aws_vpc" "example" {
instance_tenancy = "default"
enable_dns_hostnames = true
enable_dns_support = true
cidr_block = "10.0.0.0/16"
}
resource "aws_subnet" "example" {
for_each = {
for k, v in data.aws_availability_zones.selected.names : v => cidrsubnet(aws_vpc.example.cidr_block, 8, k)
}
vpc_id = aws_vpc.example.id
availability_zone = each.key
cidr_block = each.value
}
# create kms key.
resource "aws_kms_key" "example" {
key_usage = "ENCRYPT_DECRYPT"
customer_master_key_spec = "SYMMETRIC_DEFAULT"
deletion_window_in_days = 7
is_enabled = true
enable_key_rotation = false
multi_region = true
description = "postgresql-encryption"
}
# create private dns.
resource "aws_service_discovery_private_dns_namespace" "example" {
name = "my-dev-dns"
vpc = aws_vpc.example.id
}
# create postgresql service.
module "this" {
source = "../.."
infrastructure = {
vpc_id = aws_vpc.example.id
kms_key_id = aws_kms_key.example.id
domain_suffix = aws_service_discovery_private_dns_namespace.example.name
}
depends_on = [aws_service_discovery_private_dns_namespace.example]
}
output "context" {
value = module.this.context
}
output "refer" {
value = nonsensitive(module.this.refer)
}
output "connection" {
value = module.this.connection
}
output "connection_readonly" {
value = module.this.connection_readonly
}
output "address" {
value = module.this.address
}
output "address_readonly" {
value = module.this.address_readonly
}
output "port" {
value = module.this.port
}
output "database" {
value = module.this.database
}
output "username" {
value = module.this.username
}
output "password" {
value = nonsensitive(module.this.password)
}