Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide script that calls Fastly CLI to rewrite dictionary with current contents of CSV #13

Closed
pnorman opened this issue Dec 6, 2023 · 7 comments

Comments

@pnorman
Copy link
Contributor

pnorman commented Dec 6, 2023

We need to start updating the attribution_blocked_domains dictionary with a shell script to avoid manual work. This script will need to call the fastly CLI.

As far as I can tell, this needs to be done by

  1. calling fastly dictionary describe to get the dictionary ID
  2. Get items with fastly dictionary-entry list
  3. Diff the items against the CSV file
  4. Add any missing, and remove any that have been removed.

It is important that it does not rewrite the entire dictionary contents, as that will remove the date added information which is useful.

See also https://developer.fastly.com/learning/concepts/edge-state/dynamic-config/#edge-dictionaries

@Firefishy
Copy link
Member

Firefishy commented Dec 6, 2023

Rather please move to using terraform-fastly (private repo). Terraform can read the CSV file direct from github if neccessary.

@Firefishy
Copy link
Member

Example:

resource "fastly_service_dictionary_items" "attribution_blocked_domains" {
  dictionary_id = "1EMhjtZi0Mwq5ZcSElM5Gs"
  items = {
    "saverudata.info"        = "LWG email of 2022-08-01"
    "www.impresaitalia.info" = "LWG email of 2022-08-01"
    "www.topozone.com"       = "board request via grischard of 2023-06-29"
  }
  manage_items = true
  service_id   = "3vqMSxvFYqyVOoTY8ti37P"
}

You can literally start just with that in the terraform.

This was referenced Dec 6, 2023
@pnorman
Copy link
Contributor Author

pnorman commented Dec 7, 2023

We don't have terraform ready to go, and no ETA on when it will be ready.

@Firefishy
Copy link
Member

We don't have terraform ready to go, and no ETA on when it will be ready.

I've literally posted the only terraform code that is required above. I've now even made the job easier by publishing JSON which can be used directly by terraform HCL: https://raw.githubusercontent.com/openstreetmap/tile-attribution/main/tile-attribution.json

@Firefishy
Copy link
Member

Firefishy commented Dec 8, 2023

Fully working code:

terraform {

  required_version = "~> 1.5.6"

  required_providers {
    fastly = {
      source  = "fastly/fastly"
      version = ">= 5.4.0"
    }
  }
}

# Configure the Fastly Provider
# Use export FASTLY_API_KEY="afastlyapikey" terraform plan
provider "fastly" {}

data "http" "tile_attribution_data" {
  url = "https://raw.githubusercontent.com/openstreetmap/tile-attribution/main/tile-attribution.json"
}

import {
  id = "3vqMSxvFYqyVOoTY8ti37P/1EMhjtZi0Mwq5ZcSElM5Gs"
  to = fastly_service_dictionary_items.attribution_blocked_domains
}

resource "fastly_service_dictionary_items" "attribution_blocked_domains" {
  dictionary_id = "1EMhjtZi0Mwq5ZcSElM5Gs"
  items         = jsondecode(data.http.tile_attribution_data.response_body)
  manage_items  = true
  service_id    = "3vqMSxvFYqyVOoTY8ti37P"
}

@pnorman
Copy link
Contributor Author

pnorman commented Dec 8, 2023

If it's ready to go, that's good. Closing, and stopping manual updates.

@pnorman pnorman closed this as completed Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants