Skip to content
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

feat: add support to attach workload protection instance #36

Merged
merged 26 commits into from
Apr 12, 2024
Merged

Conversation

jor2
Copy link
Member

@jor2 jor2 commented Feb 29, 2024

Description

attach a Workload Protection instance to an SCC instance
#29

In a draft state as we are waiting on provider type to be able to be looked up by name.

Release required?

  • No release
  • Patch release (x.x.X)
  • Minor release (x.X.x)
  • Major release (X.x.x)
Release notes content

Run the pipeline

If the CI pipeline doesn't run when you create the PR, the PR requires a user with GitHub collaborators access to run the pipeline.

Run the CI pipeline when the PR is ready for review and you expect tests to pass. Add a comment to the PR with the following text:

/run pipeline

Checklist for reviewers

  • If relevant, a test for the change is included or updated with this PR.
  • If relevant, documentation for the change is included or updated with this PR.

For mergers

  • Use a conventional commit message to set the release level. Follow the guidelines.
  • Include information that users need to know about the PR in the commit message. The commit message becomes part of the GitHub release notes.
  • Use the Squash and merge option.

@jor2 jor2 self-assigned this Feb 29, 2024
@jor2
Copy link
Member Author

jor2 commented Feb 29, 2024

/run pipeline

Copy link
Member

@ocofaigh ocofaigh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jor2 see comments

variables.tf Outdated
type = string
description = "The name for the provider_type instance"
default = null
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to expose this, lets just hard code it to "workload-protection-instance"

@jor2 jor2 marked this pull request as draft March 4, 2024 22:59
@jor2 jor2 changed the title feat: scc workload protection - scc instance [WIP] feat: scc workload protection - scc instance Mar 4, 2024
@jor2
Copy link
Member Author

jor2 commented Mar 5, 2024

@jor2 see comments

@ocofaigh Do you think I can close the scc issues I have on my board and create new ones on my prioritised backlog to pick back up once data lookup is out?

main.tf Outdated
@@ -11,6 +11,53 @@ resource "ibm_resource_instance" "scc_instance" {
tags = var.resource_tags
}

data "ibm_scc_provider_type" "scc_provider_type" {
count = var.wp_instance_crn != null ? 1 : 0
provider_type_name = var.provider_type_name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, when IBM-Cloud/terraform-provider-ibm#5208 is implemented, this module wont have a provider_type_name variable, instead you will hard code "Security and Compliance Workload Protection" here nd do data lookup by name

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we can lookup the "Security and Compliance Workload Protection" by name and get its ID, we should be good here

@ocofaigh
Copy link
Member

@jor2 Can you try with https://github.com/IBM-Cloud/terraform-provider-ibm/releases/tag/v1.64.0-beta0 since it now has data_source_ibm_scc_provider_types

@jor2
Copy link
Member Author

jor2 commented Mar 25, 2024

@jor2 Can you try with https://github.com/IBM-Cloud/terraform-provider-ibm/releases/tag/v1.64.0-beta0 since it now has data_source_ibm_scc_provider_types

this works now using beta version.

@jor2
Copy link
Member Author

jor2 commented Mar 25, 2024

These are the provider types, hardcoded to workload one, let me know if you want to change or allow to be inputted by user.

provider_types = tolist([
  {
    "attributes" = tomap({})
    "created_at" = "2023-11-08T12:30:01.312Z"
    "data_type" = "com.ibm.cloud.scc.results.0.0.1"
    "description" = "IBM Cloud® toolchain service helps users to adopt a DevOps or DevSecOps approach in application delivery and includes open toolchains that automate the building and deployment of applications."
    "id" = "1"
    "instance_limit" = 1
    "label" = tolist([
      {
        "text" = "1 per instance"
        "tip" = "Only 1 per instance"
      },
    ])
    "mode" = "PUSH"
    "name" = "Toolchain"
    "s2s_enabled" = false
    "type" = "toolchain"
    "updated_at" = "2023-11-08T12:30:01.312Z"
  },
  {
    "attributes" = tomap({})
    "created_at" = "2023-12-15T05:08:35.877Z"
    "data_type" = "com.ibm.cloud.scc.results.0.0.1"
    "description" = "Compliance and Security at the Speed of Transformation to achieve continuous compliance and security across your hybrid cloud estate to manage overall digital risk and reduce TCO. "
    "id" = "2"
    "instance_limit" = 1
    "label" = tolist([
      {
        "text" = "1 per instance"
        "tip" = "Only 1 per instance"
      },
    ])
    "mode" = "PUSH"
    "name" = "Caveonix"
    "s2s_enabled" = false
    "type" = "caveonix"
    "updated_at" = "2023-12-15T05:08:35.877Z"
  },
  {
    "attributes" = tomap({})
    "created_at" = "2023-09-22T07:02:15.802Z"
    "data_type" = "com.sysdig.secure.results"
    "description" = "Security and Compliance Center Workload Protection helps you accelerate your Kubernetes and cloud adoption by addressing security and regulatory compliance. Easily identify vulnerabilities, check compliance, block threats and respond faster at every stage of the container and Kubernetes lifecycle."
    "id" = "3"
    "instance_limit" = 1
    "label" = tolist([
      {
        "text" = "1 per instance"
        "tip" = "Only 1 per instance"
      },
    ])
    "mode" = "PULL"
    "name" = "workload-protection"
    "s2s_enabled" = true
    "type" = "workload-protection"
    "updated_at" = "2023-09-22T07:02:15.802Z"
  },
])

@jor2 jor2 changed the title [WIP] feat: scc workload protection - scc instance [WIP] feat: add support to attach workload protection instance Mar 28, 2024
@jor2 jor2 requested a review from ocofaigh March 28, 2024 15:08
@jor2 jor2 changed the title [WIP] feat: add support to attach workload protection instance feat: add support to attach workload protection instance Apr 3, 2024
@jor2 jor2 marked this pull request as ready for review April 3, 2024 10:38
@jor2
Copy link
Member Author

jor2 commented Apr 3, 2024

/run pipeline

@jor2
Copy link
Member Author

jor2 commented Apr 3, 2024

/run pipeline

@jor2
Copy link
Member Author

jor2 commented Apr 3, 2024

module.create_profile_attachment.ibm_scc_profile_attachment.scc_profile_attachment: Creating...
2024-04-03T17:44:54.793+0100 [INFO]  Starting apply for module.create_profile_attachment.ibm_scc_profile_attachment.scc_profile_attachment
2024-04-03T17:44:54.795+0100 [DEBUG] module.create_profile_attachment.ibm_scc_profile_attachment.scc_profile_attachment: applying the planned Create change
2024-04-03T17:44:54.805+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: setting computed for "last_scan" from ComputedKeys: timestamp=2024-04-03T17:44:54.805+0100
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: panic: interface conversion: interface {} is *schema.Set, not []interface {}
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: 
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: goroutine 161 [running]:
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/scc.resourceIbmSccProfileAttachmentMapToAttachmentsPrototype(0x4c9c9a0?)
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: 	github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/scc/resource_ibm_scc_profile_attachment.go:637 +0x9d4
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/scc.resourceIbmSccProfileAttachmentMapToAttachmentPrototype(0x4c9c9a0?)
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: 	github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/scc/resource_ibm_scc_profile_attachment.go:841 +0x13b
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/scc.resourceIbmSccProfileAttachmentCreate({0x5d53418, 0xc001df2ae0}, 0x0?, {0x53eaee0?, 0xc000744a80})
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: 	github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/scc/resource_ibm_scc_profile_attachment.go:310 +0x71f
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc0015eeee0, {0x5d53450, 0xc001ced7d0}, 0xd?, {0x53eaee0, 0xc000744a80})
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: 	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:778 +0x12e
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0015eeee0, {0x5d53450, 0xc001ced7d0}, 0xc001b2bc70, 0xc001a73f80, {0x53eaee0, 0xc000744a80})
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: 	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:909 +0xa85
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000beeba0, {0x5d53450?, 0xc001ced6b0?}, 0xc001b35090)
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: 	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1060 +0xe8d
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc0009f21e0, {0x5d53450?, 0xc001ceccc0?}, 0xc0004e3650)
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: 	github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:859 +0x574
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x52665e0?, 0xc0009f21e0}, {0x5d53450, 0xc001ceccc0}, 0xc0004e35e0, 0x0)
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: 	github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:467 +0x170
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: google.golang.org/grpc.(*Server).processUnaryRPC(0xc00095eb40, {0x5d5e2e0, 0xc000452000}, 0xc00061bd40, 0xc001684cc0, 0x7d83078, 0x0)
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: 	google.golang.org/[email protected]/server.go:1358 +0xe23
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: google.golang.org/grpc.(*Server).handleStream(0xc00095eb40, {0x5d5e2e0, 0xc000452000}, 0xc00061bd40, 0x0)
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: 	google.golang.org/[email protected]/server.go:1735 +0xa2f
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: google.golang.org/grpc.(*Server).serveStreams.func1.1()
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: 	google.golang.org/[email protected]/server.go:970 +0xca
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: created by google.golang.org/grpc.(*Server).serveStreams.func1
2024-04-03T17:44:54.809+0100 [DEBUG] provider.terraform-provider-ibm_v1.64.0: 	google.golang.org/[email protected]/server.go:981 +0x15c
2024-04-03T17:44:54.814+0100 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/ibm-cloud/ibm/1.64.0/darwin_amd64/terraform-provider-ibm_v1.64.0 pid=35434 error="exit status 2"
2024-04-03T17:44:54.814+0100 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2024-04-03T17:44:54.814+0100 [ERROR] plugin.(*GRPCProvider).ApplyResourceChange: error="rpc error: code = Unavailable desc = error reading from server: EOF"
2024-04-03T17:44:54.936+0100 [DEBUG] State storage *statemgr.Filesystem declined to persist a state snapshot
2024-04-03T17:44:54.936+0100 [ERROR] vertex "module.create_profile_attachment.ibm_scc_profile_attachment.scc_profile_attachment" error: Plugin did not respond
╷
│ Error: Plugin did not respond
│ 
│   with module.create_profile_attachment.ibm_scc_profile_attachment.scc_profile_attachment,
│   on ../../modules/attachment/main.tf line 40, in resource "ibm_scc_profile_attachment" "scc_profile_attachment":
│   40: resource "ibm_scc_profile_attachment" "scc_profile_attachment" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-ibm_v1.64.0 plugin:

panic: interface conversion: interface {} is *schema.Set, not []interface {}

goroutine 161 [running]:
github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/scc.resourceIbmSccProfileAttachmentMapToAttachmentsPrototype(0x4c9c9a0?)
	github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/scc/resource_ibm_scc_profile_attachment.go:637 +0x9d4
github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/scc.resourceIbmSccProfileAttachmentMapToAttachmentPrototype(0x4c9c9a0?)
	github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/scc/resource_ibm_scc_profile_attachment.go:841 +0x13b
github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/scc.resourceIbmSccProfileAttachmentCreate({0x5d53418, 0xc001df2ae0}, 0x0?, {0x53eaee0?, 0xc000744a80})
	github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/scc/resource_ibm_scc_profile_attachment.go:310 +0x71f
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc0015eeee0, {0x5d53450, 0xc001ced7d0}, 0xd?, {0x53eaee0, 0xc000744a80})
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:778 +0x12e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0015eeee0, {0x5d53450, 0xc001ced7d0}, 0xc001b2bc70, 0xc001a73f80, {0x53eaee0, 0xc000744a80})
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:909 +0xa85
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000beeba0, {0x5d53450?, 0xc001ced6b0?}, 0xc001b35090)
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1060 +0xe8d
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc0009f21e0, {0x5d53450?, 0xc001ceccc0?}, 0xc0004e3650)
	github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:859 +0x574
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x52665e0?, 0xc0009f21e0}, {0x5d53450, 0xc001ceccc0}, 0xc0004e35e0, 0x0)
	github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:467 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00095eb40, {0x5d5e2e0, 0xc000452000}, 0xc00061bd40, 0xc001684cc0, 0x7d83078, 0x0)
	google.golang.org/[email protected]/server.go:1358 +0xe23
google.golang.org/grpc.(*Server).handleStream(0xc00095eb40, {0x5d5e2e0, 0xc000452000}, 0xc00061bd40, 0x0)
	google.golang.org/[email protected]/server.go:1735 +0xa2f
google.golang.org/grpc.(*Server).serveStreams.func1.1()
	google.golang.org/[email protected]/server.go:970 +0xca
created by google.golang.org/grpc.(*Server).serveStreams.func1
	google.golang.org/[email protected]/server.go:981 +0x15c

Error: The terraform-provider-ibm_v1.64.0 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

2024-04-03T17:44:54.990+0100 [DEBUG] provider: plugin exited

@jor2
Copy link
Member Author

jor2 commented Apr 12, 2024

/run pipeline

Copy link
Member

@ocofaigh ocofaigh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

variables.tf Outdated
@@ -14,6 +14,18 @@ variable "instance_name" {
description = "Name of the security and compliance instance that will be provisioned by this module"
}

variable "attach_wp_to_scc_instance" {
type = string
description = "Set to `true` to attach an existing SCC Workload Protection instance to attach it to the SCC instance."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When set to true, a value must be passed for the wp_instance_crn inout variable

main.tf Outdated
}

resource "ibm_iam_authorization_policy" "scc_wp_s2s_access" {
count = var.attach_wp_to_scc_instance ? 1 : 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to add the ability to skip this. Suggest adding a variable called skip_scc_wp_auth_policy and update the logic here include it

@@ -6,7 +6,7 @@ terraform {
required_providers {
ibm = {
source = "IBM-Cloud/ibm"
version = "1.63.0"
version = ">= 1.64.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basic example should lock into lowest supported version, which is now 1.64.1

version.tf Outdated

time = {
source = "hashicorp/time"
version = "0.9.1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always use greater than sign in module, aka >= 0.9.1, <1.0.0

@jor2
Copy link
Member Author

jor2 commented Apr 12, 2024

/run pipeline

@jor2 jor2 requested a review from ocofaigh April 12, 2024 14:01
@@ -6,7 +6,7 @@ terraform {
required_providers {
ibm = {
source = "IBM-Cloud/ibm"
version = "1.63.0"
version = ">= 1.64.1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to lock into 1.64.1 for basic

@jor2
Copy link
Member Author

jor2 commented Apr 12, 2024

/run pipeline

@jor2 jor2 requested a review from ocofaigh April 12, 2024 14:29
@ocofaigh ocofaigh merged commit 99b9a29 into main Apr 12, 2024
2 checks passed
@ocofaigh ocofaigh deleted the workload branch April 12, 2024 14:33
@terraform-ibm-modules-ops
Copy link
Contributor

🎉 This PR is included in version 1.4.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants