1 Resposta
- Mais recentes
- Mais votos
- Mais comentários
0
You can do this with Conditions in the template, then test this condition and choose between defining the UserData property with the MySQL or MariaDB install. Something like this:
Conditions:
CreateProdResources: !Equals [!Ref Environment, "prod"]
Then:
UserData: !If [CreateProdResources, !Base64 |
#!/bin/bash
# Install MySQL on production instances
sudo apt-get update
sudo apt install mysql-server -y
sudo systemctl restart mysql
sudo systemctl enable mysql, !Base64 |
# Install MariaDB on development instances
sudo apt-get update
sudo apt install mariadb-server mariadb-client -y
sudo systemctl enable mariadb]
Conteúdo relevante
- AWS OFICIALAtualizada há 2 anos
- AWS OFICIALAtualizada há 2 meses
AWSTemplateFormatVersion: "2010-09-09"
Parameters: Environment: Description: "The environment to deploy to (dev or prod)" Type: String Default: ""
Conditions: CreateProdResources: !Equals [!Ref Environment, "prod"]
Resources: EC2Instance: Type: "AWS::EC2::Instance" Properties: InstanceType: "t2.micro" ImageId: "ami-0f8ca728008ff5af4" KeyName: "devops" SecurityGroupIds: - "sg-02464c840862fddaf" SubnetId: "subnet-0b2bbe1a860c1ec8f" UserData: !If - CreateProdResources - !Base64 | Fn::Sub: | #!/bin/bash
sudo apt-get update sudo apt install mysql-server -y sudo systemctl restart mysql sudo systemctl enable mysql - !Base64 | Fn::Sub: | #!/bin/bash sudo apt-get update sudo apt install mariadb-server mariadb-client -y sudo systemctl enable mariadb Tags: - Key: "Name" Value: !If [CreateProdResources, "${Environment}-prod", "${Environment}-dev"]