Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
DEV-289: Tutorial Revamp (#13)
Browse files Browse the repository at this point in the history
* updated api to working example

* Added working examples for new weather API

* Added working examples for new weather API

* reset 01-geodesic

* reset 01-geodesic
  • Loading branch information
milldr authored Oct 10, 2022
1 parent 1909e5e commit d1ae5aa
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 36 deletions.
39 changes: 14 additions & 25 deletions 02-atmos/components/terraform/fetch-weather/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
variable "date" {
default = null
type = string
description = "The date to retrieve weather data for."
variable "hourly_forecast" {
type = bool
description = "Whether or not to retrieve hourly weather data"
default = false
}

data "terraform_remote_state" "location" {
Expand All @@ -13,43 +13,32 @@ data "terraform_remote_state" "location" {
}

locals {
# Pulls Longitude and Latitude from the Remote State of fetch-location
users_location_map = data.terraform_remote_state.location.outputs.users_location_map
lat = local.users_location_map.lat
lon = local.users_location_map.lon

lat = local.users_location_map.lat
lon = local.users_location_map.lon
# Curls Weather API for Location Data
location_url = "https://api.weather.gov/points/${local.lat},${local.lon}"
location_data = jsondecode(data.http.fetch_location.body).properties

location_url = "https://www.metaweather.com/api/location/search/?lattlong=${local.lat},${local.lon}"

location_id = local.location_data[0].woeid
weather_base_url = "https://www.metaweather.com/api/location"
weather_url = var.date != null ? "${local.weather_base_url}/${local.location_id}/${var.date}" : "${local.weather_base_url}/${local.location_id}/"

location_data = jsondecode(data.http.fetch_location.body)
full_weather_data = jsondecode(data.http.fetch_weather.body)

selected_weather_data = var.date != null ? local.full_weather_data[0] : local.full_weather_data.consolidated_weather[0]
# Curls Weather API for Forecast Data
weather_url = (var.hourly_forecast) ? local.location_data.forecastHourly : local.location_data.forecast
weather_data = jsondecode(data.http.fetch_weather.body).properties.periods[0]
}

data "http" "fetch_location" {
url = local.location_url

request_headers = {
Accept = "application/json"
}
}

data "http" "fetch_weather" {
url = local.weather_url

request_headers = {
Accept = "application/json"
}
}

output "location_data" {
value = local.location_data
}

output "weather_data" {
value = local.selected_weather_data
value = local.weather_data
}
14 changes: 9 additions & 5 deletions 02-atmos/components/terraform/output-results/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,22 @@ locals {
users_location = data.terraform_remote_state.location.outputs.users_location

weather_data = data.terraform_remote_state.weather.outputs.weather_data
weather_date = local.weather_data.applicable_date
weather_temp = local.weather_data.the_temp
weather_description = local.weather_data.weather_state_name
weather_start_time = local.weather_data.startTime
weather_end_time = local.weather_data.endTime
weather_temp = local.weather_data.temperature
weather_temp_unit = local.weather_data.temperatureUnit
weather_description = local.weather_data.shortForecast
}

data "template_file" "weather_report" {
template = file("${path.root}/weather-report.tpl")
vars = {
users_location = local.users_location
weather_temp = local.weather_temp
weather_temp_unit = local.weather_temp_unit
weather_description = local.weather_description
weather_date = local.weather_date
weather_start_time = local.weather_start_time
weather_end_time = local.weather_end_time
}
}

Expand All @@ -60,7 +64,7 @@ output "weather_description" {
}

output "weather_date" {
value = local.weather_date
value = "${local.weather_start_time} through ${local.weather_end_time}"
}

output "weather_report" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=== Your Weather Report ===
============================
Location: ${users_location}
Temperature: ${weather_temp}°
Temperature: ${weather_temp}°${weather_temp_unit}
Weather: ${weather_description}
Date: ${weather_date}
============================
Time: ${weather_start_time} to ${weather_end_time}
============================
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ARG VERSION=latest
ARG OS=debian
ARG CLI_NAME=tutorials
ARG TF_1_VERSION=1.3.0

FROM cloudposse/geodesic:$VERSION-$OS

Expand All @@ -13,10 +14,11 @@ RUN apt-get install -y software-properties-common && \
apt-get install -y golang-petname


ARG TF_1_VERSION
# Install terraform.
RUN apt-get update && apt-get install -y -u terraform-0.14
# Set Terraform 0.14.x as the default `terraform`.
RUN update-alternatives --set terraform /usr/share/terraform/0.14/bin/terraform
RUN apt-get update && apt-get install -y -u --allow-downgrades \
terraform-1="${TF_1_VERSION}-*" && \
update-alternatives --set terraform /usr/share/terraform/1/bin/terraform

# Install Atmos
RUN apt-get install -y --allow-downgrades \
Expand Down

0 comments on commit d1ae5aa

Please sign in to comment.