11PSWattTime
22==========
33
4- PowerShell Module for getting PSWattTime emission data
5- ------------------------------------------------------
4+ PowerShell Module for PSWattTime emission data
5+ ----------------------------------------------
66
77[ ![ PowerShell Module Quality Assurance] ( https://github.com/cloudyspells/PSWattTime/actions/workflows/qa.yml/badge.svg )] ( https://github.com/cloudyspells/PSWattTime/actions/workflows/qa.yml )
88
99This PowerShell module is intended for retrieving emissions
1010data from [ WattTime] ( https://www.watttime.org/ ) for a
11- supplied Azure Region.
11+ supplied Azure Region during resource deployments.
12+ This is a lightweight solution making use of only the limited
13+ functionality available with a free account at _ WattTime_ .
14+ This means the module is only able to get near-realtime
15+ emissions data and no prodictive values. This means this module is
16+ _ not_ a real solution for reduced carbon deployments and -software.
17+ It _ does_ however provide some nice realtime values so you can
18+ simulate the beheaviour of deployments and software based on emissions
19+ data without the cost of a paid account for such data. For example in
20+ lab- or proof of concept environments.
21+
22+ The intended use of this module is for setting the ` Location ` parameter
23+ on Azure IaC deployments in GitHub workflows using the included GitHub
24+ action.
25+
26+ For a real-world solution with a commercial data provider, check out
27+ the [ carbon-aware-sdk] ( https://github.com/Green-Software-Foundation/carbon-aware-sdk )
28+ by the [ Green Software Foundation] ( https://greensoftware.foundation/ )
1229
1330This module is supplied as-is at the moment and not (yet)
1431published through _ PSGallery_ .
@@ -18,31 +35,32 @@ published through _PSGallery_.
1835#### PowerShell Module
1936
2037To get started with this module you will need an account on
21- [ WattTime] ( https://www.watttime.org/ ) . See
38+ [ WattTime] ( https://www.watttime.org/ ) . See
2239[ the manual] ( https://www.watttime.org/api-documentation/#register-new-user )
2340on registering an account. NOTE: You can only register via the API.
24- Currently no GUI exists for registration.
41+ Currently no GUI exists for registration.
2542
2643You will also need the _ Az.Resources_ PowerShell Module for Azure installed
27- and connected to your Azure account. See
28- [ the installation manual] ( https://learn.microsoft.com/en-us/powershell/azure/install-az-ps ) for the _ Az_ module for instructions.
44+ and connected to your Azure account. See
45+ [ the installation manual] ( https://learn.microsoft.com/en-us/powershell/azure/install-az-ps )
46+ for the _ Az_ module for instructions.
2947
3048
3149Import the module from a clone of this repository:
3250
33- ```
51+ ``` powershell
3452Import-Module .\src\PSWattTime
3553```
3654
3755Authenticate to the _ WattTime_ API:
3856
39- ```
57+ ``` powershell
4058 $token = Get-WattTimeAuthToken -Username '<YOUR_WATTTIME_USERNAME>' -Password '<YOUR_WATTTIME_PASSWORD>'
4159```
4260
4361Get current percentage of energy with emissions the 'westeurope' Azure region:
4462
45- ```
63+ ``` powershell
4664PS C:\> Get-WattTimeForAzureRegion -Region westeurope -AuthToken $token
4765
4866ba : NL
@@ -56,7 +74,7 @@ region : westeurope
5674Determine the lowest emissions for the list of northeurope,
5775westeurope, francecentral and uksouth Azure regions:
5876
59- ```
77+ ``` powershell
6078PS C:\> Get-AzureRegionWithLowestWattTime -Regions westeurope,uksouth,northeurope,francecentral -AuthToken $token
6179
6280ba : IE
@@ -73,7 +91,7 @@ This PowerShell module also comes with a _GitHub Action_ you can use
7391in your GitHub workflows. Again you will need a pre-existing account
7492for _ WattTime_ and an Azure CLI/PowerShell secret configured in your repo
7593
76- ** Example**
94+ ##### Example
7795
7896``` yaml
7997
@@ -92,26 +110,26 @@ jobs:
92110 - name : Checkout
93111 uses : actions/checkout@v3
94112
95- - name : Login to Az PowerShell Module
96- uses : azure/login@v1
97- with :
98- creds : ${{ secrets.AZURE_CREDENTIALS }}
99- enable-AzPSSession : true
100-
101113 - name : Get region with lowest emissions
102114 uses : cloudyspells/PSWattTime@main
103- id : watttime_action
115+ id : watttime_action # Set step id for using output in deployment
104116 with :
105117 azure_credential : ${{ secrets.AZURE_CREDENTIALS }}
106118 watttime_username : ${{ secrets.WATTTIMEUSERNAME }}
107119 watttime_password : ${{ secrets.WATTTIMEPASSWORD }}
108120 regions : ' "westeurope","northeurope","uksouth","francecentral","germanynorth"'
109121
122+ - name : Login to Az PowerShell Module
123+ uses : azure/login@v1
124+ with :
125+ creds : ${{ secrets.AZURE_CREDENTIALS }}
126+ enable-AzPSSession : true
127+
110128 - uses : azure/arm-deploy@v1
111129 name : Run Bicep deployment
112130 with :
113131 subscriptionId : ${{ secrets.AZURE_SUBSCRIPTION_ID }}
114132 scope : subscription
115- region : ${{ steps.watttime_action.outputs.region }}
133+ region : ${{ steps.watttime_action.outputs.region }} # The region output from PSWattTime
116134 template : src/bicep/main.bicep
117135` ` `
0 commit comments