-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathbuild.gradle
63 lines (51 loc) · 2.01 KB
/
build.gradle
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
// -*- coding: utf-8; mode: groovy -*-
import jp.classmethod.aws.gradle.ec2.AmazonEC2ImportKeyTask;
import jp.classmethod.aws.gradle.ec2.AmazonEC2RunInstanceTask;
import jp.classmethod.aws.gradle.ec2.AmazonEC2StartInstanceTask;
import jp.classmethod.aws.gradle.ec2.AmazonEC2StopInstanceTask;
import jp.classmethod.aws.gradle.ec2.AmazonEC2TerminateInstanceTask;
import jp.classmethod.aws.gradle.ec2.AmazonEC2WaitInstanceStatusTask;
buildscript {
repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "jp.classmethod.aws:gradle-aws-plugin:0.+"
}
}
apply plugin: "jp.classmethod.aws.ec2"
aws {
profileName = "default"
region = "ap-northeast-1"
}
task importKey(type: AmazonEC2ImportKeyTask) {
keyName "sample-key"
publicKeyMaterial "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCDSfT3mJ5LbEIVgxh0FIFyERmfML2FkEmTCmF6dxmuJGiHaja6e71IwALDAH2B6HyrEbzuYE+43DMFxgnglkzOnZ5azWnotDDqXUS+Rg+EKU7vDzMifV5iQ13oVwQSr0vGX2WDzvhKMe9nQtUsu1LAVHir128Bnl6M76VrlAfjEX2sUfHGzWKEPzyTY0DgQFQo+2e37bP2M0Wvrb+CJxlFLQPsDc5ebB2hWnJtWK++7IORT7mgLLeLCRZQ7sOF1ZUP5ax0M9j7dl7+m6Vev/fHIbQjqVPRKbgm35iOCTkto8lHCZmoRGQmG6t83T8FSy7Pzd4XDw49hDF1uXZXkl19"
ifNotExists true
}
if (hasProperty('instanceId') == false) { ext.instanceId = 'i-12345678' }
task runInstance(type: AmazonEC2RunInstanceTask, dependsOn: importKey) {
ami "ami-cbf90ecb"
keyName "sample-key"
instanceType "t2.micro"
userData "#! /bin/bash\nyum -y update"
iamInstanceProfileName "profile-name"
}
task stopInstance(type: AmazonEC2StopInstanceTask) {
instanceIds += project.instanceId
}
task startInstance(type: AmazonEC2StartInstanceTask) {
instanceIds += project.instanceId
}
task terminateInstance(type: AmazonEC2TerminateInstanceTask) {
instanceIds += project.instanceId
}
task waitInstanceStatusStable(type: AmazonEC2WaitInstanceStatusTask) {
shouldRunAfter runInstance, stopInstance, startInstance, terminateInstance
instanceId = project.instanceId
loopWait = 2
doLast {
println "Ip of the instance: " + awsInstance.getPublicIpAddress()
}
}