forked from GoogleCloudPlatform/cloud-foundation-fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
123 lines (113 loc) · 3.32 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
120
121
122
123
/**
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
locals {
role_id = "projects/${var.project_id}/roles/${local.role_name}"
role_name = "feeds_cf"
}
module "project" {
source = "../../../modules/project"
name = var.project_id
project_create = var.project_create
services = [
"cloudasset.googleapis.com",
"cloudbuild.googleapis.com",
"cloudfunctions.googleapis.com",
"compute.googleapis.com"
]
custom_roles = {
(local.role_name) = [
"compute.instances.list",
"compute.instances.setTags",
"compute.zones.list",
"compute.zoneOperations.get",
"compute.zoneOperations.list"
]
}
iam = {
(local.role_id) = [module.service-account.iam_email]
}
}
module "vpc" {
source = "../../../modules/net-vpc"
project_id = module.project.project_id
name = var.name
subnets = [{
ip_cidr_range = "192.168.0.0/24"
name = "${var.name}-default"
region = var.region
}]
}
module "pubsub" {
source = "../../../modules/pubsub"
project_id = module.project.project_id
name = var.name
subscriptions = { "${var.name}-default" = null }
iam = {
"roles/pubsub.publisher" = [
"serviceAccount:${module.project.service_accounts.robots.cloudasset}"
]
}
}
module "service-account" {
source = "../../../modules/iam-service-account"
project_id = module.project.project_id
name = "${var.name}-cf"
# iam_project_roles = { (module.project.project_id) = [local.role_id] }
}
module "cf" {
source = "../../../modules/cloud-function-v1"
project_id = module.project.project_id
name = var.name
bucket_name = "${var.name}-${random_pet.random.id}"
bucket_config = {
location = var.region
}
bundle_config = {
source_dir = "${path.module}/cf"
output_path = var.bundle_path
}
service_account = module.service-account.email
trigger_config = {
event = "google.pubsub.topic.publish"
resource = module.pubsub.topic.id
}
}
module "simple-vm-example" {
source = "../../../modules/compute-vm"
project_id = module.project.project_id
zone = "${var.region}-b"
name = var.name
network_interfaces = [{
network = module.vpc.self_link
subnetwork = try(module.vpc.subnet_self_links["${var.region}/${var.name}-default"], "")
}]
tags = ["${var.project_id}-test-feed", "shared-test-feed"]
}
resource "random_pet" "random" {
length = 1
}
# Create a feed that sends notifications about instance updates.
resource "google_cloud_asset_project_feed" "project_feed" {
project = module.project.project_id
feed_id = var.name
content_type = "RESOURCE"
asset_types = ["compute.googleapis.com/Instance"]
feed_output_config {
pubsub_destination {
topic = module.pubsub.topic.id
}
}
}