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

Vercel Project Secure Compute Networks resource + data source #327

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
61 changes: 54 additions & 7 deletions client/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,23 @@ func (r *ProjectResponse) Repository() *Repository {
return nil
}

type ConnectConfigurationResponse struct {
Environment string `json:"envId"`
ConnectConfigurationID string `json:"connectConfigurationId"`
Passive bool `json:"passive"`
BuildsEnabled bool `json:"buildsEnabled"`
}

// ProjectResponse defines the information Vercel returns about a project.
type ProjectResponse struct {
BuildCommand *string `json:"buildCommand"`
CommandForIgnoringBuildStep *string `json:"commandForIgnoringBuildStep"`
DevCommand *string `json:"devCommand"`
Framework *string `json:"framework"`
ID string `json:"id"`
TeamID string `json:"-"`
InstallCommand *string `json:"installCommand"`
BuildCommand *string `json:"buildCommand"`
CommandForIgnoringBuildStep *string `json:"commandForIgnoringBuildStep"`
ConnectConfigurations []ConnectConfigurationResponse `json:"connectConfigurations"`
DevCommand *string `json:"devCommand"`
Framework *string `json:"framework"`
ID string `json:"id"`
TeamID string `json:"-"`
InstallCommand *string `json:"installCommand"`
Link *struct {
Type string `json:"type"`
// github
Expand Down Expand Up @@ -346,6 +354,45 @@ func (c *Client) UpdateProject(ctx context.Context, projectID, teamID string, re
return r, err
}

// UpdateProjectSecureComputeNetworksRequest allows updating the Secure Compute Networks for a project.
type UpdateProjectSecureComputeNetworksRequest struct {
TeamID string `json:"-"`
ProjectID string `json:"-"`
SecureComputeNetworks []ConnectConfigurationRequest `json:"connectConfigurations"`
}

type ConnectConfigurationRequest struct {
Environment string `json:"envId"`
ConnectConfigurationID string `json:"connectConfigurationId"`
Passive bool `json:"passive"`
BuildsEnabled bool `json:"buildsEnabled"`
}

// UpdateProjectSecureComputeNetworks updates an existing projects connectConfigurations within Vercel.
func (c *Client) UpdateProjectSecureComputeNetworks(ctx context.Context, request UpdateProjectSecureComputeNetworksRequest) (r ProjectResponse, err error) {
url := fmt.Sprintf("%s/v9/projects/%s", c.baseURL, request.ProjectID)
if c.TeamID(request.TeamID) != "" {
url = fmt.Sprintf("%s?teamId=%s", url, c.TeamID(request.TeamID))
}
payload := string(mustMarshal(request))
tflog.Info(ctx, "updating project", map[string]any{
"url": url,
"payload": payload,
})
err = c.doRequest(clientRequest{
ctx: ctx,
method: "PATCH",
url: url,
body: payload,
}, &r)
if err != nil {
return r, err
}

r.TeamID = c.TeamID(request.TeamID)
return r, err
}

type UpdateProductionBranchRequest struct {
TeamID string `json:"-"`
ProjectID string `json:"-"`
Expand Down
62 changes: 62 additions & 0 deletions client/secure_compute_network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package client

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-log/tflog"
)

// SecureComputeNetworkAWS represents the AWS configuration part of a Secure Compute Network.
type SecureComputeNetworkAWS struct {
AccountID string `json:"AccountId"`
Region string `json:"Region"`
ElasticIpAddresses []string `json:"ElasticIpAddresses,omitempty"`
LambdaRoleArn *string `json:"LambdaRoleArn,omitempty"`
SecurityGroupId *string `json:"SecurityGroupId,omitempty"`
StackId *string `json:"StackId,omitempty"`
SubnetIds []string `json:"SubnetIds,omitempty"`
SubscriptionArn *string `json:"SubscriptionArn,omitempty"`
VpcId *string `json:"VpcId,omitempty"`
}

// SecureComputeNetwork represents a Vercel Secure Compute Network configuration.
type SecureComputeNetwork struct {
DC string `json:"dc"`
ProjectIDs []string `json:"projectIds,omitempty"`
ProjectsCount *int `json:"projectsCount,omitempty"`
PeeringConnectionsCount *int `json:"peeringConnectionsCount,omitempty"`

AWS SecureComputeNetworkAWS `json:"AWS"`
ConfigurationName string `json:"ConfigurationName"`
ID string `json:"Id"`
TeamID string `json:"TeamId"`
CIDRBlock *string `json:"CidrBlock,omitempty"`
AvailabilityZoneIDs []string `json:"AvailabilityZoneIds,omitempty"`
Version string `json:"Version"`
ConfigurationStatus string `json:"ConfigurationStatus"`
}

// ListSecureComputeNetworks fetches all Secure Compute Networks for a team.
func (c *Client) ListSecureComputeNetworks(
ctx context.Context,
teamID string,
) ([]SecureComputeNetwork, error) {
url := fmt.Sprintf("%s/v1/connect/configurations", c.baseURL)
if c.TeamID(teamID) != "" {
url = fmt.Sprintf("%s?teamId=%s", url, c.TeamID(teamID))
}
tflog.Info(ctx, "reading secure compute networks", map[string]any{
"url": url,
"team_id": c.TeamID(teamID),
})

var networks []SecureComputeNetwork
err := c.doRequest(clientRequest{
ctx: ctx,
method: "GET",
url: url,
}, &networks)

return networks, err
}
48 changes: 48 additions & 0 deletions docs/data-sources/project_secure_compute_networks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "vercel_project_secure_compute_networks Data Source - terraform-provider-vercel"
subcategory: ""
description: |-

---

# vercel_project_secure_compute_networks (Data Source)



## Example Usage

```terraform
data "vercel_project" "example" {
name = "my-existing-project"
}

data "vercel_project_secure_compute_networks" "example" {
project_id = data.vercel_project.example.id
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `project_id` (String) The ID of the Project

### Optional

- `team_id` (String) The team ID. Required when configuring a team data source if a default team has not been set in the provider.

### Read-Only

- `secure_compute_networks` (Attributes Set) A set of Secure Compute Networks that the project should be configured with. (see [below for nested schema](#nestedatt--secure_compute_networks))

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

Read-Only:

- `builds_enabled` (Boolean) Whether the projects build container should be included in the Secure Compute Network.
- `environment` (String) The environment being configured. Should be one of 'production', 'preview', or the ID of a Custom Environment
- `network_id` (String) The ID of the Secure Compute Network to configure for this environment
- `passive` (Boolean) Whether the Secure Compute Network should be configured as a passive network, meaning it is used for passive failover.
55 changes: 55 additions & 0 deletions docs/data-sources/secure_compute_network.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "vercel_secure_compute_network Data Source - terraform-provider-vercel"
subcategory: ""
description: |-
Provides information about an existing Vercel Secure Compute Network.
This data source allows you to retrieve details about a Secure Compute Network by its name and optional team ID.
---

# vercel_secure_compute_network (Data Source)

Provides information about an existing Vercel Secure Compute Network.

This data source allows you to retrieve details about a Secure Compute Network by its name and optional team ID.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) The name of the Secure Compute Network configuration.

### Optional

- `team_id` (String) The ID of the Vercel team the Secure Compute Network belongs to. If omitted, the provider will use the team configured on the provider or the user's default team.

### Read-Only

- `availability_zone_ids` (Set of String) A set of AWS Availability Zone IDs where the Secure Compute Network resources are deployed.
- `aws` (Attributes) AWS configuration for the Secure Compute Network. (see [below for nested schema](#nestedatt--aws))
- `cidr_block` (String) The CIDR block assigned to the Secure Compute Network.
- `configuration_status` (String) The operational status of the Secure Compute Network (e.g., 'ready', 'create_in_progress').
- `dc` (String) The data center (region) associated with the Secure Compute Network.
- `id` (String) The unique identifier of the Secure Compute Network.
- `peering_connections_count` (Number) The number of peering connections established for this Secure Compute Network.
- `project_ids` (Set of String) A list of Vercel Project IDs connected to this Secure Compute Network.
- `projects_count` (Number) The number of Vercel Projects connected to this Secure Compute Network.
- `version` (String) The current version identifier of the Secure Compute Network configuration.

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

Read-Only:

- `account_id` (String) The AWS account ID.
- `elastic_ip_addresses` (Set of String) A list of Elastic IP addresses.
- `lambda_role_arn` (String) The ARN of the Lambda role.
- `region` (String) The AWS region.
- `security_group_id` (String) The ID of the security group.
- `stack_id` (String) The ID of the CloudFormation stack.
- `subnet_ids` (Set of String) A list of subnet IDs.
- `subscription_arn` (String) The ARN of the subscription.
- `vpc_id` (String) The ID of the VPC.
72 changes: 72 additions & 0 deletions docs/resources/project_secure_compute_networks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "vercel_project_secure_compute_networks Resource - terraform-provider-vercel"
subcategory: ""
description: |-

---

# vercel_project_secure_compute_networks (Resource)



## Example Usage

```terraform
resource "vercel_project" "example" {
name = "example-project"
}

data "vercel_secure_compute_network" "example" {
name = "Example Network"
}

resource "vercel_project_secure_compute_networks" "example" {
project_id = vercel_project.example.id
secure_compute_networks = [
{
environment = "production"
network_id = data.vercel_secure_compute_network.example.id
passive = false
builds_enabled = true
}
]
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `project_id` (String) The ID of the Project
- `secure_compute_networks` (Attributes Set) A set of Secure Compute Networks that the project should be configured with. (see [below for nested schema](#nestedatt--secure_compute_networks))

### Optional

- `team_id` (String) The team ID. Required when configuring a team resource if a default team has not been set in the provider.

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

Required:

- `builds_enabled` (Boolean) Whether the projects build container should be included in the Secure Compute Network.
- `environment` (String) The environment being configured. Should be one of 'production', 'preview', or the ID of a Custom Environment
- `network_id` (String) The ID of the Secure Compute Network to configure for this environment
- `passive` (Boolean) Whether the Secure Compute Network should be configured as a passive network, meaning it is used for passive failover.

## Import

Import is supported using the following syntax:

```shell
# If importing with a team configured on the provider, simply use the project ID.
# - project_id can be found in the project `settings` tab in the Vercel UI.
terraform import vercel_project_secure_compute_networks.example prj_xxxxxxxxxxxxxxxxxxxxxxxxxxxx

# Alternatively, you can import via the team_id and project_id.
# - team_id can be found in the team `settings` tab in the Vercel UI.
# - project_id can be found in the project `settings` tab in the Vercel UI.
terraform import vercel_project_secure_compute_networks.example team_xxxxxxxxxxxxxxxxxxxxxxxx/prj_xxxxxxxxxxxxxxxxxxxxxxxxxxxx
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
data "vercel_project" "example" {
name = "my-existing-project"
}

data "vercel_project_secure_compute_networks" "example" {
project_id = data.vercel_project.example.id
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# If importing with a team configured on the provider, simply use the project ID.
# - project_id can be found in the project `settings` tab in the Vercel UI.
terraform import vercel_project_secure_compute_networks.example prj_xxxxxxxxxxxxxxxxxxxxxxxxxxxx

# Alternatively, you can import via the team_id and project_id.
# - team_id can be found in the team `settings` tab in the Vercel UI.
# - project_id can be found in the project `settings` tab in the Vercel UI.
terraform import vercel_project_secure_compute_networks.example team_xxxxxxxxxxxxxxxxxxxxxxxx/prj_xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
resource "vercel_project" "example" {
name = "example-project"
}

data "vercel_secure_compute_network" "example" {
name = "Example Network"
}

resource "vercel_project_secure_compute_networks" "example" {
project_id = vercel_project.example.id
secure_compute_networks = [
{
environment = "production"
network_id = data.vercel_secure_compute_network.example.id
passive = false
builds_enabled = true
}
]
}
10 changes: 0 additions & 10 deletions vercel/contains.go

This file was deleted.

29 changes: 29 additions & 0 deletions vercel/convert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package vercel

import (
"context"

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
)

func intPtrToInt64Ptr(i *int) *int64 {
if i == nil {
return nil
}
val := int64(*i)
return &val
}

func stringsToSet(ctx context.Context, strings []string) (types.Set, diag.Diagnostics) {
diags := diag.Diagnostics{}
stringSet := []attr.Value{}
for _, s := range strings {
stringSet = append(stringSet, types.StringValue(s))
}

set, d := types.SetValueFrom(ctx, types.StringType, stringSet)
diags.Append(d...)
return set, diags
}
Loading
Loading