|
| 1 | +/* |
| 2 | + * Copyright 2013-2014 Classmethod, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package jp.classmethod.aws.gradle.rds; |
| 17 | + |
| 18 | +import java.util.List; |
| 19 | + |
| 20 | +import lombok.Getter; |
| 21 | +import lombok.Setter; |
| 22 | + |
| 23 | +import org.gradle.api.GradleException; |
| 24 | +import org.gradle.api.internal.ConventionTask; |
| 25 | +import org.gradle.api.tasks.TaskAction; |
| 26 | + |
| 27 | +import com.amazonaws.services.rds.AmazonRDS; |
| 28 | +import com.amazonaws.services.rds.model.CreateDBInstanceRequest; |
| 29 | +import com.amazonaws.services.rds.model.DBInstance; |
| 30 | + |
| 31 | + |
| 32 | +public class AmazonRDSCreateDBInstanceTask extends ConventionTask { |
| 33 | + |
| 34 | + @Getter @Setter |
| 35 | + private String dbName; |
| 36 | + |
| 37 | + @Getter @Setter |
| 38 | + private String dbInstanceIdentifier; |
| 39 | + |
| 40 | + @Getter @Setter |
| 41 | + private Integer allocatedStorage; |
| 42 | + |
| 43 | + @Getter @Setter |
| 44 | + private String dbInstanceClass; |
| 45 | + |
| 46 | + @Getter @Setter |
| 47 | + private String engine; |
| 48 | + |
| 49 | + @Getter @Setter |
| 50 | + private String masterUsername; |
| 51 | + |
| 52 | + @Getter @Setter |
| 53 | + private String masterUserPassword; |
| 54 | + |
| 55 | + @Getter @Setter |
| 56 | + private List<String> vpcSecurityGroupIds; |
| 57 | + |
| 58 | + @Getter @Setter |
| 59 | + private String dbSubnetGroupName; |
| 60 | + |
| 61 | + @Getter @Setter |
| 62 | + private String preferredMaintenanceWindow; |
| 63 | + |
| 64 | + @Getter @Setter |
| 65 | + private String dbParameterGroupName; |
| 66 | + |
| 67 | + @Getter @Setter |
| 68 | + private Integer backupRetentionPeriod; |
| 69 | + |
| 70 | + @Getter @Setter |
| 71 | + private String preferredBackupWindow; |
| 72 | + |
| 73 | + @Getter @Setter |
| 74 | + private Integer port; |
| 75 | + |
| 76 | + @Getter @Setter |
| 77 | + private Boolean multiAZ; |
| 78 | + |
| 79 | + @Getter @Setter |
| 80 | + private String engineVersion; |
| 81 | + |
| 82 | + @Getter @Setter |
| 83 | + private Boolean autoMinorVersionUpgrade; |
| 84 | + |
| 85 | + @Getter @Setter |
| 86 | + private String licenseModel; |
| 87 | + |
| 88 | + @Getter @Setter |
| 89 | + private Integer iops; |
| 90 | + |
| 91 | + @Getter @Setter |
| 92 | + private String optionGroupName; |
| 93 | + |
| 94 | + @Getter @Setter |
| 95 | + private Boolean publiclyAccessible; |
| 96 | + |
| 97 | + @Getter @Setter |
| 98 | + private String characterSetName; |
| 99 | + |
| 100 | + @Getter @Setter |
| 101 | + private String storageType; |
| 102 | + |
| 103 | + @Getter @Setter |
| 104 | + private String tdeCredentialArn; |
| 105 | + |
| 106 | + @Getter @Setter |
| 107 | + private String tdeCredentialPassword; |
| 108 | + |
| 109 | + @Getter @Setter |
| 110 | + private Boolean storageEncrypted; |
| 111 | + |
| 112 | + @Getter @Setter |
| 113 | + private String kmsKeyId; |
| 114 | + |
| 115 | + @Getter |
| 116 | + private DBInstance dbInstance; |
| 117 | + |
| 118 | + |
| 119 | + public AmazonRDSCreateDBInstanceTask() { |
| 120 | + setDescription("Create RDS instance."); |
| 121 | + setGroup("AWS"); |
| 122 | + } |
| 123 | + |
| 124 | + @TaskAction |
| 125 | + public void createDBInstance() { |
| 126 | + // to enable conventionMappings feature |
| 127 | + String dbInstanceIdentifier = getDbInstanceIdentifier(); |
| 128 | + String dbInstanceClass = getDbInstanceClass(); |
| 129 | + String engine = getEngine(); |
| 130 | + |
| 131 | + if (dbInstanceClass == null) throw new GradleException("dbInstanceClass is required"); |
| 132 | + if (dbInstanceIdentifier == null) throw new GradleException("dbInstanceIdentifier is required"); |
| 133 | + if (engine == null) throw new GradleException("engine is required"); |
| 134 | + |
| 135 | + AmazonRDSPluginExtension ext = getProject().getExtensions().getByType(AmazonRDSPluginExtension.class); |
| 136 | + AmazonRDS rds = ext.getClient(); |
| 137 | + |
| 138 | + CreateDBInstanceRequest request = new CreateDBInstanceRequest() |
| 139 | + .withDBName(getDbName()) |
| 140 | + .withDBInstanceIdentifier(dbInstanceIdentifier) |
| 141 | + .withAllocatedStorage(getAllocatedStorage()) |
| 142 | + .withDBInstanceClass(dbInstanceClass) |
| 143 | + .withEngine(engine) |
| 144 | + .withMasterUsername(getMasterUsername()) |
| 145 | + .withMasterUserPassword(getMasterUserPassword()) |
| 146 | + .withVpcSecurityGroupIds(getVpcSecurityGroupIds()) |
| 147 | + .withDBSubnetGroupName(getDbSubnetGroupName()) |
| 148 | + .withPreferredMaintenanceWindow(getPreferredMaintenanceWindow()) |
| 149 | + .withDBParameterGroupName(getDbParameterGroupName()) |
| 150 | + .withBackupRetentionPeriod(getBackupRetentionPeriod()) |
| 151 | + .withPreferredBackupWindow(getPreferredBackupWindow()) |
| 152 | + .withPort(getPort()) |
| 153 | + .withMultiAZ(getMultiAZ()) |
| 154 | + .withEngineVersion(getEngineVersion()) |
| 155 | + .withAutoMinorVersionUpgrade(getAutoMinorVersionUpgrade()) |
| 156 | + .withLicenseModel(getLicenseModel()) |
| 157 | + .withIops(getIops()) |
| 158 | + .withOptionGroupName(getOptionGroupName()) |
| 159 | + .withPubliclyAccessible(getPubliclyAccessible()) |
| 160 | + .withCharacterSetName(getCharacterSetName()) |
| 161 | + .withStorageType(getStorageType()) |
| 162 | + .withTdeCredentialArn(getTdeCredentialArn()) |
| 163 | + .withTdeCredentialPassword(getTdeCredentialPassword()) |
| 164 | + .withStorageEncrypted(getStorageEncrypted()) |
| 165 | + .withKmsKeyId(getKmsKeyId()); |
| 166 | + dbInstance = rds.createDBInstance(request); |
| 167 | + getLogger().info("Create RDS instance requested: {}", dbInstance.getDBInstanceIdentifier()); |
| 168 | + } |
| 169 | +} |
0 commit comments