Stick with your learning though, it does eventually get clearer the more you experiment.Whatever your reason for needing a simple AWS web server setup, thats what well be covering today.
Well cover all of the fiddly AWS details like AMIs and user data scripts. Youll notice in the above example Ive removed a lot of code (which mainly was the userdata property). Well cover what the userdata property does soon, but for now lets focus on the EC2 instance block. You can only execute this resource when youve installed the AWS provider (so make sure you have that setup first). The AMI property stands for Amazon Machine Image (AMI), which is the underlying base machine that our EC2 is created upon. But, hardcoding AMIs is to be avoided if you want to eventually run this configuration in production. Instead youll want to dynamically grab your AMI using the awsami resource block. But rather than do it manually, we want our instance to automatically start itself once its deployed, and thats done by usage of the user data script. In our script we install Apache, create a basic web page and then start apache. These characters simply allow us to put multiline strings into terraform configurations, in our case, thats our putting our bash script into user data. This tells our interpreter that we want to execute our script using bash. We create our website as a small HTML string, and outputting it to the varwww directorywhich is the default location for files on an apache web server. We start our server using the global binary systemctl which we installed with yum in the last step. Outputs are easy ways to expose values that can be consumed in other configurations, or in our case just make an easy way to see a simple output when we run our terraform apply command. In our case our name is DNS and were pointing our variable to a returned values of our instance, in our case the public DNS entry. Terraform Aws Example Free To OmitBut in our case the output block is optional, so feel free to omit it if you dont feel you need it. Now lets move onto the practicalities of executing it, and what you should see in AWS when youve executed your configuration. Because we didnt define things like subnets, security groups and mounted volumes AWS takes a best guess at what we want to set these values to, using things like default resources. Note the URL at the bottom, which is thanks to our output block. The small instances cost about 10 dollars per month, but thats money you can put elsewhere. This setup can be used to create a basic website, or in my case you can use it for experimenting with different AWS features, such as exploring how load balancing works, or DNS failover.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |