这是indexloc提供的服务,不要输入任何密码
Skip to content

Update Deployment Protection support #145

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

Merged
merged 9 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ jobs:
run: task build
- name: Format
run: task lint

docs:
name: Docs Test
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: "1.20"
id: go
- name: Install Task
uses: arduino/setup-task@v1
with:
version: "3.x"
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Check if docs are up-to-date
run: |
task docs
Expand All @@ -48,7 +65,7 @@ jobs:

test:
name: Matrix Test
needs: [ build ]
needs: [build]
timeout-minutes: 15
strategy:
max-parallel: 1
Expand Down Expand Up @@ -80,7 +97,7 @@ jobs:
env:
TF_ACC: "true"
VERCEL_API_TOKEN: ${{ secrets.VERCEL_API_TOKEN }}
VERCEL_TERRAFORM_TESTING_TEAM: "team_Q8MH2GVRnqKLtxicP2HWPgLi"
VERCEL_TERRAFORM_TESTING_TEAM: "team_RvxIb1z0pi9RSsQ13p3ES4cK"
VERCEL_TERRAFORM_TESTING_GITHUB_REPO: "dglsparsons/test"
VERCEL_TERRAFORM_TESTING_GITLAB_REPO: "dglsparsons/test"
VERCEL_TERRAFORM_TESTING_BITBUCKET_REPO: "dglsparsons-test/test"
Expand Down
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,30 @@ If you wish to work on the provider, you'll first need [Go](http://www.golang.or

To compile the provider, run `task build`. This will build the provider and put the provider binary in the repository root.

In addition, you can run `task install` to set up a developer overrides in your ~/.terraformrc. This will then allow you
to use your locally built provider binary.
```sh
$ task build
```

In addition, you can run `task install` to set up a developer overrides in your ~/.terraformrc. This will then allow you to use your locally built provider binary.

```sh
$ task install
```

Create a `main.tf` file on your machine and use the [terraform cli](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli#install-terraform) to test

```sh
$ terraform plan
$ terraform apply
```

When you are finished using a local version of the provider, running `task uninstall` will remove _all_ developer
overrides.

```sh
$ task uninstall
```

- HashiCorp - [Development Overrides for Provider developers](https://www.terraform.io/docs/cli/config/config-file.html#development-overrides-for-provider-developers).

## Testing
Expand All @@ -42,6 +60,8 @@ The acceptance tests require a few environment variables to be set:
* `VERCEL_TERRAFORM_TESTING_TEAM` - a Vercel team_id where resources can be created and destroyed
* `VERCEL_TERRAFORM_TESTING_GITHUB_REPO` - a GitHub repository in the form 'org/repo' that can be used to trigger deployments
* `VERCEL_TERRAFORM_TESTING_BITBUCKET_REPO` - a Bitbucket repository in the form 'project/repo' that can be used to trigger deployments
* `VERCEL_TERRAFORM_TESTING_GITLAB_REPO` - a GitLab repository in the form 'project/repo' that can be used to trigger deployments
* `VERCEL_TERRAFORM_TESTING_DOMAIN` - a Vercel testing domain that can be used for testing

```sh
$ task test
Expand All @@ -59,6 +79,7 @@ To run a specific set of tests, use the `-run` flag and specify a regex pattern
$ task test -- -run 'TestAcc_Project*'
```


## Building The Documentation

The documentation is autogenerated from Description fields within the provider, and the `examples` directory.
Expand Down
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ tasks:
install-tfplugindocs:
desc: "Install the tfplugindocs tool"
cmds:
- go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@v0.7.0
- go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@v0.16.0
status:
- which tfplugindocs

Expand Down
28 changes: 28 additions & 0 deletions client/deployment_protection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package client

type VercelAuthentication struct {
DeploymentType string `json:"deploymentType"`
}

type PasswordProtection struct {
DeploymentType string `json:"deploymentType"`
}
type PasswordProtectionWithPassword struct {
DeploymentType string `json:"deploymentType"`
Password string `json:"password"`
}

type TrustedIpAddress struct {
Value string `json:"value"`
Note string `json:"note"`
}

type TrustedIps struct {
DeploymentType string `json:"deploymentType"`
Addresses []TrustedIpAddress `json:"addresses"`
ProtectionMode string `json:"protectionMode"`
}

type ProtectionBypass struct {
Scope string `json:"scope"`
}
16 changes: 15 additions & 1 deletion client/must_marshal.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
package client

import "encoding/json"
import (
"encoding/json"
)

func (v *VercelAuthentication) MarshalJSON() ([]byte, error) {
if v.DeploymentType == "none" {
return []byte(`null`), nil
}

return json.Marshal(&struct {
DeploymentType string `json:"deploymentType"`
}{
DeploymentType: v.DeploymentType,
})
}

// mustMarshal is a helper to remove unnecessary error checking when marshaling a Go
// struct to json. There are only a few instances where marshaling can fail, and they
Expand Down
13 changes: 3 additions & 10 deletions client/project_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ func (r *ProjectResponse) Repository() *Repository {
return nil
}

type Protection struct {
DeploymentType string `json:"deploymentType"`
}

type ProtectionBypass struct {
Scope string `json:"scope"`
}

// ProjectResponse defines the information Vercel returns about a project.
type ProjectResponse struct {
BuildCommand *string `json:"buildCommand"`
Expand Down Expand Up @@ -92,8 +84,9 @@ type ProjectResponse struct {
PublicSource *bool `json:"publicSource"`
RootDirectory *string `json:"rootDirectory"`
ServerlessFunctionRegion *string `json:"serverlessFunctionRegion"`
SSOProtection *Protection `json:"ssoProtection"`
PasswordProtection *Protection `json:"passwordProtection"`
VercelAuthentication *VercelAuthentication `json:"ssoProtection"`
PasswordProtection *PasswordProtection `json:"passwordProtection"`
TrustedIps *TrustedIps `json:"trustedIps"`
ProtectionBypass map[string]ProtectionBypass `json:"protectionBypass"`
}

Expand Down
30 changes: 13 additions & 17 deletions client/project_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,26 @@ import (
"github.com/hashicorp/terraform-plugin-log/tflog"
)

type PasswordProtectionRequest struct {
DeploymentType string `json:"deploymentType"`
Password string `json:"password"`
}

// UpdateProjectRequest defines the possible fields that can be updated within a vercel project.
// note that the values are all pointers, with many containing `omitempty` for serialisation.
// This is because the Vercel API behaves in the following manner:
// - a provided field will be updated
// - setting the field to an empty value (e.g. "") will remove the setting for that field.
// - omitting the value entirely from the request will _not_ update the field.
type UpdateProjectRequest struct {
BuildCommand *string `json:"buildCommand"`
CommandForIgnoringBuildStep *string `json:"commandForIgnoringBuildStep"`
DevCommand *string `json:"devCommand"`
Framework *string `json:"framework"`
InstallCommand *string `json:"installCommand"`
Name *string `json:"name,omitempty"`
OutputDirectory *string `json:"outputDirectory"`
PublicSource *bool `json:"publicSource"`
RootDirectory *string `json:"rootDirectory"`
ServerlessFunctionRegion *string `json:"serverlessFunctionRegion"`
SSOProtection *Protection `json:"ssoProtection"`
PasswordProtection *PasswordProtectionRequest `json:"passwordProtection"`
BuildCommand *string `json:"buildCommand"`
CommandForIgnoringBuildStep *string `json:"commandForIgnoringBuildStep"`
DevCommand *string `json:"devCommand"`
Framework *string `json:"framework"`
InstallCommand *string `json:"installCommand"`
Name *string `json:"name,omitempty"`
OutputDirectory *string `json:"outputDirectory"`
PublicSource *bool `json:"publicSource"`
RootDirectory *string `json:"rootDirectory"`
ServerlessFunctionRegion *string `json:"serverlessFunctionRegion"`
VercelAuthentication *VercelAuthentication `json:"ssoProtection"`
PasswordProtection *PasswordProtectionWithPassword `json:"passwordProtection"`
TrustedIps *TrustedIps `json:"trustedIps"`
}

// UpdateProject updates an existing projects configuration within Vercel.
Expand Down
2 changes: 0 additions & 2 deletions docs/data-sources/alias.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@ An Alias allows a `vercel_deployment` to be accessed through a different URL.

- `deployment_id` (String) The ID of the Deployment the Alias is associated with.
- `id` (String) The ID of this resource.


2 changes: 0 additions & 2 deletions docs/data-sources/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,3 @@ resource "vercel_deployment" "example" {

- `file` (Map of String) A map of filename to metadata about the file. The metadata contains the file size and hash, and allows a deployment to be created if the file changes.
- `id` (String) The ID of this resource.


2 changes: 0 additions & 2 deletions docs/data-sources/prebuilt_project.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,3 @@ resource "vercel_deployment" "example" {

- `id` (String) The ID of this resource.
- `output` (Map of String) A map of output file to metadata about the file. The metadata contains the file size and hash, and allows a deployment to be created if the file changes.


42 changes: 30 additions & 12 deletions docs/data-sources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ output "project_id" {

### Optional

- `password_protection` (Attributes) Ensures visitors of your Preview Deployments must enter a password in order to gain access. (see [below for nested schema](#nestedatt--password_protection))
- `team_id` (String) The team ID the project exists beneath. Required when configuring a team resource if a default team has not been set in the provider.

### Read-Only
Expand All @@ -52,19 +51,13 @@ output "project_id" {
- `ignore_command` (String) When a commit is pushed to the Git repository that is connected with your Project, its SHA will determine if a new Build has to be issued. If the SHA was deployed before, no new Build will be issued. You can customize this behavior with a command that exits with code 1 (new Build needed) or code 0.
- `install_command` (String) The install command for this project. If omitted, this value will be automatically detected.
- `output_directory` (String) The output directory of the project. When null is used this value will be automatically detected.
- `password_protection` (Attributes) Ensures visitors of your Preview Deployments must enter a password in order to gain access. (see [below for nested schema](#nestedatt--password_protection))
- `public_source` (Boolean) Specifies whether the source code and logs of the deployments for this project should be public or not.
- `root_directory` (String) The name of a directory or relative path to the source code of your project. When null is used it will default to the project root.
- `serverless_function_region` (String) The region on Vercel's network to which your Serverless Functions are deployed. It should be close to any data source your Serverless Function might depend on. A new Deployment is required for your changes to take effect. Please see [Vercel's documentation](https://vercel.com/docs/concepts/edge-network/regions) for a full list of regions.
- `trusted_ips` (Attributes) Ensures only visitors from an allowed IP address can access your deployment. (see [below for nested schema](#nestedatt--trusted_ips))
- `vercel_authentication` (Attributes) Ensures visitors to your Preview Deployments are logged into Vercel and have a minimum of Viewer access on your team. (see [below for nested schema](#nestedatt--vercel_authentication))

<a id="nestedatt--password_protection"></a>
### Nested Schema for `password_protection`

Optional:

- `protect_production` (Boolean) If true, production deployments will also be protected


<a id="nestedatt--environment"></a>
### Nested Schema for `environment`

Expand All @@ -87,11 +80,36 @@ Read-Only:
- `type` (String) The git provider of the repository. Must be either `github`, `gitlab`, or `bitbucket`.


<a id="nestedatt--vercel_authentication"></a>
### Nested Schema for `vercel_authentication`
<a id="nestedatt--password_protection"></a>
### Nested Schema for `password_protection`

Read-Only:

- `protect_production` (Boolean) If true, production deployments will also be protected
- `deployment_type` (String) The deployment environment that will be protected.


<a id="nestedatt--trusted_ips"></a>
### Nested Schema for `trusted_ips`

Read-Only:

- `addresses` (List of Object) The allowed IP addressses and CIDR ranges with optional descriptions. (see [below for nested schema](#nestedatt--trusted_ips--addresses))
- `deployment_type` (String) The deployment environment that will be protected.
- `protection_mode` (String) Whether or not Trusted IPs is required or optional to access a deployment.

<a id="nestedatt--trusted_ips--addresses"></a>
### Nested Schema for `trusted_ips.addresses`

Read-Only:

- `note` (String)
- `value` (String)



<a id="nestedatt--vercel_authentication"></a>
### Nested Schema for `vercel_authentication`

Read-Only:

- `deployment_type` (String) The deployment environment that will be protected.
2 changes: 0 additions & 2 deletions docs/data-sources/project_directory.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,3 @@ resource "vercel_deployment" "example" {

- `files` (Map of String) A map of filename to metadata about the file. The metadata contains the file size and hash, and allows a deployment to be created if the file changes.
- `id` (String) The ID of this resource.


2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ terraform {
required_providers {
vercel = {
source = "vercel/vercel"
version = "~> 0.4"
version = "~> 1.0"
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions docs/resources/alias.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@ An Alias allows a `vercel_deployment` to be accessed through a different URL.
### Read-Only

- `id` (String) The ID of this resource.


2 changes: 0 additions & 2 deletions docs/resources/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,3 @@ Optional:
- `install_command` (String) The install command for this deployment. If omitted, this value will be taken from the project or automatically detected.
- `output_directory` (String) The output directory of the deployment. If omitted, this value will be taken from the project or automatically detected.
- `root_directory` (String) The name of a directory or relative path to the source code of your project. When null is used it will default to the project root.


2 changes: 1 addition & 1 deletion docs/resources/dns_record.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ For 'TXT' records, this can contain arbitrary text.
<a id="nestedatt--srv"></a>
### Nested Schema for `srv`

Optional:
Required:

- `port` (Number) The TCP or UDP port on which the service is to be found.
- `priority` (Number) The priority of the target host, lower value means more preferred.
Expand Down
Loading