From 650f801c1948dcaa5a15a618b697ee008b711ef1 Mon Sep 17 00:00:00 2001 From: Bohdan Mateiko Date: Mon, 16 Dec 2024 13:28:40 +0200 Subject: [PATCH] initial --- .github/workflows/test.yaml | 18 ++++++++++ README.md | 44 +++++++++++++++++++++++- estimate.json | 67 +++++++++++++++++++++++++++++++++++++ tests/test-estimate.ps1 | 66 ++++++++++++++++++++++++++++++++++++ 4 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test.yaml create mode 100644 estimate.json create mode 100644 tests/test-estimate.ps1 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..ff6e19c --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,18 @@ +name: Test + +run-name: ${{ github.actor }} - ${{ github.ref_name }} + +on: + workflow_dispatch: + pull_request: + +jobs: + validate-task: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + + - name: 'Test estimate' + shell: pwsh + run: tests/test-estimate.ps1 + \ No newline at end of file diff --git a/README.md b/README.md index ad52fb6..f3bc3c7 100644 --- a/README.md +++ b/README.md @@ -1 +1,43 @@ -# aws_devops_task_2_estimate_costs \ No newline at end of file +# AWS Essentials: estimate costs + +One of main benefits of the cloud is it's cost effectiveness, that's why it's important to learn how to estimate cloud costs. In this task you will work with AWS pricing calculator to estimate the cost of the Grafana deployment you will be working on over the module. + +## Prerequirements + +Before completing any task in the module, make sure that you followed all the steps described in the **Environment Setup** topic, in particular: + +1. Make sure you have an [AWS](https://aws.amazon.com/free/) account. + +2. Install [aws cli](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) + +3. Install [powershell core](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-7.4) + +4. Install [terraform](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli) + +5. Log in to aws cli on your computer by running command: + ``` + aws configure + ``` + +## Task requirements + +Your Grafana deployment will consist of the following resources: + +- EC2 virtual machine: we will go with 1 t2.micro running Linux; +- For the EC2 we wil need a VPC and 1 Public IP; +- We will also use some S3 storage (**S3 Standard storage**) for Grafana database backups. We will need around 10GB of space, we will do a nigtly upload of DB backups and we will clean up the old backups when we will run out of planned storage space; +- All resources will be deployed to 'eu-central-1' region; +- We will use on-demand pricing witout any reservations; + +To complete this task, you will need to perform the following steps: +1. Use [AWS pricing calculator](https://calculator.aws/) to calculate our cloud infra costs. +2. Export results in JSON format: save it to file, called `estimate.json` in this repository. +3. Run automated test to check yourself. + ``` + pwsh ./tests/test-estimate.ps1 + ``` +If any test fails - please check your estimate and try again. +4. Commit the `estimate.json`, and submit your solution for a review + +| :memo: |Don't be worried about the total cost of infra: if you are using AWS free account - you will get all those resources for free | +|---------------|:--------------------------------------------------------------------------------------------------------------------------------| diff --git a/estimate.json b/estimate.json new file mode 100644 index 0000000..f369dad --- /dev/null +++ b/estimate.json @@ -0,0 +1,67 @@ +{ + "Name": "My Estimate", + "Total Cost": { + "monthly": "13.67", + "upfront": "0.00", + "12 months": "164.04" + }, + "Metadata": { + "Currency": "USD", + "Locale": "en_US", + "Created On": "12/12/2024", + "Legal Disclaimer": "AWS Pricing Calculator provides only an estimate of your AWS fees and doesn't include any taxes that might apply. Your actual fees depend on a variety of factors, including your actual usage of AWS services.", + "Share Url": "https://calculator.aws/#/estimate?id=44e30727acce6185accda025919bf6153f0366a1" + }, + "Groups": { + "Services": [ + { + "Service Name": "Amazon EC2 ", + "Region": "Europe (Frankfurt)", + "Status": "", + "Service Cost": { + "monthly": "9.78", + "upfront": "0.00", + "12 months": "117.38" + }, + "Properties": { + "Tenancy": "Shared Instances", + "Operating system": "Linux", + "Workload": "Consistent, Number of instances: 1", + "Advance EC2 instance": "t2.micro", + "Pricing strategy": "On-Demand Utilization: 100 %Utilized/Month", + "Enable monitoring": "disabled", + "DT Inbound: Not selected": "0 TB per month", + "DT Outbound: Not selected": "0 TB per month", + "DT Intra-Region:": "0 TB per month" + } + }, + { + "Service Name": "Public IPv4 Address", + "Region": "Europe (Frankfurt)", + "Status": "", + "Service Cost": { + "monthly": "3.65", + "upfront": "0.00", + "12 months": "43.80" + }, + "Properties": { + "Number of In-use public IPv4 addresses": "1" + } + }, + { + "Service Name": "S3 Standard", + "Region": "Europe (Frankfurt)", + "Status": "", + "Service Cost": { + "monthly": "0.24", + "upfront": "0.00", + "12 months": "2.88" + }, + "Properties": { + "S3 Standard storage": "10 GB per month", + "S3 Standard Average Object Size": "16 MB" + } + } + ] + } +} \ No newline at end of file diff --git a/tests/test-estimate.ps1 b/tests/test-estimate.ps1 new file mode 100644 index 0000000..70e0a00 --- /dev/null +++ b/tests/test-estimate.ps1 @@ -0,0 +1,66 @@ +$estimatePath = './estimate.json' + +if (Test-Path $estimatePath) { + Write-Output "`u{2705} Checking if estimate file - OK. " +} else { + throw "`u{1F635} Unable to find estimate file. Please make sure that you saved you estimate to a file 'exsimate.json' in this repo and try again. " +} + +$estimate = (Get-Content -Path $estimatePath | ConvertFrom-Json) + +$ec2 = $estimate.Groups.Services | Where-Object {$_.'Service Name' -eq 'Amazon EC2 '} +if ($ec2 -and ($ec2.Count -eq 1 )) { + Write-Output "`u{2705} Checking if EC2 VM is present in the estimate - OK. " +} else { + throw "`u{1F635} Unable to find EC2 VM. Please make sure that you added a EC2 VM (and only one EC2 VM) to the estimate and try again. " +} +if ($ec2.Region -eq 'Europe (Frankfurt)') { + Write-Output "`u{2705} Checking if EC2 VM region in the estimate - OK. " +} else { + throw "`u{1F635} Unable to validate EC2 VM region. Please make sure that you added a EC2 VM to the 'Europe (Frankfurt)' ('eu-central-1') region and try again. " +} +if ($ec2.Properties.'Advance EC2 instance' -eq 't2.micro') { + Write-Output "`u{2705} Checking the EC2 VM size in the estimate - OK. " +} else { + throw "`u{1F635} Unable to validate EC2 VM size. Please make sure that you added a EC2 VM with size 't2.micro' and try again. " +} +if ($ec2.Properties.'Pricing strategy'.Contains('On-Demand Utilization')) { + Write-Output "`u{2705} Checking the EC2 VM prising strategy in the estimate - OK. " +} else { + throw "`u{1F635} Unable to validate EC2 VM pricing strategy. Please make sure that you chose on-demand pricing and try again. " +} +if ($ec2.Properties.'Operating system' -eq 'Linux') { + Write-Output "`u{2705} Checking the EC2 VM operating system in the estimate - OK. " +} else { + throw "`u{1F635} Unable to validate EC2 VM operating system. Please make sure that you added a EC2 VM with Linux operating system and try again. " +} +if ($ec2.Properties.'Operating system' -eq 'Linux') { + Write-Output "`u{2705} Checking the EC2 VM operating system in the estimate - OK. " +} else { + throw "`u{1F635} Unable to validate EC2 VM operating system. Please make sure that you added a EC2 VM with Linux operating system and try again. " +} + + +$ipV4 = $estimate.Groups.Services | Where-Object {$_.'Service Name' -eq 'Public IPv4 Address'} +if ($ipV4 -and ($ipV4.Count -eq 1 )) { + Write-Output "`u{2705} Checking if public IP resource is present in the estimate - OK. " +} else { + throw "`u{1F635} Unable to find Public IP resource in the estimate. Please make sure that you added a VPC with Public IP selected to the estimate and try again. " +} + + +$s3 = $estimate.Groups.Services | Where-Object {$_.'Service Name' -eq 'S3 Standard'} +if ($s3 -and ($s3.Count -eq 1 )) { + Write-Output "`u{2705} Checking if public S3 storage is present in the estimate - OK. " +} else { + throw "`u{1F635} Unable to find S3 storage in the estimate. Please make sure that you added S3 storage to the estimate and try again. " +} +if ($s3.Properties.'S3 Standard storage' -eq '10 GB per month') { + Write-Output "`u{2705} Checking S3 storage capacity in the estimate - OK. " +} else { + throw "`u{1F635} Unable to validate S3 storage capacity. Please make sure that you added 10GB of S3 Standard storage to the estimate and try again. " +} + + +Write-Output "" +Write-Output "`u{1F973} Congratulations! All tests passed!"