Skip to content

Commit

Permalink
Add _manifest for file entities
Browse files Browse the repository at this point in the history
  • Loading branch information
blomqma committed Sep 16, 2024
1 parent dc9dd04 commit a510cf1
Show file tree
Hide file tree
Showing 28 changed files with 1,146 additions and 275 deletions.
364 changes: 279 additions & 85 deletions .speakeasy/gen.lock

Large diffs are not rendered by default.

66 changes: 53 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ TF_REATTACH_PROVIDERS=... terraform apply

<!-- End SDK <no value> -->

<!-- Start SDK Installation [installation] -->
## SDK Installation
<!-- Start Installation [installation] -->
## Installation

To install this provider, copy and paste this code into your Terraform configuration. Then, run `terraform init`.

Expand All @@ -59,7 +59,7 @@ terraform {
required_providers {
epilot-file = {
source = "epilot-dev/epilot-file"
version = "0.4.0"
version = "0.4.1"
}
}
}
Expand All @@ -68,19 +68,17 @@ provider "epilot-file" {
# Configuration options
}
```
<!-- End SDK Installation [installation] -->
<!-- End Installation [installation] -->

<!-- Start SDK Example Usage [usage] -->
## SDK Example Usage
<!-- Start Testing the provider locally [usage] -->
## Testing the provider locally

### Testing the provider locally
#### Local Provider

Should you want to validate a change locally, the `--debug` flag allows you to execute the provider against a terraform instance locally.

This also allows for debuggers (e.g. delve) to be attached to the provider.

### Example

```sh
go run main.go --debug
# Copy the TF_REATTACH_PROVIDERS env var
Expand All @@ -89,13 +87,55 @@ cd examples/your-example
TF_REATTACH_PROVIDERS=... terraform init
TF_REATTACH_PROVIDERS=... terraform apply
```
<!-- End SDK Example Usage [usage] -->

<!-- Start Available Resources and Operations [operations] -->
## Available Resources and Operations
#### Compiled Provider

Terraform allows you to use local provider builds by setting a `dev_overrides` block in a configuration file called `.terraformrc`. This block overrides all other configured installation methods.

1. Execute `go build` to construct a binary called `terraform-provider-epilot-file`
2. Ensure that the `.terraformrc` file is configured with a `dev_overrides` section such that your local copy of terraform can see the provider binary

Terraform searches for the `.terraformrc` file in your home directory and applies any configuration settings you set.

```
provider_installation {
dev_overrides {
"registry.terraform.io/epilot-dev/epilot-file" = "<PATH>"
}
# For all other providers, install them directly from their origin provider
# registries as normal. If you omit this, Terraform will _only_ use
# the dev_overrides block, and so no other providers will be available.
direct {}
}
```
<!-- End Testing the provider locally [usage] -->

<!-- Start Available Resources and Data Sources [operations] -->
## Available Resources and Data Sources

### Resources

* [epilot-file_file](docs/resources/file.md)
### Data Sources

* [epilot-file_file](docs/data-sources/file.md)
<!-- End Available Resources and Data Sources [operations] -->

<!-- Start Summary [summary] -->
## Summary

File API: Upload and manage epilot Files
<!-- End Summary [summary] -->

<!-- Start Table of Contents [toc] -->
## Table of Contents

<!-- End Available Resources and Operations [operations] -->
* [Installation](#installation)
* [Available Resources and Data Sources](#available-resources-and-data-sources)
* [Testing the provider locally](#testing-the-provider-locally)
<!-- End Table of Contents [toc] -->

<!-- Placeholder for Future Speakeasy SDK Sections -->

Expand Down
7 changes: 4 additions & 3 deletions docs/data-sources/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,27 @@ data "epilot-file_file" "my_file" {

### Read-Only

- `access_control` (String) must be one of ["private", "public-read"]
- `access_control` (String)
- `acl` (Attributes) Access control list (ACL) for an entity. Defines sharing access to external orgs or users. (see [below for nested schema](#nestedatt--acl))
- `additional` (Map of String) Additional fields that are not part of the schema
- `created_at` (String)
- `custom_download_url` (String) Custom external download url used for the file
- `filename` (String)
- `id` (String) The ID of this resource.
- `manifest` (List of String) Manifest ID used to create/update the entity
- `mime_type` (String) MIME type of the file
- `org` (String)
- `owners` (Attributes List) (see [below for nested schema](#nestedatt--owners))
- `public_url` (String) Direct URL for file (public only if file access control is public-read)
- `purpose` (List of String)
- `readable_size` (String) Human readable file size
- `s3ref` (Attributes) (see [below for nested schema](#nestedatt--s3ref))
- `schema` (String) must be one of ["file"]
- `schema` (String)
- `size_bytes` (Number) File size in bytes
- `source_url` (String) Source URL for the file. Included if the entity was created from source_url, or when ?source_url=true
- `tags` (List of String)
- `title` (String)
- `type` (String) must be one of ["document", "document_template", "text", "image", "video", "audio", "spreadsheet", "presentation", "font", "archive", "application", "unknown"]
- `type` (String)
- `updated_at` (String)
- `versions` (Attributes List) (see [below for nested schema](#nestedatt--versions))

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ terraform {
required_providers {
epilot-file = {
source = "epilot-dev/epilot-file"
version = "0.4.0"
version = "0.4.1"
}
}
}
Expand Down
52 changes: 43 additions & 9 deletions docs/resources/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,44 @@ File Resource

```terraform
resource "epilot-file_file" "my_file" {
id = "ef7d985c-2385-44f4-9c71-ae06a52264f8"
title = "document.pdf"
access_control = "private"
access_control = "public-read"
acl = {
delete = [
"org:456"
]
edit = [
"org:456"
]
view = [
"org:456"
]
}
activity_id = "01F130Q52Q6MWSNS8N2AVXV4JN"
additional = {
"see" : jsonencode("documentation"),
}
custom_download_url = "https://some-api-url.com/download?file_id=123"
filename = "document.pdf"
mime_type = "application/pdf"
source_url = "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf"
strict = true
type = "application"
fill_activity = true
id = "ef7d985c-2385-44f4-9c71-ae06a52264f8"
manifest = [
"123e4567-e89b-12d3-a456-426614174000"
]
mime_type = "application/pdf"
purpose = [
"..."
]
s3ref = {
bucket = "epilot-prod-user-content"
key = "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"
}
source_url = "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf"
strict = true
tags = [
"..."
]
title = "document.pdf"
type = "font"
}
```

Expand All @@ -31,11 +60,16 @@ resource "epilot-file_file" "my_file" {

### Optional

- `access_control` (String) must be one of ["private", "public-read"]; Default: "private"
- `access_control` (String) Default: "private"; must be one of ["private", "public-read"]
- `acl` (Attributes) Access control list (ACL) for an entity. Defines sharing access to external orgs or users. (see [below for nested schema](#nestedatt--acl))
- `activity_id` (String) Activity to include in event feed
- `additional` (Map of String) Additional fields that are not part of the schema
- `custom_download_url` (String) Custom external download url used for the file
- `filename` (String)
- `fill_activity` (Boolean) Update the diff and entity for the custom activity included in the query.
Pending state on activity is automatically ended when activity is filled.
Default: false
- `manifest` (List of String) Manifest ID used to create/update the entity
- `mime_type` (String) MIME type of the file
- `purpose` (List of String)
- `s3ref` (Attributes) (see [below for nested schema](#nestedatt--s3ref))
Expand All @@ -53,7 +87,7 @@ resource "epilot-file_file" "my_file" {
- `owners` (Attributes List) (see [below for nested schema](#nestedatt--owners))
- `public_url` (String) Direct URL for file (public only if file access control is public-read)
- `readable_size` (String) Human readable file size
- `schema` (String) must be one of ["file"]
- `schema` (String) must be "file"
- `size_bytes` (Number) File size in bytes
- `updated_at` (String)
- `versions` (Attributes List) (see [below for nested schema](#nestedatt--versions))
Expand Down
2 changes: 1 addition & 1 deletion examples/provider/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
epilot-file = {
source = "epilot-dev/epilot-file"
version = "0.4.0"
version = "0.4.1"
}
}
}
Expand Down
43 changes: 36 additions & 7 deletions examples/resources/epilot-file_file/resource.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
resource "epilot-file_file" "my_file" {
id = "ef7d985c-2385-44f4-9c71-ae06a52264f8"
title = "document.pdf"
access_control = "private"
access_control = "public-read"
acl = {
delete = [
"org:456"
]
edit = [
"org:456"
]
view = [
"org:456"
]
}
activity_id = "01F130Q52Q6MWSNS8N2AVXV4JN"
additional = {
"see" : jsonencode("documentation"),
}
custom_download_url = "https://some-api-url.com/download?file_id=123"
filename = "document.pdf"
mime_type = "application/pdf"
source_url = "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf"
strict = true
type = "application"
fill_activity = true
id = "ef7d985c-2385-44f4-9c71-ae06a52264f8"
manifest = [
"123e4567-e89b-12d3-a456-426614174000"
]
mime_type = "application/pdf"
purpose = [
"..."
]
s3ref = {
bucket = "epilot-prod-user-content"
key = "123/4d689aeb-1497-4410-a9fe-b36ca9ac4389/document.pdf"
}
source_url = "https://productengineer-content.s3.eu-west-1.amazonaws.com/product-engineer-checklist.pdf"
strict = true
tags = [
"..."
]
title = "document.pdf"
type = "font"
}
2 changes: 1 addition & 1 deletion gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ go:
outputModelSuffix: output
packageName: openapi
terraform:
version: 0.4.0
version: 0.4.1
additionalDataSources: []
additionalDependencies: {}
additionalResources: []
Expand Down
15 changes: 9 additions & 6 deletions internal/provider/file_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type FileDataSourceModel struct {
CustomDownloadURL types.String `tfsdk:"custom_download_url"`
Filename types.String `tfsdk:"filename"`
ID types.String `tfsdk:"id"`
Manifest []types.String `tfsdk:"manifest"`
MimeType types.String `tfsdk:"mime_type"`
Org types.String `tfsdk:"org"`
Owners []tfTypes.BaseEntityOwner `tfsdk:"owners"`
Expand Down Expand Up @@ -66,8 +67,7 @@ func (r *FileDataSource) Schema(ctx context.Context, req datasource.SchemaReques

Attributes: map[string]schema.Attribute{
"access_control": schema.StringAttribute{
Computed: true,
Description: `must be one of ["private", "public-read"]`,
Computed: true,
},
"acl": schema.SingleNestedAttribute{
Computed: true,
Expand Down Expand Up @@ -105,6 +105,11 @@ func (r *FileDataSource) Schema(ctx context.Context, req datasource.SchemaReques
"id": schema.StringAttribute{
Required: true,
},
"manifest": schema.ListAttribute{
Computed: true,
ElementType: types.StringType,
Description: `Manifest ID used to create/update the entity`,
},
"mime_type": schema.StringAttribute{
Computed: true,
Description: `MIME type of the file`,
Expand Down Expand Up @@ -149,8 +154,7 @@ func (r *FileDataSource) Schema(ctx context.Context, req datasource.SchemaReques
},
},
"schema": schema.StringAttribute{
Computed: true,
Description: `must be one of ["file"]`,
Computed: true,
},
"size_bytes": schema.Int64Attribute{
Computed: true,
Expand All @@ -173,8 +177,7 @@ func (r *FileDataSource) Schema(ctx context.Context, req datasource.SchemaReques
Computed: true,
},
"type": schema.StringAttribute{
Computed: true,
Description: `must be one of ["document", "document_template", "text", "image", "video", "audio", "spreadsheet", "presentation", "font", "archive", "application", "unknown"]`,
Computed: true,
},
"updated_at": schema.StringAttribute{
Computed: true,
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/file_data_source_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func (r *FileDataSourceModel) RefreshFromSharedFileEntity(resp *shared.FileEntit
} else {
r.CreatedAt = types.StringNull()
}
r.Manifest = []types.String{}
for _, v := range resp.Manifest {
r.Manifest = append(r.Manifest, types.StringValue(v))
}
r.Org = types.StringPointerValue(resp.Org)
r.Owners = []tfTypes.BaseEntityOwner{}
if len(r.Owners) > len(resp.Owners) {
Expand Down
Loading

0 comments on commit a510cf1

Please sign in to comment.