How to use create_vpc method in localstack

Best Python code snippet using localstack_python

aws.py

Source:aws.py Github

copy

Full Screen

1class main():2 #Redirector3 def redirector(c):4 if c["redirector_id"] == "localhost" and c["type"]== "dns":5 output = f"""6module "redirector_{c["id"]}" {{7 source = "../../redbaron/modules/{c["provider"]}/{c["type"]}-local-rdir"8 redirect_to = ["localhost"]9 instance_type = "{c["size"]}"10 vpc_id = "${{module.create_vpc.vpc_id}}"11 subnet_id = "${{module.create_vpc.subnet_id}}"12}}13output "redirector_{c["id"]}-ips" {{14 value = "${{module.redirector_{c["id"]}.ips}}"15}}16output "{c["id"]}_Run_the_following_command_on_your_internal_HTTP_server" {{17 value = "\\n\\nsocat tcp4-LISTEN:53,fork udp:localhost:53\\nsudo autossh -M 11166 -i ${{module.redirector_{c["id"]}.ips[0][0]}} -N -R 2222:localhost:53 admin@${{module.redirector_{c["id"]}.ips[0][0]}}\\n"18}}19""" 20 elif c["redirector_id"] == "localhost" and c["type"]== "http":21 output = f"""22module "redirector_{c["id"]}" {{23 source = "../../redbaron/modules/{c["provider"]}/{c["type"]}-rdir"24 redirect_to = ["localhost"]25 instance_type = "{c["size"]}"26 vpc_id = "${{module.create_vpc.vpc_id}}"27 subnet_id = "${{module.create_vpc.subnet_id}}"28 http-port = 808029 https-port = 444330}}31output "redirector_{c["id"]}-ips" {{32 value = "${{module.redirector_{c["id"]}.ips}}"33}}34output "{c["id"]}_Run_the_following_command_on_your_internal_HTTP_server" {{35 value = "\\n\\nautossh -M 11166 -i ${{module.redirector_{c["id"]}.ips[0][0]}} -N -R 8080:localhost:80 admin@${{module.redirector_{c["id"]}.ips[0][0]}}\\nautossh -M 11166 -i ${{module.redirector_{c["id"]}.ips[0][0]}} -N -R 4443:localhost:443 admin@${{module.redirector_{c["id"]}.ips[0][0]}}\\n"36}}37""" 38 else:39 output = f"""40module "redirector_{c["id"]}" {{41 source = "../../redbaron/modules/{c["provider"]}/{c["type"]}-rdir"42 redirect_to = flatten("${{module.{c["redirector_id"].split("/")[1]}_{c["redirector_id"].split("/")[0]}.ips}}")43 instance_type = "{c["size"]}"44 vpc_id = "${{module.create_vpc.vpc_id}}"45 subnet_id = "${{module.create_vpc.subnet_id}}"46}}47output "redirector_{c["id"]}-ips" {{48 value = "${{module.redirector_{c["id"]}.ips}}"49}}50"""51 return output52 #C253 def c2(c):54 scripts = ', '.join('"../../redbaron/data/scripts/tools/{0}.sh"'.format(s) for s in c["tools"])55 user = ""56 if c["distro"] == "kali":57 user = "ec2-user"58 elif c["distro"] == "ubuntu":59 user = "ubuntu"60 else:61 user = "admin"62 63 if c["redirectors"] > 0:64 output = f"""65module "c2_{c["id"]}" {{66 source = "../../redbaron/modules/{c["provider"]}/{c["type"]}-c2"67 install = [{scripts}]68 instance_type = "{c["size"]}"69 vpc_id = "${{module.create_vpc.vpc_id}}"70 subnet_id = "${{module.create_vpc.subnet_id}}"71 user = "{user}"72 amis = {{"{c["region"]}"="{c["ami"]}"}}73}}74module "c2_rdir_{c["id"]}" {{75 source = "../../redbaron/modules/{c["provider"]}/{c["type"]}-rdir"76 counter = {c["redirectors"]}77 redirect_to = flatten("${{module.c2_{c["id"]}.ips}}")78 instance_type = "{c["size"]}"79 vpc_id = "${{module.create_vpc.vpc_id}}"80 subnet_id = "${{module.create_vpc.subnet_id}}"81}}82output "c2-{c["id"]}-ips" {{83 value = "${{module.c2_{c["id"]}.ips}}"84}}85output "c2-rdir-{c["id"]}-ips" {{86 value = "${{module.c2_rdir_{c["id"]}.ips}}"87}}88"""89 else:90 output = f"""91module "c2_{c["id"]}" {{92 source = "../../redbaron/modules/{c["provider"]}/{c["type"]}-c2"93 install = [{scripts}]94 instance_type = "{c["size"]}"95 vpc_id = "${{module.create_vpc.vpc_id}}"96 subnet_id = "${{module.create_vpc.subnet_id}}"97 user = "{user}"98 amis = {{"{c["region"]}"="{c["ami"]}"}}99}}100output "c2-{c["id"]}-ips" {{101 value = "${{module.c2_{c["id"]}.ips}}"102}}103"""104 return output105 #WebServer106 def webserver(c):107 if c["redirectors"] > 0:108 output = f"""109module "webserver_{c["id"]}" {{110 source = "../../redbaron/modules/{c["provider"]}/phishing-server"111 instance_type = "{c["size"]}"112 vpc_id = "${{module.create_vpc.vpc_id}}"113 subnet_id = "${{module.create_vpc.subnet_id}}"114}}115module "webserver_rdir_{c["id"]}" {{116 source = "../../redbaron/modules/{c["provider"]}/http-rdir"117 redirect_to = flatten("${{module.webserver_{c["id"]}.ips}}")118 instance_type = "{c["size"]}"119 counter = {c["redirectors"]}120 vpc_id = "${{module.create_vpc.vpc_id}}"121 subnet_id = "${{module.create_vpc.subnet_id}}"122}}123output "webserver-{c["id"]}-ips" {{124 value = "${{module.webserver_{c["id"]}.ips}}"125}}126output "webserver-rdir-{c["id"]}-ips" {{127 value = "${{module.webserver_rdir_{c["id"]}.ips}}"128}}129"""130 else:131 output = f"""132module "webserver_{c["id"]}" {{133 source = "../../redbaron/modules/{c["provider"]}/phishing-server"134 instance_type = "{c["size"]}"135 vpc_id = "${{module.create_vpc.vpc_id}}"136 subnet_id = "${{module.create_vpc.subnet_id}}"137}}138output "webserver-{c["id"]}-ips" {{139 value = "${{module.webserver_{c["id"]}.ips}}"140}}141"""142 return output143 #Gophish:144 def gophish(c):145 if c["redirectors"] > 0:146 output = f"""147module "gophish_{c["id"]}" {{148 source = "../../redbaron/modules/{c["provider"]}/phishing-server-gophish"149 instance_type = "{c["size"]}"150 vpc_id = "${{module.create_vpc.vpc_id}}"151 subnet_id = "${{module.create_vpc.subnet_id}}"152}}153module "gophish_rdir_{c["id"]}" {{154 source = "../../redbaron/modules/{c["provider"]}/http-rdir"155 redirect_to = flatten("${{module.gophish_{c["id"]}.ips}}")156 instance_type = "{c["size"]}"157 counter = {c["redirectors"]}158 vpc_id = "${{module.create_vpc.vpc_id}}"159 subnet_id = "${{module.create_vpc.subnet_id}}"160}}161output "gophish-{c["id"]}-ips" {{162 value = "${{module.gophish_{c["id"]}.ips}}"163}}164output "gophish-rdir-{c["id"]}-ips" {{165 value = "${{module.gophish_rdir_{c["id"]}.ips}}"166}}167output "Admin_Password_{c["id"]}" {{168 value = "You can find the auto-generated Gophish admin password at: /opt/gophish/password.txt"169}}170"""171 else:172 output = f"""173module "gophish_{c["id"]}" {{174 source = "../../redbaron/modules/{c["provider"]}/phishing-server-gophish"175 instance_type = "{c["size"]}"176 vpc_id = "${{module.create_vpc.vpc_id}}"177 subnet_id = "${{module.create_vpc.subnet_id}}"178}}179output "gophish-{c["id"]}-ips" {{180 value = "${{module.gophish_{c["id"]}.ips}}"181}}182output "Admin_Password_{c["id"]}" {{183 value = "You can find the auto-generated Gophish admin password at: /opt/gophish/password.txt"184}}185"""186 return output187 #Mail188 def mail(c,my_nets_1,my_nets_2,my_nets_3,project_id):189 data = ""190 with open (f"projects/{project_id}/{c['id']}/iredmailpass.txt", "r") as myfile:191 data = myfile.readlines() 192 data = data[0].strip('\n')193 output=f"""194module "mail_{c["id"]}" {{195 source = "../../redbaron/modules/{c["provider"]}/mail-server"196 instance_type = "{c["size"]}"197 vpc_id = "${{module.create_vpc.vpc_id}}"198 subnet_id = "${{module.create_vpc.subnet_id}}"199 path = "{c["id"]}/iredmail.sh"200}}201output "mail-{c["id"]}-ips" {{202 value = "${{module.mail_{c["id"]}.ips}}"203}}204output "iRedMail_credentials_{c["id"]}" {{205 value = "postmaster@{c["domain_name"]}:{data}\\n"206}}207resource "null_resource" "update_iredmail_{c["id"]}" {{208 provisioner "remote-exec" {{209 inline = [210 "sudo postconf -e 'mynetworks = 127.0.0.1 [::1] {my_nets_1}'",211 "echo \\"MYNETWORKS = [{my_nets_2}]\\" | sudo tee -a /opt/iredapd/settings.py",212 "sudo postconf -e \\"mydomain = {c["domain_name"]}\\"",213 "sudo postconf -e \\"myhostname = {c["subdomain"]}.{c["domain_name"]}\\"",214 "sudo postconf -e \\"myorigin = \\\\$mydomain\\"",215 "sudo postconf -# \\"content_filter\\"",216 "sudo postconf -e \\"always_add_missing_headers = yes\\"",217 "sudo sed -i 's/@bypass_virus_checks_maps = (0);/@bypass_virus_checks_maps = (1);/g' /etc/amavis/conf.d/50-user",218 "sudo touch /etc/postfix/sender_access.pcre",219 "sudo echo -e \\"{my_nets_3}\\" | sudo tee -a /etc/postfix/sender_access.pcre",220 "sudo service clamav-daemon restart",221 "sudo service amavis restart",222 "sudo service clamav-freshclam restart",223 "sudo service postfix restart"224 ]225 connection {{226 host = module.mail_{c["id"]}.ips[0][0]227 type = "ssh"228 user = "admin"229 private_key = file("ssh_keys/${{module.mail_{c["id"]}.ips[0][0]}}")230 }}231 }}232}}233"""234 return output235 def dns_records_type(c,record,value,godaddy_id,aws_domains):236 domain = record.split('"')237 id_domain = 0238 for idx,d in enumerate(aws_domains):239 if domain[1] in aws_domains[idx]:240 id_domain = idx241 break242 if not godaddy_id:243 if not c["name"]:244 output=f"""245module "create_dns_record_{c["id"]}" {{246 source = "../../redbaron/modules/aws/create-dns-record"247 name = "{list(c["records"])[0]}"248 type = "{c["type"]}"249 counter = 1250 records = {{ {record} }}251 zone = module.public_zone.public_zones_ids[{value}]252}}\n"""253 else:254 output=f"""255module "create_dns_record_{c["id"]}" {{256 source = "../../redbaron/modules/aws/create-dns-record"257 name = "{c["name"]}.{list(c["records"])[0]}"258 type = "{c["type"]}"259 counter = 1260 records = {{ {record} }}261 zone = module.public_zone.public_zones_ids[{value}]262}}\n"""263 else:264 if not c["name"]:265 output=f"""266module "create_dns_record_{c["id"]}" {{267 source = "../../redbaron/modules/aws/create-dns-record"268 name = "{list(c["records"])[0]}"269 type = "{c["type"]}"270 counter = module.redirect_ns_{godaddy_id}.redirected271 records = {{ {record} }}272 zone = module.public_zone.public_zones_ids[{value}]273}}\n"""274 else:275 output=f"""276module "create_dns_record_{c["id"]}" {{277 source = "../../redbaron/modules/aws/create-dns-record"278 name = "{c["name"]}.{list(c["records"])[0]}"279 type = "{c["type"]}"280 counter = module.redirect_ns_{godaddy_id}.redirected281 records = {{ {record} }}282 zone = module.public_zone.public_zones_ids[{value}]283}}\n"""284 return output285 def dns_records_type_txt(record,value):286 output=f"""287module "create_dns_record_{value}" {{288 source = "../../redbaron/modules/aws/create-dns-txt-record"289 name = ""290 type = "TXT"291 records = [{record}]292 zone = module.public_zone.public_zones_ids[{value}]293}}\n"""294 return output295 def create_dns_name(domain_string_aws):296 output=f"""297##################################################################################################################298# DNS ROUTE53 Zone #299##################################################################################################################300module "public_zone" {{301 source = "../../redbaron/modules/aws/create-hosted-zone"302 public_hosted_zones = [{domain_string_aws}]303 tags = {{304 Environment = "prod"305 Infrastructure = "core"306 Owner = "terraform"307 Project = "zones-public"308 }}309 comment = "Managed by Terraform"310}}311"""...

Full Screen

Full Screen

vpc_Automation_using_Python.py

Source:vpc_Automation_using_Python.py Github

copy

Full Screen

...3client = boto3.client('ec2', region_name="ap-south-1", aws_access_key_id="AKIAQZWM3ITJU2LFIUGF",aws_secret_access_key="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")45print ("Enter the CIDR For VPC:")6vpc_cidr = input()7create_vpc = client.create_vpc(CidrBlock=vpc_cidr)8print (create_vpc['Vpc']['VpcId'])9vpcid = create_vpc['Vpc']['VpcId']1011print ("Enter the CIDR For Subnet:")12subnet_cidr = input()13create_subnet = client.create_subnet(CidrBlock=subnet_cidr,VpcId=vpcid)14subnetid = create_subnet['Subnet']['SubnetId']15print(subnetid)16171819Internet gateway2021Route table

Full Screen

Full Screen

deploy_system.py

Source:deploy_system.py Github

copy

Full Screen

1from src.create_vpc.createvpc import CreateVpc2from src.create_ec2.createec2 import EC23from src.ec2.other_featurs import Features4def mainprogram():5 create_bucket = Features()6 create_bucket.create_bucket()7 create_bucket.list_of_bucket()8 create_vpc = CreateVpc()9 create_vpc.createvpc()10 create_ec2 = EC2()11 create_ec2.createec2(create_vpc)12# Deploy the cloud System13if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful