Skip to content

Commit

Permalink
Changes for v1.0.0 (#532) (#534)
Browse files Browse the repository at this point in the history
* Changes for v1.0.0 (#532)

* V1 versionless deletion protection (#110)

* Add DiffSuppressFunc to optionally suppress all diffs on ACL entries

Adds a manage_entries attribute which defaults to false. Then a
DiffSuppressFunc reads this and decides whether to suppress the diff on
the entries set. By default this then only applies the changes on create
and does nothing the rest of the time, unless the user sets
manage_entries to true manually, then it behaves as usual. This is to
make the resource safer by default in the event that entries are added
to the ACL outside of Terraform, so that they aren't accidentally
deleted.

* Add acceptance tests for manage_entries attribute

* Add DiffSuppressFunc manage_entries to dictionary items as well

Same change as for the ACL entries resource, but for the dictionary
items.

* Run make generate-docs

* add a missing argument

* re-generate docs

Co-authored-by: Ben Gesoff <[email protected]>
Co-authored-by: Hieu Doan <[email protected]>

* Make backend `auto_loadbalance` default to false (#111)

The Fastly web interface defaults "Auto load balance" to "No". The most
common reason for having multiple backends in a single service is to
route different paths to different backends, rather than load balance
between different origins. Currently, this provider defaults
`auto_loadbalance` to true, which is surprising and confusing. This
commit makes `auto_loadbalance` default to false to reduce confusion.

Co-authored-by: Ben Gesoff <[email protected]>
Co-authored-by: Hieu Doan <[email protected]>

* V1 update default format and format version (#112)

* Update default values for format & format_version

* Update format & format_version in docs and doc strings

* Cosmetic change: capitilise Default

* Update format & format_version in tests

* Fix 'format' for papertail

* add FormatVersion for the GCS struct

* update gcslogging doc with format_version

* change double quotes to backticks

Co-authored-by: Hieu Doan <[email protected]>

* V1 change email to user in gcslogging (#113)

* Change the email field to user to align with the API docs.

* fix TestGcsloggingEnvDefaultFuncAttributes by using the user attribute

* fix TestResourceFastlyFlattenGCS

* go fmt

Co-authored-by: Hieu Doan <[email protected]>

* use `TypeList` schema for `gzip` nested block attributes (#114)

Co-authored-by: Shohei Maeda <[email protected]>
Co-authored-by: Hieu Doan <[email protected]>

* Consistent resource naming (#115)

Consistent resource naming:
- change `v1` to `vcl`
- remove `v1` 
- add `logging` prefix
- update docs and examples

Other changes:
- fix acl manage entries test
- fix `user` attribute in gcs

Co-authored-by: Hieu Doan <[email protected]>

Co-authored-by: Ben Gesoff <[email protected]>
Co-authored-by: Hieu Doan <[email protected]>
Co-authored-by: Shohei Maeda <[email protected]>

* make fmt

* fix broken merge

* make generate-docs

* Remove Director `capacity` field as it's unused (#535)

* remove director capacity

* Fix the example usage in docs/index.md (#533)

* Fix the example usage in docs/index.md

* Fix templates/index.md.tmpl

* run make generate-docs

* Remove extraneous line

* Remove extraneous line

Co-authored-by: Mark McDonnell <[email protected]>

* Support Terraform CLI 1.1.4 (#536)

* fix director tests

* update docs

Co-authored-by: Hiromasa Kakehashi <[email protected]>

* Add missing docs and attributes in versionless resources (#537)

* add the 'manage_snippets' attribute into 'fastly_service_dynamic_snippet_content'
update 'fastly_service_dictionary_items'

* delete a typo in manage_snippets

* domestic change: format hcl in the test

* Remove 'ignore_changes' from the docs and examples

Co-authored-by: Hieu Doan <[email protected]>

* Bump terraform-plugin-sdk (#538)

* remove terraform json from go.mod

* format example

* regenerate docs after typo

Co-authored-by: Hiieu <[email protected]>
Co-authored-by: Ben Gesoff <[email protected]>
Co-authored-by: Hieu Doan <[email protected]>
Co-authored-by: Shohei Maeda <[email protected]>
Co-authored-by: Hiromasa Kakehashi <[email protected]>
  • Loading branch information
6 people authored Feb 8, 2022
1 parent 59312a3 commit 8fe4296
Show file tree
Hide file tree
Showing 351 changed files with 12,756 additions and 7,012 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,16 @@ $ make testacc
```

In order to run an individual acceptance test, the '-run' flag can be used together with a regular expression.
The following example uses a regular expression matching single test called 'TestAccFastlyServiceV1_basic'.
The following example uses a regular expression matching single test called 'TestAccFastlyServiceVCL_basic'.

```sh
$ make testacc TESTARGS='-run=TestAccFastlyServiceV1_basic'
$ make testacc TESTARGS='-run=TestAccFastlyServiceVCL_basic'
```

The following example uses a regular expression to execute a grouping of basic acceptance tests.

```sh
$ make testacc TESTARGS='-run=TestAccFastlyServiceV1_.*_basic'
$ make testacc TESTARGS='-run=TestAccFastlyServiceVCL.*_basic'
```

In order to run the tests with extra debugging context, prefix the `make` command with `TF_LOG` (see the [terraform documentation](https://www.terraform.io/docs/internals/debugging.html) for details).
Expand Down
4 changes: 2 additions & 2 deletions docs/data-sources/waf_rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ variable "type_status" {
}
}
resource "fastly_service_v1" "demo" {
resource "fastly_service_vcl" "demo" {
name = "demofastly"
domain {
Expand Down Expand Up @@ -111,7 +111,7 @@ data "fastly_waf_rules" "owasp" {
}
resource "fastly_service_waf_configuration" "waf" {
waf_id = fastly_service_v1.demo.waf[0].waf_id
waf_id = fastly_service_vcl.demo.waf[0].waf_id
http_violation_score_threshold = 100
dynamic "rule" {
Expand Down
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ provider "fastly" {
}
# Create a Service
resource "fastly_service_v1" "myservice" {
resource "fastly_service_vcl" "myservice" {
name = "myawesometestservice"
# ...
Expand Down Expand Up @@ -65,7 +65,7 @@ provider "fastly" {
api_key = "test"
}
resource "fastly_service_v1" "myservice" {
resource "fastly_service_vcl" "myservice" {
# ...
}
```
Expand All @@ -79,7 +79,7 @@ representing your Fastly API key. When using this method, you may omit the
Fastly `provider` block entirely:

```terraform
resource "fastly_service_v1" "myservice" {
resource "fastly_service_vcl" "myservice" {
# ...
}
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
layout: "fastly"
page_title: "Fastly: service_acl_entries_v1"
sidebar_current: "docs-fastly-resource-service-acl-entries-v1"
page_title: "Fastly: service_acl_entries"
sidebar_current: "docs-fastly-resource-service-acl-entries"
description: |-
Defines a set of Fastly ACL entries that can be used to populate a service ACL.
---

# fastly_service_acl_entries_v1
# fastly_service_acl_entries

Defines a set of Fastly ACL entries that can be used to populate a service ACL. This resource will populate an ACL with the entries and will track their state.

~> **Warning:** Terraform will take precedence over any changes you make in the UI or API. Such changes are likely to be reversed if you run Terraform again.

If Terraform is being used to populate the initial content of an ACL which you intend to manage via API or UI, then the lifecycle `ignore_changes` field can be used with the resource. An example of this configuration is provided below.

~> **Note:** By default the Terraform provider allows you to externally manage the entries via API or UI.
If you wish to apply your changes in the HCL, then you should explicitly set the `manage_entries` attribute. An example of this configuration is provided below.

## Example Usage (Terraform >= 0.12.6)

Expand All @@ -25,7 +25,7 @@ variable "myacl_name" {
default = "My ACL"
}
resource "fastly_service_v1" "myservice" {
resource "fastly_service_vcl" "myservice" {
name = "demofastly"
domain {
Expand All @@ -46,11 +46,11 @@ resource "fastly_service_v1" "myservice" {
force_destroy = true
}
resource "fastly_service_acl_entries_v1" "entries" {
resource "fastly_service_acl_entries" "entries" {
for_each = {
for d in fastly_service_v1.myservice.acl : d.name => d if d.name == var.myacl_name
for d in fastly_service_vcl.myservice.acl : d.name => d if d.name == var.myacl_name
}
service_id = fastly_service_v1.myservice.id
service_id = fastly_service_vcl.myservice.id
acl_id = each.value.acl_id
entry {
ip = "127.0.0.1"
Expand Down Expand Up @@ -84,7 +84,7 @@ locals {
]
}
resource "fastly_service_v1" "myservice" {
resource "fastly_service_vcl" "myservice" {
name = "demofastly"
domain {
Expand All @@ -105,11 +105,11 @@ resource "fastly_service_v1" "myservice" {
force_destroy = true
}
resource "fastly_service_acl_entries_v1" "entries" {
resource "fastly_service_acl_entries" "entries" {
for_each = {
for d in fastly_service_v1.myservice.acl : d.name => d if d.name == local.acl_name
for d in fastly_service_vcl.myservice.acl : d.name => d if d.name == local.acl_name
}
service_id = fastly_service_v1.myservice.id
service_id = fastly_service_vcl.myservice.id
acl_id = each.value.acl_id
dynamic "entry" {
for_each = [for e in local.acl_entries : {
Expand All @@ -134,14 +134,14 @@ similar behaviour as seen in the example below.

~> **Warning:** Terraform might not properly calculate implicit dependencies on computed attributes when using `for` expressions

For scenarios such as adding an ACL to a service and at the same time, creating the ACL entries (`fastly_service_acl_entries_v1`)
For scenarios such as adding an ACL to a service and at the same time, creating the ACL entries (`fastly_service_acl_entries`)
resource, Terraform will not calculate implicit dependencies correctly on `for` expressions. This will result in index lookup
problems and the execution will fail.

For those scenarios, it's recommended to split the changes into two distinct steps:

1. Add the `acl` block to the `fastly_service_v1` and apply the changes
2. Add the `fastly_service_acl_entries_v1` resource with the `for` expressions to the HCL and apply the changes
1. Add the `acl` block to the `fastly_service_vcl` and apply the changes
2. Add the `fastly_service_acl_entries` resource with the `for` expressions to the HCL and apply the changes

Usage:

Expand All @@ -151,17 +151,17 @@ variable "myacl_name" {
default = "My ACL"
}
resource "fastly_service_v1" "myservice" {
resource "fastly_service_vcl" "myservice" {
#...
acl {
name = var.myacl_name
}
#...
}
resource "fastly_service_acl_entries_v1" "entries" {
service_id = fastly_service_v1.myservice.id
acl_id = {for d in fastly_service_v1.myservice.acl : d.name => d.acl_id}[var.myacl_name]
resource "fastly_service_acl_entries" "entries" {
service_id = fastly_service_vcl.myservice.id
acl_id = {for d in fastly_service_vcl.myservice.acl : d.name => d.acl_id}[var.myacl_name]
entry {
ip = "127.0.0.1"
subnet = "24"
Expand All @@ -171,31 +171,32 @@ resource "fastly_service_acl_entries_v1" "entries" {
}
```

### Supporting API and UI ACL updates with ignore_changes
### Reapplying original entries with `managed_entries` if the state of the entries drifts

By default the user is opted out from reapplying the original changes if the entries are managed externally.
The following example demonstrates how the `manage_entries` field can be used to reapply the changes defined in the HCL if the state of the entries drifts.
When the value is explicitly set to 'true', Terraform will keep the original changes and discard any other changes made under this resource outside of Terraform.

The following example demonstrates how the lifecycle `ignore_changes` field can be used to suppress updates against the
entries in an ACL. If, after your first deploy, the Fastly API or UI is to be used to manage entries in an ACL, then this will stop Terraform realigning the remote state with the initial set of ACL entries defined in your HCL.
~> **Warning:** You will lose externally managed entries if `manage_entries=true`.

~> **Note:** The `ignore_changes` built-in meta-argument takes precedence over `manage_entries` regardless of its value.

```terraform
#...
resource "fastly_service_acl_entries_v1" "entries" {
for_each = {
for d in fastly_service_v1.myservice.acl : d.name => d if d.name == var.myacl_name
resource "fastly_service_acl_entries" "entries" {
for_each = {
for d in fastly_service_vcl.myservice.acl : d.name => d if d.name == var.myacl_name
}
service_id = fastly_service_v1.myservice.id
acl_id = each.value.acl_id
service_id = fastly_service_vcl.myservice.id
acl_id = each.value.acl_id
manage_entries = true
entry {
ip = "127.0.0.1"
subnet = "24"
negated = false
comment = "ACL Entry 1"
}
lifecycle {
ignore_changes = [entry,]
}
}
```

Expand All @@ -206,18 +207,18 @@ resource "fastly_service_acl_entries_v1" "entries" {

## Import

This is an example of the import command being applied to the resource named `fastly_service_acl_entries_v1.entries`
This is an example of the import command being applied to the resource named `fastly_service_acl_entries.entries`
The resource ID is a combined value of the `service_id` and `acl_id` separated by a forward slash.

```sh
$ terraform import fastly_service_acl_entries_v1.entries xxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxx
$ terraform import fastly_service_acl_entries.entries xxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxx
```

If Terraform is already managing remote acl entries against a resource being imported then the user will be asked to remove it from the existing Terraform state.
The following is an example of the Terraform state command to remove the resource named `fastly_service_acl_entries_v1.entries` from the Terraform state file.
The following is an example of the Terraform state command to remove the resource named `fastly_service_acl_entries.entries` from the Terraform state file.

```sh
$ terraform state rm fastly_service_acl_entries_v1.entries
$ terraform state rm fastly_service_acl_entries.entries
```

<!-- schema generated by tfplugindocs -->
Expand All @@ -232,6 +233,7 @@ $ terraform state rm fastly_service_acl_entries_v1.entries

- **entry** (Block Set, Max: 10000) ACL Entries (see [below for nested schema](#nestedblock--entry))
- **id** (String) The ID of this resource.
- **manage_entries** (Boolean) Whether to reapply changes if the state of the entries drifts, i.e. if entries are managed externally

<a id="nestedblock--entry"></a>
### Nested Schema for `entry`
Expand Down
Loading

0 comments on commit 8fe4296

Please sign in to comment.