Skip to content

Instantly share code, notes, and snippets.

@ricardochaves
Created November 6, 2019 21:31
Show Gist options
  • Save ricardochaves/8b00c135ff16686453d0934bfaf8649e to your computer and use it in GitHub Desktop.
Save ricardochaves/8b00c135ff16686453d0934bfaf8649e to your computer and use it in GitHub Desktop.
Recipe for Google Deployment Manager
import uuid
def GenerateConfig(context):
"""Generate YAML resource configuration."""
sql_zone = context.properties["SQL_ZONE"]
sql_name = str(uuid.uuid4().hex)
db_name = context.properties["DB_NAME"]
user_name = context.properties["USER_NAME"]
user_password = context.properties["USER_PASSWORD"]
resources = []
resources.append(
{
"name": sql_name,
"type": "sqladmin.v1beta4.instance",
"properties": {
"databaseVersion": "POSTGRES_11",
"settings": {
"tier": "db-f1-micro",
"locationPreference": {"zone": sql_zone},
"ipConfiguration": {
"privateNetwork": "https://www.googleapis.com/compute/v1/projects/my-project-dev/global/networks/default"
},
},
},
}
)
resources.append(
{
"name": db_name,
"type": "sqladmin.v1beta4.database",
"properties": {"instance": "$(ref." + sql_name + ".name)", "charset": "UTF8"},
}
)
resources.append(
{
"name": user_name,
"type": "sqladmin.v1beta4.user",
"properties": {"instance": "$(ref." + sql_name + ".name)", "password": user_password, "host":"$(ref." + db_name + ".name)" },
}
)
outputs = []
outputs.append({"name": "ipAddresses", "value": "$(ref." + sql_name + ".ipAddresses[0].ipAddress)"})
outputs.append({"name": "name", "value": sql_name})
return {"resources": resources, "outputs": outputs}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment