Skip to content

Commit 81ed7c0

Browse files
committed
initial commit
1 parent 5e0a183 commit 81ed7c0

File tree

18 files changed

+1235
-0
lines changed

18 files changed

+1235
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: golangci-lint
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- main
7+
jobs:
8+
golangci:
9+
name: lint
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: golangci-lint
14+
uses: golangci/golangci-lint-action@v2
15+
with:
16+
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
17+
version: v1.29
18+
19+
# Optional: working directory, useful for monorepos
20+
# working-directory: somedir
21+
22+
# Optional: golangci-lint command line arguments.
23+
# args: --issues-exit-code=0
24+
25+
# Optional: show only new issues if it's a pull request. The default value is `false`.
26+
# only-new-issues: true

.github/workflows/release.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
name: release
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
jobs:
8+
goreleaser:
9+
runs-on: ubuntu-latest
10+
steps:
11+
-
12+
name: Checkout
13+
uses: actions/checkout@v2
14+
-
15+
name: Unshallow
16+
run: git fetch --prune --unshallow
17+
-
18+
name: Set up Go
19+
uses: actions/setup-go@v2
20+
with:
21+
go-version: 1.15
22+
-
23+
name: Import GPG key
24+
id: import_gpg
25+
uses: paultyng/[email protected]
26+
env:
27+
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
28+
PASSPHRASE: ${{ secrets.PASSPHRASE }}
29+
-
30+
name: Run GoReleaser
31+
uses: goreleaser/goreleaser-action@v2
32+
with:
33+
version: latest
34+
args: release --rm-dist
35+
env:
36+
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.terraform/
2+
*tfstate*
3+
terraform-provider-mcbroken

.goreleaser.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Visit https://goreleaser.com for documentation on how to customize this
2+
# behavior.
3+
before:
4+
hooks:
5+
# this is just an example and not a requirement for provider building/publishing
6+
- go mod tidy
7+
builds:
8+
- env:
9+
# goreleaser does not work with CGO, it could also complicate
10+
# usage by users in CI/CD systems like Terraform Cloud where
11+
# they are unable to install libraries.
12+
- CGO_ENABLED=0
13+
mod_timestamp: '{{ .CommitTimestamp }}'
14+
flags:
15+
- -trimpath
16+
ldflags:
17+
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
18+
goos:
19+
- freebsd
20+
- windows
21+
- linux
22+
- darwin
23+
goarch:
24+
- amd64
25+
- '386'
26+
- arm
27+
- arm64
28+
ignore:
29+
- goos: darwin
30+
goarch: '386'
31+
binary: '{{ .ProjectName }}_v{{ .Version }}'
32+
archives:
33+
- format: zip
34+
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
35+
checksum:
36+
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
37+
algorithm: sha256
38+
signs:
39+
- artifacts: checksum
40+
args:
41+
# if you are using this is a GitHub action or some other automated pipeline, you
42+
# need to pass the batch flag to indicate its not interactive.
43+
- "--batch"
44+
- "--local-user"
45+
- "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key
46+
- "--output"
47+
- "${signature}"
48+
- "--detach-sign"
49+
- "${artifact}"
50+
release:
51+
# If you want to manually examine the release before its live, uncomment this line:
52+
# draft: true
53+
changelog:
54+
skip: true

Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
NAMESPACE=circa10a
2+
PROVIDER_NAME=mcbroken
3+
PROVIDER_FULL_PATH=$(REGISTRY)/$(NAMESPACE)/$(PROVIDER_NAME)
4+
PROVIDER_FULL_NAME=terraform-provider-$(PROVIDER_NAME)
5+
PROJECT=$(NAMESPACE)/$(PROVIDER_FULL_NAME)
6+
VERSION=0.1.0
7+
8+
build-mac: PLUGIN_DIR = ~/.terraform.d/plugins/local/provider/$(PROVIDER_NAME)/$(VERSION)/darwin_amd64
9+
build-mac:
10+
test -d $(PLUGIN_DIR) || mkdir -p $(PLUGIN_DIR)
11+
go build -o $(PLUGIN_DIR)/$(PROVIDER_FULL_NAME)
12+
13+
build-linux: PLUGIN_DIR = ~/.terraform.d/plugins/local/provider/$(PROVIDER_NAME)/$(VERSION)/linux_amd64
14+
build-linux:
15+
test -d $(PLUGIN_DIR) || mkdir -p $(PLUGIN_DIR)
16+
go build -o $(PLUGIN_DIR)/$(PROVIDER_FULL_NAME)
17+
18+
lint:
19+
@if ! command -v golangci-lint 1>/dev/null; then\
20+
echo "Need to install golangci-lint";\
21+
exit 1;\
22+
fi;\
23+
golangci-lint run

README.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# terraform-provider-mcbroken <img src="https://i.imgur.com/fAS7XqO.png" height="5%" width="5%" align="left"/>
2+
3+
![Build Status](https://github.com/circa10a/terraform-provider-mcbroken/workflows/release/badge.svg)
4+
[![Go Report Card](https://goreportcard.com/badge/github.com/circa10a/terraform-provider-mcbroken)](https://goreportcard.com/report/github.com/circa10a/terraform-provider-mcbroken)
5+
![GitHub release (latest by date)](https://img.shields.io/github/v/release/circa10a/terraform-provider-mcbroken?style=plastic)
6+
[![Buy Me A Coffee](https://img.shields.io/badge/BuyMeACoffee-Donate-ff813f.svg?logo=CoffeeScript&style=plastic)](https://www.buymeacoffee.com/caleblemoine)
7+
8+
Base the count of your infrastucture resources on the national average of broken mcdonald's ice machines or by a city of your choosing. Powered by [Mcbroken](https://mcbroken.com/).
9+
10+
- [terraform-provider-mcbroken](#terraform-provider-mcbroken)
11+
* [Usage](#usage)
12+
* [Development](#development)
13+
+ [Linting](#linting)
14+
+ [Mac](#mac)
15+
+ [Linux](#linux)
16+
+ [Windows](#windows)
17+
18+
## Usage
19+
20+
```terraform
21+
provider "mcbroken" {}
22+
23+
// Data source to get all available cities/national average of broken ice cream machines
24+
data "mcbroken_cities" "all" {}
25+
// Data source to get current outage percentage of a specific city
26+
data "mcbroken_city" "Dallas" {
27+
city = "Dallas"
28+
}
29+
// If specified city isn't found, returns -1
30+
data "mcbroken_city" "not_found" {
31+
city = "not_found"
32+
}
33+
// Get national average of broken ice cream machines
34+
output "global_broken_average" {
35+
value = data.mcbroken_cities.all.broken
36+
}
37+
// Get list of all cities and their outage percentage
38+
output "all_available_cities" {
39+
value = data.mcbroken_cities.all.cities
40+
}
41+
// Get outage percentage of a specific city
42+
output "user_specified_city" {
43+
value = data.mcbroken_city.Dallas.broken
44+
}
45+
// When user specified city isn't found, return -1
46+
output "user_specified_city_not_found" {
47+
value = data.mcbroken_city.not_found.broken
48+
}
49+
50+
# Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
51+
52+
# Outputs:
53+
54+
# all_available_cities = [
55+
# {
56+
# "broken" = 13.04
57+
# "city" = "New York"
58+
# },
59+
# {
60+
# "broken" = 13.04
61+
# "city" = "San diego"
62+
# },
63+
# {
64+
# "broken" = 12.5
65+
# "city" = "Philadelphia"
66+
# },
67+
# {
68+
# "broken" = 11.11
69+
# "city" = "Boston"
70+
# },
71+
# {
72+
# "broken" = 10.81
73+
# "city" = "Washington"
74+
# },
75+
# {
76+
# "broken" = 10.53
77+
# "city" = "Los Angeles"
78+
# },
79+
# {
80+
# "broken" = 9.88
81+
# "city" = "Chicago"
82+
# },
83+
# {
84+
# "broken" = 8.51
85+
# "city" = "Phoenix"
86+
# },
87+
# {
88+
# "broken" = 8.11
89+
# "city" = "Dallas"
90+
# },
91+
# {
92+
# "broken" = 8.05
93+
# "city" = "Houston"
94+
# },
95+
# {
96+
# "broken" = 7.41
97+
# "city" = "San Jose"
98+
# },
99+
# {
100+
# "broken" = 6.67
101+
# "city" = "San Francisco"
102+
# },
103+
# {
104+
# "broken" = 3.77
105+
# "city" = "San antonio"
106+
# },
107+
# {
108+
# "broken" = 0
109+
# "city" = "Seattle"
110+
# },
111+
# ]
112+
# global_broken_average = 7.45
113+
# user_specified_city = 8.11
114+
# user_specified_city_not_found = -1
115+
```
116+
117+
## Development
118+
119+
### Linting
120+
121+
```bash
122+
make lint
123+
```
124+
125+
### Mac
126+
127+
```bash
128+
make build-mac && \
129+
cd examples && \
130+
terraform init && \
131+
terraform apply
132+
```
133+
134+
### Linux
135+
136+
```bash
137+
make build-linux && \
138+
cd examples && \
139+
terraform init && \
140+
terraform apply
141+
```
142+
143+
### Windows
144+
145+
![alt text](https://media.giphy.com/media/4cuyucPeVWbNS/giphy.gif)

docs/data-sources/cities.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# mcbroken_cities Data Source
2+
3+
Data source to get all available cities/national average of broken ice cream machines
4+
5+
## Example Usage
6+
7+
```hcl
8+
data "mcbroken_cities" "all" {}
9+
10+
// Get national average of broken ice cream machines
11+
output "global_broken_average" {
12+
value = data.mcbroken_cities.all.broken
13+
}
14+
15+
// Get list of all cities and their outage percentage
16+
output "all_available_cities" {
17+
value = data.mcbroken_cities.all.cities
18+
}
19+
```
20+
21+
## Argument Reference
22+
23+
None
24+
25+
## Attribute Reference
26+
27+
* `cities` - List of maps that contains cities and their broken ice machine average
28+
* `broken` - National average of broken ice cream machines

docs/data-sources/city.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# mcbroken_city Data Source
2+
3+
// Get outage percentage of a specific city
4+
5+
## Example Usage
6+
7+
```hcl
8+
// Data source to get current outage percentage of a specific city
9+
data "mcbroken_city" "Dallas" {
10+
city = "Dallas"
11+
}
12+
13+
// Get outage percentage of a specific city
14+
output "user_specified_city" {
15+
value = data.mcbroken_city.Dallas.broken
16+
}
17+
18+
// If specified city isn't found, returns -1
19+
data "mcbroken_city" "not_found" {
20+
city = "not_found"
21+
}
22+
23+
// When user specified city isn't found, return -1
24+
output "user_specified_city_not_found" {
25+
value = data.mcbroken_city.not_found.broken
26+
}
27+
```
28+
29+
## Argument Reference
30+
31+
* `city` - (Required) Name of city to get percentage of broken ice cream machines
32+
33+
## Attribute Reference
34+
35+
* `broken` - Percentage of broken ice cream machines in the user specified city. `-1` if no data

0 commit comments

Comments
 (0)