Skip to content

Commit

Permalink
New code for project service (IBM-Cloud#4561)
Browse files Browse the repository at this point in the history
* fix: generate project code

Signed-off-by: dvesperini <dvesperini@gmail.com>

* fix: fix build

Signed-off-by: dvesperini <dvesperini@gmail.com>

* fix: add examples and markdown files

Signed-off-by: dvesperini <dvesperini@gmail.com>

* fix: mark new false positive secrets

Signed-off-by: dvesperini <dvesperini@gmail.com>

* fix: fix review

Signed-off-by: dvesperini <dvesperini@gmail.com>

* fix: fix links

Signed-off-by: dvesperini <dvesperini@gmail.com>

* fix: fix test

Signed-off-by: dvesperini <dvesperini@gmail.com>

* fix: remove regex check

Signed-off-by: dvesperini <dvesperini@gmail.com>

* fix: fix id to project_id

Signed-off-by: dvesperini <dvesperini@gmail.com>

* fix: fix integration test project

Signed-off-by: dvesperini <dvesperini@gmail.com>

* fix: fix resource_group values

Signed-off-by: dvesperini <dvesperini@gmail.com>

* fix: last changes

Signed-off-by: dvesperini <dvesperini@gmail.com>

* fix integration test

* fix integration test

* fix integration test

* fix integration test

* fix integration test

* fix integration test

* fix name

* pr comments

* pr comments

* fix doc

* fix doc

* new version

* new version

* new version

* new version

* update code to the latest SDK level

* fix integration tests

* fix integration tests

* fix integration tests

* fix integration tests

* address PR comment

---------

Signed-off-by: dvesperini <dvesperini@gmail.com>
Co-authored-by: Riccardo Angelilli <riccardo.angelilli@it.ibm.com>
  • Loading branch information
dvesperini and riccardo-angelilli authored May 11, 2023
1 parent 221ca84 commit c886711
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 161 deletions.
12 changes: 4 additions & 8 deletions examples/ibm-project/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Run `terraform destroy` when you don't need these resources.
project_instance resource:

```hcl
resource "project_instance" "project_instance_instance" {
resource "project_instance" "project_instance" {
name = var.project_instance_name
description = var.project_instance_description
configs = var.project_instance_configs
Expand All @@ -40,8 +40,6 @@ project_event_notification data source:
```hcl
data "project_event_notification" "project_event_notification_instance" {
id = var.project_event_notification_id
exclude_configs = var.project_event_notification_exclude_configs
complete = var.project_event_notification_complete
}
```

Expand Down Expand Up @@ -73,11 +71,9 @@ data "project_event_notification" "project_event_notification_instance" {
| name | The project name. | `string` | true |
| description | A project's descriptive text. | `string` | false |
| configs | The project configurations. | `list()` | false |
| resource_group | Group name of the customized collection of resources. | `string` | false |
| location | Data center locations for resource deployment. | `string` | false |
| id | The ID of the project, which uniquely identifies it. | `string` | true |
| exclude_configs | Only return with the active configuration, no drafts. | `bool` | false |
| complete | The flag to determine if full metadata should be returned. | `bool` | false |
| resource_group | The resource group where the project's data and tools are created. | `string` | true |
| location | The location where the project's data and tools are created. | `string` | true |
| project_id | The unique project ID. | `string` | true |

## Outputs

Expand Down
5 changes: 1 addition & 4 deletions examples/ibm-project/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ resource "ibm_project_instance" "project_instance" {
name = "My static website"
description = "Sample static website test using the IBM catalog deployable architecture"
configs {
id = "0013790d-6cb5-4adc-8927-a725a1261d0c"
name = "static-website-dev"
labels = [ "env:dev", "billing:internal" ]
description = "Website - development"
Expand All @@ -29,8 +28,6 @@ resource "ibm_project_instance" "project_instance" {
/*
// Create project_event_notification data source
data "ibm_project_event_notification" "project_event_notification_instance" {
id = var.project_event_notification_id
exclude_configs = var.project_event_notification_exclude_configs
complete = var.project_event_notification_complete
project_id = var.project_event_notification_id
}
*/
2 changes: 1 addition & 1 deletion examples/ibm-project/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This allows project_instance data to be referenced by other resources and the terraform CLI
// Modify this if only certain data should be exposed
output "ibm_project_instance" {
value = ibm_project_instance.project_instance_instance
value = ibm_project_instance.project_instance
description = "project_instance resource instance"
}
12 changes: 1 addition & 11 deletions examples/ibm-project/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,7 @@ variable "project_instance_location" {

// Data source arguments for project_event_notification
variable "project_event_notification_id" {
description = "The ID of the project, which uniquely identifies it."
description = "The unique project ID."
type = string
default = "id"
}
variable "project_event_notification_exclude_configs" {
description = "Only return with the active configuration, no drafts."
type = bool
default = false
}
variable "project_event_notification_complete" {
description = "The flag to determine if full metadata should be returned."
type = bool
default = false
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/IBM/continuous-delivery-go-sdk v1.1.0
github.com/IBM/event-notifications-go-admin-sdk v0.2.1
github.com/IBM/eventstreams-go-sdk v1.2.0
github.com/IBM/go-sdk-core/v5 v5.13.0
github.com/IBM/go-sdk-core/v5 v5.13.1
github.com/IBM/ibm-cos-sdk-go v1.10.0
github.com/IBM/ibm-cos-sdk-go-config v1.2.0
github.com/IBM/ibm-hpcs-tke-sdk v0.0.0-20211109141421-a4b61b05f7d1
Expand Down Expand Up @@ -58,12 +58,12 @@ require (

require (
github.com/IBM/go-sdk-core/v3 v3.2.4
github.com/IBM/project-go-sdk v0.0.10
github.com/pkg/errors v0.9.1
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/IBM/project-go-sdk v0.0.0-20230405195937-52b52b875b03 // indirect
github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56 // indirect
github.com/PromonLogicalis/asn1 v0.0.0-20190312173541-d60463189a56 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
Expand Down
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ github.com/IBM/go-sdk-core/v5 v5.7.0/go.mod h1:+YbdhrjCHC84ls4MeBp+Hj4NZCni+tDAc
github.com/IBM/go-sdk-core/v5 v5.9.2/go.mod h1:YlOwV9LeuclmT/qi/LAK2AsobbAP42veV0j68/rlZsE=
github.com/IBM/go-sdk-core/v5 v5.9.5/go.mod h1:YlOwV9LeuclmT/qi/LAK2AsobbAP42veV0j68/rlZsE=
github.com/IBM/go-sdk-core/v5 v5.10.2/go.mod h1:WZPFasUzsKab/2mzt29xPcfruSk5js2ywAPwW4VJjdI=
github.com/IBM/go-sdk-core/v5 v5.13.0 h1:foXLa2LfTSr3kgldpizaSDXH3gS/HB3YKj1BK8ywrE4=
github.com/IBM/go-sdk-core/v5 v5.13.0/go.mod h1:pVkN7IGmsSdmR1ZCU4E/cLcCclqRKMYgg7ya+O2Mk6g=
github.com/IBM/go-sdk-core/v5 v5.13.1 h1:zD6p3t1whAlRJo/VBmE69c8RcH9LCHL1n0/sO1MWlpw=
github.com/IBM/go-sdk-core/v5 v5.13.1/go.mod h1:pVkN7IGmsSdmR1ZCU4E/cLcCclqRKMYgg7ya+O2Mk6g=
github.com/IBM/ibm-cos-sdk-go v1.3.1/go.mod h1:YLBAYobEA8bD27P7xpMwSQeNQu6W3DNBtBComXrRzRY=
github.com/IBM/ibm-cos-sdk-go v1.10.0 h1:/2VIev2/jBei39OqU2+nSZQnoWJ+KtkiSAIDkqsd7uU=
github.com/IBM/ibm-cos-sdk-go v1.10.0/go.mod h1:C8KRTRaoD3CWPPBOa6FCOpdh0ZMlUjKAAA4i3F+Q/sc=
Expand All @@ -91,8 +91,8 @@ github.com/IBM/networking-go-sdk v0.40.0 h1:NdHTG0YXtN2D/B62BRgy6iJRFLdiJtSFCdTz
github.com/IBM/networking-go-sdk v0.40.0/go.mod h1:lTUZwtUkMANMnrLHFIgRhHrkBfwASY/Iho1fabaPHxo=
github.com/IBM/platform-services-go-sdk v0.34.0 h1:ozGdyWdBByNS8sw07FP4qx2r1qUc59D0BoN3rMTgtIk=
github.com/IBM/platform-services-go-sdk v0.34.0/go.mod h1:oFW/DQyAXGBcGytB+DtKjE3yNdEGM2bmw5SDOjrRwTw=
github.com/IBM/project-go-sdk v0.0.0-20230405195937-52b52b875b03 h1:mpz4CSzFeqfWSx+rP55n1afeZeACDcZGvtud2fY1KKA=
github.com/IBM/project-go-sdk v0.0.0-20230405195937-52b52b875b03/go.mod h1:yO1Pqm7Y9hWrn6eUlfPKwipqFAbvp9QeuLRb07H3/Ks=
github.com/IBM/project-go-sdk v0.0.10 h1:vHSuemwZ4S4c6BEb22tzsEcPTs/5LnZ0yKpP3GG/GL8=
github.com/IBM/project-go-sdk v0.0.10/go.mod h1:lqe0M4cKvABI1iHR1b+KfasVcxQL6nl2VJ8eOyQs8Ig=
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5 h1:NPUhkoOCRuv3OFWt19PmwjXGGTKlvmbuPg9fUrBUNe4=
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5/go.mod h1:b07XHUVh0XYnQE9s2mqgjYST1h9buaQNqN4EcKhOsX0=
github.com/IBM/scc-go-sdk/v3 v3.1.6 h1:wg7yujuJJ1O1pcGrIn8ITq6i6GeXb7GRBPNq6kLrkMU=
Expand Down Expand Up @@ -792,8 +792,6 @@ go.mongodb.org/mongo-driver v1.7.0/go.mod h1:Q4oFMbo1+MSNqICAdYMlC/zSTrwCogR4R8N
go.mongodb.org/mongo-driver v1.7.3/go.mod h1:NqaYOwnXWr5Pm7AOpO5QFxKJ503nbMse/R79oO62zWg=
go.mongodb.org/mongo-driver v1.7.5/go.mod h1:VXEWRZ6URJIkUq2SCAyapmhH0ZLRBP+FT4xhp5Zvxng=
go.mongodb.org/mongo-driver v1.10.0/go.mod h1:wsihk0Kdgv8Kqu1Anit4sfK+22vSFbUrAVEYRhCXrA8=
go.mongodb.org/mongo-driver v1.11.2 h1:+1v2rDQUWNcGW7/7E0Jvdz51V38XXxJfhzbV17aNHCw=
go.mongodb.org/mongo-driver v1.11.2/go.mod h1:s7p5vEtfbeR1gYi6pnj3c3/urpbLv2T5Sfd6Rp2HBB8=
go.mongodb.org/mongo-driver v1.11.3 h1:Ql6K6qYHEzB6xvu4+AU0BoRoqf9vFPcc4o7MUIdPW8Y=
go.mongodb.org/mongo-driver v1.11.3/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
Expand Down
51 changes: 19 additions & 32 deletions ibm/service/project/data_source_ibm_project_event_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,7 @@ func DataSourceIbmProjectEventNotification() *schema.Resource {
"project_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "The ID of the project, which uniquely identifies it.",
},
"exclude_configs": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Only return with the active configuration, no drafts.",
},
"complete": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "The flag to determine if full metadata should be returned.",
Description: "The unique project ID.",
},
"name": &schema.Schema{
Type: schema.TypeString,
Expand All @@ -62,7 +50,7 @@ func DataSourceIbmProjectEventNotification() *schema.Resource {
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The unique ID of a project.",
Description: "The ID of the configuration. If this parameter is empty, an ID is automatically created for the configuration.",
},
"name": &schema.Schema{
Type: schema.TypeString,
Expand All @@ -85,7 +73,7 @@ func DataSourceIbmProjectEventNotification() *schema.Resource {
"locator_id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The location ID of a project configuration manual property.",
Description: "A dotted value of catalogID.versionID.",
},
"type": &schema.Schema{
Type: schema.TypeString,
Expand All @@ -108,6 +96,11 @@ func DataSourceIbmProjectEventNotification() *schema.Resource {
Computed: true,
Description: "The variable type.",
},
"value": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "Can be any value - a string, number, boolean, array, or object.",
},
"required": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Expand All @@ -133,20 +126,17 @@ func DataSourceIbmProjectEventNotification() *schema.Resource {
Description: "A short explanation of the output value.",
},
"value": &schema.Schema{
Type: schema.TypeList,
Type: schema.TypeString,
Computed: true,
Description: "The output value.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "Can be any value - a string, number, boolean, array, or object.",
},
},
},
},
"setting": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "An optional setting object that's passed to the cart API.",
Description: "Schematics environment variables to use to deploy the configuration.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Expand All @@ -157,7 +147,7 @@ func DataSourceIbmProjectEventNotification() *schema.Resource {
"value": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The value of a the configuration setting.",
Description: "The value of the configuration setting.",
},
},
},
Expand All @@ -179,7 +169,7 @@ func DataSourceIbmProjectEventNotification() *schema.Resource {
"created_at": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "A date/time value in the format YYYY-MM-DDTHH:mm:ssZ or YYYY-MM-DDTHH:mm:ss.sssZ, matching the date-time format as specified by RFC 3339.",
Description: "A date and time value in the format YYYY-MM-DDTHH:mm:ssZ or YYYY-MM-DDTHH:mm:ss.sssZ, matching the date and time format as specified by RFC 3339.",
},
"cumulative_needs_attention_view": &schema.Schema{
Type: schema.TypeList,
Expand Down Expand Up @@ -218,12 +208,12 @@ func DataSourceIbmProjectEventNotification() *schema.Resource {
"location": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The location where the project was created.",
Description: "The IBM Cloud location where a resource is deployed.",
},
"resource_group": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The resource group where the project was created.",
Description: "The resource group where the project's data and tools are created.",
},
"state": &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -251,12 +241,6 @@ func dataSourceIbmProjectEventNotificationRead(context context.Context, d *schem
getProjectOptions := &projectv1.GetProjectOptions{}

getProjectOptions.SetID(d.Get("project_id").(string))
if _, ok := d.GetOk("exclude_configs"); ok {
getProjectOptions.SetExcludeConfigs(d.Get("exclude_configs").(bool))
}
if _, ok := d.GetOk("complete"); ok {
getProjectOptions.SetComplete(d.Get("complete").(bool))
}

project, response, err := projectClient.GetProjectWithContext(context, getProjectOptions)
if err != nil {
Expand Down Expand Up @@ -310,7 +294,7 @@ func dataSourceIbmProjectEventNotificationRead(context context.Context, d *schem
func dataSourceIbmProjectEventNotificationProjectConfigToMap(model *projectv1.ProjectConfig) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.ID != nil {
modelMap["id"] = model.ID
modelMap["project_id"] = model.ID
}
if model.Name != nil {
modelMap["name"] = model.Name
Expand Down Expand Up @@ -371,6 +355,9 @@ func dataSourceIbmProjectEventNotificationInputVariableToMap(model *projectv1.In
if model.Type != nil {
modelMap["type"] = model.Type
}
if model.Value != nil {
modelMap["value"] = model.Value
}
if model.Required != nil {
modelMap["required"] = model.Required
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import (

func TestAccIbmProjectEventNotificationDataSourceBasic(t *testing.T) {
projectName := fmt.Sprintf("tf_name_%d", acctest.RandIntRange(10, 100))
projectResourceGroup := fmt.Sprintf("Default")
projectLocation := fmt.Sprintf("us-south")

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckIbmProjectEventNotificationDataSourceConfigBasic(projectName),
Config: testAccCheckIbmProjectEventNotificationDataSourceConfigBasic(projectResourceGroup, projectLocation, projectName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_project_event_notification.project_event_notification", "project_id"),
resource.TestCheckResourceAttrSet("data.ibm_project_event_notification.project_event_notification", "name"),
Expand All @@ -45,8 +47,6 @@ func TestAccIbmProjectEventNotificationDataSourceAllArgs(t *testing.T) {
Config: testAccCheckIbmProjectEventNotificationDataSourceConfig(projectName, projectDescription, projectResourceGroup, projectLocation),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_project_event_notification.project_event_notification", "project_id"),
resource.TestCheckResourceAttrSet("data.ibm_project_event_notification.project_event_notification", "exclude_configs"),
resource.TestCheckResourceAttrSet("data.ibm_project_event_notification.project_event_notification", "complete"),
resource.TestCheckResourceAttrSet("data.ibm_project_event_notification.project_event_notification", "name"),
resource.TestCheckResourceAttrSet("data.ibm_project_event_notification.project_event_notification", "description"),
resource.TestCheckResourceAttrSet("data.ibm_project_event_notification.project_event_notification", "metadata.#"),
Expand All @@ -56,27 +56,26 @@ func TestAccIbmProjectEventNotificationDataSourceAllArgs(t *testing.T) {
})
}

func testAccCheckIbmProjectEventNotificationDataSourceConfigBasic(projectName string) string {
func testAccCheckIbmProjectEventNotificationDataSourceConfigBasic(projectResourceGroup string, projectLocation string, projectName string) string {
return fmt.Sprintf(`
resource "ibm_project_instance" "project_instance_instance" {
resource "ibm_project_instance" "project_instance" {
resource_group = "%s"
location = "%s"
name = "%s"
}
data "ibm_project_event_notification" "project_event_notification" {
project_id = ibm_project_instance.project_instance_instance.id
exclude_configs = false
complete = true
project_id = ibm_project_instance.project_instance.id
}
`, projectName)
`, projectResourceGroup, projectLocation, projectName)
}

func testAccCheckIbmProjectEventNotificationDataSourceConfig(projectName string, projectDescription string, projectResourceGroup string, projectLocation string) string {
return fmt.Sprintf(`
resource "ibm_project_instance" "project_instance_instance" {
resource "ibm_project_instance" "project_instance" {
name = "%s"
description = "%s"
configs {
id = "0013790d-6cb5-4adc-8927-a725a1261d0c"
name = "name"
labels = [ "labels" ]
description = "description"
Expand All @@ -94,9 +93,7 @@ func testAccCheckIbmProjectEventNotificationDataSourceConfig(projectName string,
}
data "ibm_project_event_notification" "project_event_notification" {
project_id = ibm_project_instance.project_instance_instance.id
exclude_configs = false
complete = true
project_id = ibm_project_instance.project_instance.id
}
`, projectName, projectDescription, projectResourceGroup, projectLocation)
}
Loading

0 comments on commit c886711

Please sign in to comment.