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

[WIP] New Resource: cloudflare_spectrum_app #156

Merged
merged 2 commits into from
Jan 11, 2019

Conversation

ewilde
Copy link
Contributor

@ewilde ewilde commented Nov 17, 2018

Work in progress this PR is to add a new resource to automate cloudflare spectrum applications

Relates to #155

TODO

Test results

resource cloudflare_spectrum_app

GOROOT=/usr/lib/go-1.10 #gosetup
GOPATH=/home/ewilde/data/go #gosetup
/usr/lib/go-1.10/bin/go test -c -i -o /tmp/___resource_cloudflare_spectrum_app_test_go github.com/terraform-providers/terraform-provider-cloudflare/cloudflare #gosetup
/usr/lib/go-1.10/bin/go tool test2json -t /tmp/___resource_cloudflare_spectrum_app_test_go -test.v -test.run "^TestAccCloudflareSpectrumApplication_Basic|TestAccCloudflareSpectrumApplication_Update|TestAccCloudflareSpectrumApplication_CreateAfterManualDestroy$" #gosetup
=== RUN   TestAccCloudflareSpectrumApplication_Basic
--- PASS: TestAccCloudflareSpectrumApplication_Basic (4.91s)
=== RUN   TestAccCloudflareSpectrumApplication_Update
--- PASS: TestAccCloudflareSpectrumApplication_Update (8.10s)
=== RUN   TestAccCloudflareSpectrumApplication_CreateAfterManualDestroy
--- PASS: TestAccCloudflareSpectrumApplication_CreateAfterManualDestroy (6.77s)
PASS

Process finished with exit code 0

data cloudflare_zone

GOROOT=/usr/lib/go-1.10 #gosetup
GOPATH=/home/ewilde/data/go #gosetup
/usr/lib/go-1.10/bin/go test -c -i -o /tmp/___data_source_zone_test_go github.com/terraform-providers/terraform-provider-cloudflare/cloudflare #gosetup
/usr/lib/go-1.10/bin/go tool test2json -t /tmp/___data_source_zone_test_go -test.v -test.run ^TestAccCloudflareZone$ #gosetup
=== RUN   TestAccCloudflareZone
--- PASS: TestAccCloudflareZone (1.60s)
PASS

Process finished with exit code 0

Import

=== RUN   TestAccCloudflareSpectrumApp_Import
=== PAUSE TestAccCloudflareSpectrumApp_Import
=== CONT  TestAccCloudflareSpectrumApp_Import
--- PASS: TestAccCloudflareSpectrumApp_Import (3.69s)
PASS

Process finished with exit code 0

Website

make website-test

/home/ewilde/data/go/src/github.com/hashicorp/terraform-website/content/scripts/check-links.sh "http://127.0.0.1:4567/docs/providers/cloudflare/"
2018-11-19 14:29:41 URL:http://127.0.0.1:4567/docs/providers/cloudflare/ [30474/30474] -> "index.html.tmp.tmp" [1]
2018-11-19 14:29:41 URL:http://127.0.0.1:4567/robots.txt [44/44] -> "robots.txt.tmp" [1]
2018-11-19 14:29:41 URL:http://127.0.0.1:4567/docs/providers/cloudflare/index.html [30474/30474] -> "index.html.tmp.tmp" [1]
2018-11-19 14:29:41 URL:http://127.0.0.1:4567/docs/providers/cloudflare/d/ip_ranges.html [28144/28144] -> "ip_ranges.html.tmp.tmp" [1]
2018-11-19 14:29:41 URL:http://127.0.0.1:4567/docs/providers/cloudflare/d/zone.html [28532/28532] -> "zone.html.tmp.tmp" [1]
2018-11-19 14:29:41 URL:http://127.0.0.1:4567/docs/providers/cloudflare/r/access_application.html [28666/28666] -> "access_application.html.tmp.tmp" [1]
2018-11-19 14:29:41 URL:http://127.0.0.1:4567/docs/providers/cloudflare/r/access_policy.html [32425/32425] -> "access_policy.html.tmp.tmp" [1]
2018-11-19 14:29:41 URL:http://127.0.0.1:4567/docs/providers/cloudflare/r/access_rule.html [33161/33161] -> "access_rule.html.tmp.tmp" [1]
2018-11-19 14:29:41 URL:http://127.0.0.1:4567/docs/providers/cloudflare/r/account_member.html [28646/28646] -> "account_member.html.tmp.tmp" [1]
2018-11-19 14:29:41 URL:http://127.0.0.1:4567/docs/providers/cloudflare/r/custom_pages.html [29692/29692] -> "custom_pages.html.tmp.tmp" [1]
2018-11-19 14:29:41 URL:http://127.0.0.1:4567/docs/providers/cloudflare/r/filter.html [29840/29840] -> "filter.html.tmp.tmp" [1]
2018-11-19 14:29:41 URL:http://127.0.0.1:4567/docs/providers/cloudflare/r/firewall_rule.html [31002/31002] -> "firewall_rule.html.tmp.tmp" [1]
2018-11-19 14:29:41 URL:http://127.0.0.1:4567/docs/providers/cloudflare/r/load_balancer.html [33943/33943] -> "load_balancer.html.tmp.tmp" [1]
2018-11-19 14:29:42 URL:http://127.0.0.1:4567/docs/providers/cloudflare/r/load_balancer_monitor.html [31101/31101] -> "load_balancer_monitor.html.tmp.tmp" [1]
2018-11-19 14:29:42 URL:http://127.0.0.1:4567/docs/providers/cloudflare/r/load_balancer_pool.html [31987/31987] -> "load_balancer_pool.html.tmp.tmp" [1]
2018-11-19 14:29:42 URL:http://127.0.0.1:4567/docs/providers/cloudflare/r/page_rule.html [34666/34666] -> "page_rule.html.tmp.tmp" [1]
2018-11-19 14:29:42 URL:http://127.0.0.1:4567/docs/providers/cloudflare/r/rate_limit.html [35649/35649] -> "rate_limit.html.tmp.tmp" [1]
2018-11-19 14:29:42 URL:http://127.0.0.1:4567/docs/providers/cloudflare/r/record.html [30345/30345] -> "record.html.tmp.tmp" [1]
2018-11-19 14:29:42 URL:http://127.0.0.1:4567/docs/providers/cloudflare/r/spectrum_app.html [30151/30151] -> "spectrum_app.html.tmp.tmp" [1]
2018-11-19 14:29:42 URL:http://127.0.0.1:4567/docs/providers/cloudflare/r/waf_rule.html [28514/28514] -> "waf_rule.html.tmp.tmp" [1]
2018-11-19 14:29:42 URL:http://127.0.0.1:4567/docs/providers/cloudflare/r/worker_route.html [31257/31257] -> "worker_route.html.tmp.tmp" [1]
2018-11-19 14:29:42 URL:http://127.0.0.1:4567/docs/providers/cloudflare/r/worker_script.html [30246/30246] -> "worker_script.html.tmp.tmp" [1]
2018-11-19 14:29:42 URL:http://127.0.0.1:4567/docs/providers/cloudflare/r/zone.html [29589/29589] -> "zone.html.tmp.tmp" [1]
2018-11-19 14:29:42 URL:http://127.0.0.1:4567/docs/providers/cloudflare/r/zone_lockdown.html [31058/31058] -> "zone_lockdown.html.tmp.tmp" [1]
2018-11-19 14:29:42 URL:http://127.0.0.1:4567/docs/providers/cloudflare/r/zone_settings_override.html [37775/37775] -> "zone_settings_override.html.tmp.tmp" [1]
Found no broken links.

FINISHED --2018-11-19 14:29:42--
Total wall clock time: 0.7s
Downloaded: 25 files, 730K in 0.04s (15.9 MB/s)
tf-website-cloudflare-temp
make[1]: Leaving directory '/home/ewilde/data/go/src/github.com/hashicorp/terraform-website'

cloudflare_specturm_app

image

data cloudflare_zone

image

@ghost ghost added the size/S label Nov 17, 2018
@jacobbednarz
Copy link
Member

jacobbednarz commented Nov 17, 2018 via email

@ewilde ewilde closed this Nov 18, 2018
@ghost ghost added size/XS and removed size/S labels Nov 18, 2018
@ewilde ewilde reopened this Nov 18, 2018
@ghost ghost added size/XL and removed size/XS labels Nov 19, 2018
@ghost ghost added size/XXL and removed size/XL labels Nov 19, 2018
@ewilde ewilde changed the title [WIP] New Resource: cloudflare_spectrum_app New Resource: cloudflare_spectrum_app Nov 19, 2018
@ewilde
Copy link
Contributor Author

ewilde commented Nov 19, 2018

@jacobbednarz this PR is ready for review (failing CI pending merge of cloudflare/cloudflare-go#253)

Copy link
Member

@jacobbednarz jacobbednarz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an awesome start! Some comments/discussions inline.

"regexp"
)

func dataSourceCloudflareZone() *schema.Resource {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little uncertain on whether a data source for a zone is needed as I would have expected that should you need the details, you would have defined the resource already.

Copy link
Contributor Author

@ewilde ewilde Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jacobbednarz, great question. I should have put some context around this in the PR text. Actually we don't plan to manage the zone resource in the same terraform project. We prefer to delegate permission to that important resource to another project, which is only accessible to a team with a different set of credentials. This is why i thought the datasource would be so useful. It's how we currently manage our route53, using a datasource to lookup the zone_id and then passing that when creating related resources

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very interesting (and sensible!) use case. I'm 👌 with this approach given the context.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the idea of Zone data source, in fact I've been asked for the same thing internally (a list of zones currently added to an account), but let's pull this out of this PR and create a separate PR.

1 PR == 1 feature

cloudflare/provider.go Outdated Show resolved Hide resolved
cloudflare/resource_cloudflare_spectrum_app.go Outdated Show resolved Hide resolved
cloudflare/resource_cloudflare_spectrum_app.go Outdated Show resolved Hide resolved
cloudflare/resource_cloudflare_spectrum_app.go Outdated Show resolved Hide resolved
website/docs/r/spectrum_app.html.markdown Outdated Show resolved Hide resolved
website/docs/r/spectrum_app.html.markdown Outdated Show resolved Hide resolved
website/docs/d/zone.html.md Outdated Show resolved Hide resolved
website/docs/d/zone.html.md Outdated Show resolved Hide resolved
website/docs/r/spectrum_app.html.markdown Outdated Show resolved Hide resolved
@ewilde
Copy link
Contributor Author

ewilde commented Nov 20, 2018

@jacobbednarz thanks for the review, I've hopefully addressed all the comments corrects and marked the conversations as resolved with a comment

Type: schema.TypeString,
},
},
"meta": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you determine where to draw the line with the fields here? I noticed there are a few missing from our enterprise accounts and was curious if it was intended. Happy to provide an anonymised output if you don't have visibility into the full listing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the attributes from the resource_cloudflare_zone, these look reasonable for a first attempt

@ewilde
Copy link
Contributor Author

ewilde commented Nov 21, 2018

@jacobbednarz thanks for another review 😄 all suggestions should be pushed now

Copy link
Member

@jacobbednarz jacobbednarz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine to me, great job! 🌟

There are a bunch of unrelated changes in this PR but I suspect it's a side effect of you force pushing and not rebasing/merging in the changes without fast forwarding that is causing them to show up in here.

@ghost ghost added size/XL and removed size/XXL labels Nov 22, 2018
@ewilde
Copy link
Contributor Author

ewilde commented Nov 22, 2018

@jacobbednarz I've rebased against master, there shouldn't be anything here that's not part of the PR

@ewilde ewilde changed the title New Resource: cloudflare_spectrum_app [WIP] - New Resource: cloudflare_spectrum_app Nov 22, 2018
@ewilde ewilde changed the title [WIP] - New Resource: cloudflare_spectrum_app New Resource: cloudflare_spectrum_app Nov 22, 2018
@ewilde ewilde changed the title New Resource: cloudflare_spectrum_app [WIP] New Resource: cloudflare_spectrum_app Nov 23, 2018
Copy link
Contributor

@patryk patryk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add import section in documentation, please?

zoneName = idAttr[0]
applicationID = idAttr[1]
} else {
return nil, fmt.Errorf("invalid id (\"%s\") specified, should be in format \"zoneName/applicationID\"", d.Id())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use Zone ID instead of name here?

testAccCheckCloudflareSpectrumApplicationIDIsValid(name),
resource.TestCheckResourceAttr(name, "protocol", "tcp/22"),
resource.TestCheckResourceAttr(name, "origin_direct.#", "1"),
resource.TestCheckResourceAttr(name, "origin_direct.0", "tcp://120.120.102.10:23"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use reserved IP address, instead of random public one.
See: https://en.wikipedia.org/wiki/Reserved_IP_addresses

Suggested change
resource.TestCheckResourceAttr(name, "origin_direct.0", "tcp://120.120.102.10:23"),
resource.TestCheckResourceAttr(name, "origin_direct.0", "tcp://192.0.2.1:23"),

Check: resource.ComposeTestCheckFunc(
testAccCheckCloudflareSpectrumApplicationExists(name, &spectrumApp),
testAccCheckCloudflareSpectrumApplicationIDIsValid(name),
resource.TestCheckResourceAttr(name, "origin_direct.0", "tcp://120.120.102.10:23"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use reserved IP here.

Suggested change
resource.TestCheckResourceAttr(name, "origin_direct.0", "tcp://120.120.102.10:23"),
resource.TestCheckResourceAttr(name, "origin_direct.0", "tcp://192.0.2.1:23"),

}
return nil
},
resource.TestCheckResourceAttr(name, "origin_direct.0", "tcp://81.120.102.10:23"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use reserved IP here.

Suggested change
resource.TestCheckResourceAttr(name, "origin_direct.0", "tcp://81.120.102.10:23"),
resource.TestCheckResourceAttr(name, "origin_direct.0", "tcp://192.0.2.2:23"),

"name" = "ssh.${data.cloudflare_zone.test.zone}"
}

origin_direct = ["tcp://81.120.102.10:23"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
origin_direct = ["tcp://81.120.102.10:23"]
origin_direct = ["tcp://192.0.2.2:23"]


## Argument Reference

* `protocol` - (Required) The port configuration at Cloudflare’s edge. i.e. `tcp/22`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `protocol` - (Required) The port configuration at Cloudflare’s edge. i.e. `tcp/22`.
* `protocol` - (Required) The port configuration at Cloudflare’s edge. e.g. `tcp/22`.


* `protocol` - (Required) The port configuration at Cloudflare’s edge. i.e. `tcp/22`.
* `dns` - (Required) The name and type of DNS record for the Spectrum application. Fields documented below.
* `origin_direct` - (Optional) A list of destination addresses to the origin. i.e. `tcp://192.0.2.1:22`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `origin_direct` - (Optional) A list of destination addresses to the origin. i.e. `tcp://192.0.2.1:22`.
* `origin_direct` - (Optional) A list of destination addresses to the origin. e.g. `tcp://192.0.2.1:22`.

* `dns` - (Required) The name and type of DNS record for the Spectrum application. Fields documented below.
* `origin_direct` - (Optional) A list of destination addresses to the origin. i.e. `tcp://192.0.2.1:22`.
* `origin_dns` - (Optional) A destination DNS addresses to the origin. Fields documented below.
* `origin_port` - (Optional) If using `origin_dns` this is a required attribute. Origin port to proxy traffice to i.e. `22`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `origin_port` - (Optional) If using `origin_dns` this is a required attribute. Origin port to proxy traffice to i.e. `22`.
* `origin_port` - (Optional) If using `origin_dns` this is a required attribute. Origin port to proxy traffice to e.g. `22`.


**origin_dns**

* `name` - (Required) Fully qualified domain name of the origin i.e. origin-ssh.example.com.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `name` - (Required) Fully qualified domain name of the origin i.e. origin-ssh.example.com.
* `name` - (Required) Fully qualified domain name of the origin e.g. origin-ssh.example.com.

@patryk patryk self-assigned this Jan 11, 2019
@ghost ghost added the kind/documentation Categorizes issue or PR as related to documentation. label Jan 11, 2019
@patryk patryk merged commit 2c7bd43 into cloudflare:master Jan 11, 2019
@patryk
Copy link
Contributor

patryk commented Jan 11, 2019

Thanks @ewilde !

@ewilde
Copy link
Contributor Author

ewilde commented Jan 11, 2019

@patryk thanks for the review and merge, but think the tests will need updating to use the plural zones data source, this pr was still using the single zone data source to bootstrap some of the integration tests

@ewilde
Copy link
Contributor Author

ewilde commented Jan 11, 2019

ill do this now

@patryk
Copy link
Contributor

patryk commented Jan 11, 2019

Oh yes, please do.

boekkooi-lengoo pushed a commit to boekkooi-lengoo/terraform-provider-cloudflare that referenced this pull request Feb 28, 2022
* The upcoming Purge by Host functionality has been added to the library
* flarectl now has a `purge` sub-command for purging from cache.

e.g
```
# Purge by host (upcoming)
flarectl zone purge --zone=example.com --hosts="repeater.example.com"

# Purge everything 
flarectl zone purge --zone=example.com --everything

# Purge by filename 
flarectl zone purge --zone=example.com \
  --files="http://repeater.example.com/styles.css,http://repeater.example.com/javascript.js"
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/documentation Categorizes issue or PR as related to documentation. size/XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants