-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPipeline.tf
132 lines (112 loc) · 3.49 KB
/
Pipeline.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
124
125
126
127
128
129
130
131
132
#Creating pipeline
resource "aws_imagebuilder_image_pipeline" "NewPipe2-TFE" {
image_recipe_arn = aws_imagebuilder_image_recipe.NewRecipe2-TFE.arn
infrastructure_configuration_arn = aws_imagebuilder_infrastructure_configuration.NewConfig2-TFE.arn
distribution_configuration_arn = aws_imagebuilder_distribution_configuration.NewDistSet2-TFE.arn
name = var.PipelineName
status = "ENABLED"
description = "Pipeline to create AMI"
depends_on = [
aws_imagebuilder_image_recipe.NewRecipe2-TFE,
aws_imagebuilder_infrastructure_configuration.NewConfig2-TFE
]
}
#Defining Infrastructe Configurations
resource "aws_imagebuilder_infrastructure_configuration" "NewConfig2-TFE" {
description = "Configuration for Pipeline"
instance_profile_name = aws_iam_instance_profile.AttachToPipe.name
instance_types = ["t2.micro"]
name = var.InfraName
security_group_ids = [data.aws_security_group.SG.id]
subnet_id = data.aws_subnet.SN.id
terminate_instance_on_failure = true
}
#Define Distribution Settings
resource "aws_imagebuilder_distribution_configuration" "NewDistSet2-TFE" {
name = var.DistSetName
distribution {
ami_distribution_configuration {
name = "AR-Ubuntu-{{ imagebuilder:buildDate }}"
launch_permission {
user_ids = ["549987867165"]
}
}
region = var.aws_region
}
}
#Recipe for Ubuntu 20
resource "aws_imagebuilder_image_recipe" "NewRecipe2-TFE" {
name = var.RecipeName
parent_image = "arn:${data.aws_partition.current.partition}:imagebuilder:${data.aws_region.current.name}:aws:image/ubuntu-server-20-lts-x86/x.x.x"
version = var.Version
description = "Creating Recipe through TFE"
// Below cron is for every first day of month at 10PM CST, but for now will run it manually
/*
schedule {
schedule_expression = "cron(0 4 1 * ? *)"
}
*/
block_device_mapping {
device_name = "/dev/xvdb"
ebs {
delete_on_termination = true
volume_size = 10
volume_type = "gp2"
}
}
component {
//component_arn = data.aws_imagebuilder_component.AnsiblePlay.arn
component_arn = aws_imagebuilder_component.InstallCW2.arn
}
component {
component_arn = aws_imagebuilder_component.Test_AWS_CW.arn
}
component {
component_arn = aws_imagebuilder_component.TestCLI.arn
}
}
#Components
resource "aws_imagebuilder_component" "InstallCW2" {
name = "InstallCW2"
platform = "Linux"
uri = "s3://arimagebuildcomponents/InstallCW2.yml"
version = "1.0.0"
}
resource "aws_imagebuilder_component" "TestCLI" {
data = yamlencode({
phases = [{
name = "test"
steps = [{
action = "ExecuteBash"
inputs = {
commands = ["aws --version"]
}
name = "YamlCode"
onFailure = "Continue"
}]
}]
schemaVersion = 1.0
})
name = "TestCLI"
platform = "Linux"
version = "1.0.0"
}
resource "aws_imagebuilder_component" "Test_AWS_CW" {
data = yamlencode({
phases = [{
name = "test"
steps = [{
action = "ExecuteBash"
inputs = {
commands = ["apt list --installed | grep '^amazon-cloudwatch-agent'"]
}
name = "YamlCode"
onFailure = "Continue"
}]
}]
schemaVersion = 1.0
})
name = "Test_AWS_CW"
platform = "Linux"
version = "1.0.0"
}