Last active
February 19, 2025 20:33
-
-
Save micahmelling/aa91360e7126deeb5df2ab35dfa21375 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pulumi_aws as aws | |
| def main(database_name, allocated_gb_storage, db_engine, db_engine_version, instance_class, root_password, | |
| root_username, subnet_group_name, subnet_id_list, security_group_name, vpc_id, allowed_ip_list, | |
| security_group_port): | |
| """ | |
| Creates an RDS instance and associated security group. | |
| :param database_name: name of the database | |
| :param allocated_gb_storage: number of gigabytes of storage | |
| :param db_engine: database engine | |
| :param db_engine_version: database engine version | |
| :param instance_class: compute instance type | |
| :param root_password: password for the root user | |
| :param root_username: username for the root user | |
| :param subnet_group_name: name of the db subnet group to create | |
| :param subnet_id_list: list of subnets to launch the instance in | |
| :param security_group_name: name of the security group to create | |
| :param vpc_id: id of the VPC to create the security group in | |
| :param allowed_ip_list: list of ip addresses to allow access to the RDS instance | |
| :param security_group_port: the port over which traffic should be allowed | |
| """ | |
| subnet_group = aws.rds.SubnetGroup( | |
| subnet_group_name, | |
| name=subnet_group_name, | |
| subnet_ids=subnet_id_list, | |
| ) | |
| security_group = aws.ec2.SecurityGroup( | |
| security_group_name, | |
| name=security_group_name, | |
| vpc_id=vpc_id, | |
| ingress=[aws.ec2.SecurityGroupIngressArgs( | |
| protocol='tcp', | |
| from_port=security_group_port, | |
| to_port=security_group_port, | |
| cidr_blocks=allowed_ip_list | |
| )], | |
| egress=[aws.ec2.SecurityGroupEgressArgs( | |
| from_port=0, | |
| to_port=0, | |
| protocol="-1", | |
| cidr_blocks=["0.0.0.0/0"], | |
| )]) | |
| rds = aws.rds.Instance( | |
| database_name, | |
| allocated_storage=allocated_gb_storage, | |
| engine=db_engine, | |
| engine_version=db_engine_version, | |
| instance_class=instance_class, | |
| name=database_name, | |
| password=root_password, | |
| username=root_username, | |
| publicly_accessible=True, | |
| skip_final_snapshot=True, | |
| db_subnet_group_name=subnet_group_name, | |
| vpc_security_group_ids=[security_group.id] | |
| ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment