Skip to content

Commit

Permalink
fix(app): service params & inconsistent error handling (#104)
Browse files Browse the repository at this point in the history
* fix: #101
* fix: #99
  • Loading branch information
Gourab1998 authored and debTheRay committed May 1, 2024
1 parent be1b663 commit 0f47abb
Show file tree
Hide file tree
Showing 20 changed files with 6,413 additions and 3,270 deletions.
18 changes: 6 additions & 12 deletions docs/data-sources/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ Gets information on a Cloud Foundry application.
## Example Usage

```terraform
terraform {
required_providers {
cloudfoundry = {
source = "sap/cloudfoundry"
}
}
}
provider "cloudfoundry" {}
data "cloudfoundry_app" "http-bin-server" {
name = "tf-test-do-not-delete-http-bin"
space = "tf-space-1"
Expand All @@ -32,7 +23,7 @@ output "id" {
}
output "space" {
value = data.cloudfoundry_app.http-bin-server.space
value = data.cloudfoundry_app.http-bin-server.space_name
}
output "name" {
Expand All @@ -56,6 +47,9 @@ output "routes" {
output "buildpacks" {
value = data.cloudfoundry_app.http-bin-server.buildpacks
}
output "service_bindings" {
value = data.cloudfoundry_app.http-bin-server.service_bindings
}
```

<!-- schema generated by tfplugindocs -->
Expand Down Expand Up @@ -134,15 +128,15 @@ Read-Only:
Read-Only:

- `protocol` (String) The protocol used for the route. Valid values are http2, http1, and tcp.
- `route` (String) The fully route qualified domain name which will be bound to app
- `route` (String) The fully qualified domain name which will be bound to app


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

Read-Only:

- `params` (Map of String) A map of arbitrary key/value pairs to send to the service broker during binding.
- `params` (String) A json object to represent the parameters for the service instance.
- `service_instance` (String) The service instance name.


Expand Down
8 changes: 8 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ provider "cloudfoundry" {}

All parameter values for the provider can be injected by setting environment variables `CF_API_URL`, `CF_USER`, `CF_PASSWORD`, `CF_ORIGIN`, `CF_CLIENT_ID`, `CF_CLIENT_SECRET`.

## Custom User-Agent Information

By default, the underlying Cloud Foundry client used by the Terraform Cloud Foundry Provider creates requests with User-Agent headers that include information about Terraform and Cloud Foundry Terraform provider versions. To add more details to the User-Agent headers, the `CF_APPEND_USER_AGENT` environment variable can be set, and its value will be directly added to HTTP requests. E.g.,

```bash
% export CF_APPEND_USER_AGENT="Optional_Extra_Information"
```

## Get Started

If you're not familiar with Terraform yet, see the [Fundamentals](https://developer.hashicorp.com/terraform/tutorials/cli) section with a lot of helpful tutorials.
Expand Down
26 changes: 22 additions & 4 deletions docs/resources/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,27 @@ resource "cloudfoundry_app" "gobis-server" {
service_bindings = [
{
service_instance : "xsuaa-tf"
params = {
role = "Viewer"
}
params = <<EOT
{
"xsappname": "tf-test-app",
"tenant-mode": "dedicated",
"description": "tf test123",
"foreign-scope-references": ["user_attributes"],
"scopes": [
{
"name": "uaa.user",
"description": "UAA"
}
],
"role-templates": [
{
"name": "Token_Exchange",
"description": "UAA",
"scope-references": ["uaa.user"]
}
]
}
EOT
}
]
routes = [
Expand Down Expand Up @@ -210,7 +228,7 @@ Required:

Optional:

- `params` (Map of String) A map of arbitrary key/value pairs to send to the service broker during binding.
- `params` (String) A json object to send to the service broker during service binding.


<a id="nestedatt--sidecars"></a>
Expand Down
14 changes: 4 additions & 10 deletions examples/data-sources/cloudfoundry_app/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
terraform {
required_providers {
cloudfoundry = {
source = "sap/cloudfoundry"
}
}
}
provider "cloudfoundry" {}

data "cloudfoundry_app" "http-bin-server" {
name = "tf-test-do-not-delete-http-bin"
space = "tf-space-1"
Expand All @@ -18,7 +9,7 @@ output "id" {
}

output "space" {
value = data.cloudfoundry_app.http-bin-server.space
value = data.cloudfoundry_app.http-bin-server.space_name
}

output "name" {
Expand All @@ -41,4 +32,7 @@ output "routes" {
}
output "buildpacks" {
value = data.cloudfoundry_app.http-bin-server.buildpacks
}
output "service_bindings" {
value = data.cloudfoundry_app.http-bin-server.service_bindings
}
24 changes: 21 additions & 3 deletions examples/resources/cloudfoundry_app/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,27 @@ resource "cloudfoundry_app" "gobis-server" {
service_bindings = [
{
service_instance : "xsuaa-tf"
params = {
role = "Viewer"
}
params = <<EOT
{
"xsappname": "tf-test-app",
"tenant-mode": "dedicated",
"description": "tf test123",
"foreign-scope-references": ["user_attributes"],
"scopes": [
{
"name": "uaa.user",
"description": "UAA"
}
],
"role-templates": [
{
"name": "Token_Exchange",
"description": "UAA",
"scope-references": ["uaa.user"]
}
]
}
EOT
}
]
routes = [
Expand Down
9 changes: 5 additions & 4 deletions internal/provider/datasource_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/SAP/terraform-provider-cloudfoundry/internal/provider/managers"
cfv3client "github.com/cloudfoundry-community/go-cfclient/v3/client"
cfv3operation "github.com/cloudfoundry-community/go-cfclient/v3/operation"
"github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
Expand Down Expand Up @@ -79,9 +80,9 @@ func (d *appDataSource) Schema(ctx context.Context, req datasource.SchemaRequest
MarkdownDescription: "The service instance name.",
Computed: true,
},
"params": schema.MapAttribute{
ElementType: types.StringType,
MarkdownDescription: "A map of arbitrary key/value pairs to send to the service broker during binding.",
"params": schema.StringAttribute{
CustomType: jsontypes.NormalizedType{},
MarkdownDescription: "A json object to represent the parameters for the service instance.",
Computed: true,
},
},
Expand All @@ -93,7 +94,7 @@ func (d *appDataSource) Schema(ctx context.Context, req datasource.SchemaRequest
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"route": schema.StringAttribute{
MarkdownDescription: "The fully route qualified domain name which will be bound to app",
MarkdownDescription: "The fully qualified domain name which will be bound to app",
Computed: true,
},
"protocol": schema.StringAttribute{
Expand Down
Loading

0 comments on commit 0f47abb

Please sign in to comment.