Search in sources :

Example 1 with UserData

use of com.scaleset.cfbuilder.ec2.UserData in project TOSCAna by StuPro-TOSCAna.

the class CloudFormationVisitorExtension method createSqlCompute.

protected String createSqlCompute(MysqlDatabase mysqlDatabase, String sqlQuery) {
    String computeName = toAlphanumerical(mysqlDatabase.getEntityName()) + "TmpSqlServer";
    SecurityGroup webServerSecurityGroup = cfnModule.resource(SecurityGroup.class, computeName + SECURITY_GROUP).groupDescription("Temporary group for accessing mysqlDatabase" + toAlphanumerical(mysqlDatabase.getEntityName()) + "  with SQLRequest");
    cfnModule.resource(Instance.class, computeName).securityGroupIds(webServerSecurityGroup).imageId("ami-79873901").instanceType("t2.micro").instanceInitiatedShutdownBehavior("terminate").userData(new UserData(StackUtils.getUserDataDBConnFn(mysqlDatabase, sqlQuery)));
    return computeName;
}
Also used : Instance(com.scaleset.cfbuilder.ec2.Instance) UserData(com.scaleset.cfbuilder.ec2.UserData) SecurityGroup(com.scaleset.cfbuilder.ec2.SecurityGroup)

Example 2 with UserData

use of com.scaleset.cfbuilder.ec2.UserData in project TOSCAna by StuPro-TOSCAna.

the class CloudFormationModule method build.

/**
 *     Build the template
 *     1. Add CFNInit to corresponding instance resource
 *     2. Check if EC2 instances need access to S3. If yes, then
 *     2a. Add necessary IAM resources to the module
 *     2b. Add <tt>Authentication<tt> and <tt>IamInstanceProfile<tt> to corresponding instance resource
 */
@Override
public void build() {
    for (Map.Entry<String, CFNInit> pair : cfnInitMap.entrySet()) {
        Resource res = this.getResource(pair.getKey());
        if (res instanceof Instance) {
            Instance instance = (Instance) res;
            if (!pair.getValue().getConfigs().isEmpty()) {
                instance.addCFNInit(pair.getValue()).userData(new UserData(getUserDataFn(pair.getKey(), CONFIG_SETS, this)));
            }
        }
    }
    if (!fileUploadList.isEmpty()) {
        Role instanceRole = getS3InstanceRole(this);
        getS3Policy(this).roles(instanceRole);
        getS3InstanceProfile(this).roles(instanceRole);
        Authentication s3authentication = getS3Authentication(bucketName);
        for (String instanceName : authenticationSet) {
            Resource res = this.getResource(instanceName);
            if (res instanceof Instance) {
                Instance instance = (Instance) res;
                instance.authentication(s3authentication).iamInstanceProfile(ref(INSTANCE_PROFILE));
            }
        }
    }
    if (this.hasKeyPair()) {
        strParam(KEYNAME).type(KEYNAME_TYPE).description(KEYNAME_DESCRIPTION).constraintDescription(KEYNAME_CONSTRAINT_DESCRIPTION);
    }
}
Also used : AuthenticationUtils.getS3InstanceRole(org.opentosca.toscana.plugins.cloudformation.util.AuthenticationUtils.getS3InstanceRole) Role(com.scaleset.cfbuilder.iam.Role) Instance(com.scaleset.cfbuilder.ec2.Instance) UserData(com.scaleset.cfbuilder.ec2.UserData) AuthenticationUtils.getS3Authentication(org.opentosca.toscana.plugins.cloudformation.util.AuthenticationUtils.getS3Authentication) Authentication(com.scaleset.cfbuilder.cloudformation.Authentication) Resource(com.scaleset.cfbuilder.core.Resource) CFNInit(com.scaleset.cfbuilder.ec2.metadata.CFNInit) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Instance (com.scaleset.cfbuilder.ec2.Instance)2 UserData (com.scaleset.cfbuilder.ec2.UserData)2 Authentication (com.scaleset.cfbuilder.cloudformation.Authentication)1 Resource (com.scaleset.cfbuilder.core.Resource)1 SecurityGroup (com.scaleset.cfbuilder.ec2.SecurityGroup)1 CFNInit (com.scaleset.cfbuilder.ec2.metadata.CFNInit)1 Role (com.scaleset.cfbuilder.iam.Role)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AuthenticationUtils.getS3Authentication (org.opentosca.toscana.plugins.cloudformation.util.AuthenticationUtils.getS3Authentication)1 AuthenticationUtils.getS3InstanceRole (org.opentosca.toscana.plugins.cloudformation.util.AuthenticationUtils.getS3InstanceRole)1