Skip to content

Commit

Permalink
IN-6783-Provider-Onboarding-Resource (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
dolevh-d9 authored Mar 30, 2023
1 parent e50c721 commit 03d0745
Show file tree
Hide file tree
Showing 29 changed files with 1,346 additions and 81 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ jobs:
CLIENT_X509_CERT_URL: ${{ secrets.TEST_GCP_CLIENT_X509_CERT_URL }}
ALIBABA_ACCESS_KEY: ${{ secrets.TEST_ALIBABA_ACCESS_KEY }}
ALIBABA_ACCESS_SECRET: ${{ secrets.TEST_ALIBABA_ACCESS_SECRET }}
OCI_TENANCY_ID: ${{ secrets.OCI_TENANCY_ID }}
OCI_HOME_REGION: ${{ secrets.OCI_HOME_REGION }}
OCI_USER_OCID: ${{ secrets.OCI_USER_OCID }}
run: go test -v -timeout 2400s ./...
2 changes: 2 additions & 0 deletions dome9/common/resourcetype/resource_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const (
CloudAccountAWS = "dome9_cloudaccount_aws"
CloudAccountAzure = "dome9_cloudaccount_azure"
CloudAccountGCP = "dome9_cloudaccount_gcp"
CloudAccountOCI = "dome9_cloudaccount_oci"
CloudAccountOCITempData = "dome9_cloudaccount_oci_temp_data"
CloudAccountKubernetes = "dome9_cloudaccount_kubernetes"
IPList = "dome9_iplist"
ContinuousCompliancePolicy = "dome9_continuous_compliance_policy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ const (
CloudAccountAlibabaEnvVarAccessSecret = "ALIBABA_ACCESS_SECRET"
)

// Oci environment variable
const (
CloudAccountOciEnvVarTenancyId = "OCI_TENANCY_ID"
CloudAccountOciEnvVarHomeRegion = "OCI_HOME_REGION"
CloudAccountOciEnvVarUserOcid = "OCI_USER_OCID"
)

// AWS environment variable
const (
CloudAccountAWSEnvVarArn = "ARN"
Expand Down
7 changes: 6 additions & 1 deletion dome9/common/testing/variable/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ const (
CloudAccountAlibabaVendor = "alibaba"
)

// oci resource/data source
const (
CloudAccountOciCreationResourceName = "test_cloudaccount_oci"
CloudAccountOciVendor = "oci"
)

// aws resource/data source
const (
CloudAccountAWSCreationResourceName = "test_cloudaccount_aws"
Expand Down Expand Up @@ -141,7 +147,6 @@ const (
}`

DataSourceSuffix = "Data"
AwsUnifiedOnbordingTemplateUrl = `https://cloudguard-unified-onboarding-common.s3.amazonaws.com/4.5.0/templates/role_based/onboarding.yml`
AwsUnifiedOnbordingIamCapabilities0 = `CAPABILITY_IAM`
AwsUnifiedOnbordingIamCapabilities1 = `CAPABILITY_NAMED_IAM`
AwsUnifiedOnbordingIamCapabilities2 = `CAPABILITY_AUTO_EXPAND`
Expand Down
5 changes: 4 additions & 1 deletion dome9/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import (

"github.com/dome9/dome9-sdk-go/dome9"
"github.com/dome9/dome9-sdk-go/services/admissioncontrol/admission_policy"
"github.com/dome9/dome9-sdk-go/services/imageassurance/imageassurance_policy"
"github.com/dome9/dome9-sdk-go/services/cloudaccounts/alibaba"
"github.com/dome9/dome9-sdk-go/services/cloudaccounts/aws"
"github.com/dome9/dome9-sdk-go/services/cloudaccounts/azure"
"github.com/dome9/dome9-sdk-go/services/cloudaccounts/gcp"
"github.com/dome9/dome9-sdk-go/services/cloudaccounts/k8s"
"github.com/dome9/dome9-sdk-go/services/cloudaccounts/oci"
"github.com/dome9/dome9-sdk-go/services/cloudsecuritygroup/securitygroupaws"
"github.com/dome9/dome9-sdk-go/services/cloudsecuritygroup/securitygroupazure"
"github.com/dome9/dome9-sdk-go/services/compliance/continuous_compliance_notification"
"github.com/dome9/dome9-sdk-go/services/compliance/continuous_compliance_policy"
"github.com/dome9/dome9-sdk-go/services/imageassurance/imageassurance_policy"
"github.com/dome9/dome9-sdk-go/services/iplist"
"github.com/dome9/dome9-sdk-go/services/organizationalunits"
"github.com/dome9/dome9-sdk-go/services/roles"
Expand All @@ -37,6 +38,7 @@ type Client struct {
cloudaccountGCP gcp.Service
cloudaccountKubernetes k8s.Service
cloudaccountAlibaba alibaba.Service
cloudaccountOci oci.Service
continuousCompliancePolicy continuous_compliance_policy.Service
continuousComplianceNotification continuous_compliance_notification.Service
ruleSet rulebundles.Service
Expand Down Expand Up @@ -67,6 +69,7 @@ func (c *Config) Client() (*Client, error) {
client := &Client{
iplist: *iplist.New(config),
cloudaccountAlibaba: *alibaba.New(config),
cloudaccountOci: *oci.New(config),
cloudaccountAWS: *aws.New(config),
cloudaccountAzure: *azure.New(config),
cloudaccountGCP: *gcp.New(config),
Expand Down
107 changes: 107 additions & 0 deletions dome9/data_source_dome9_cloudaccount_oci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package dome9

import (
"github.com/dome9/dome9-sdk-go/services/cloudaccounts/oci"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-dome9/dome9/common/testing/variable"
"log"
)

func dataSourceCloudAccountOCI() *schema.Resource {
return &schema.Resource{
Read: dataSourceOciRead,

Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Required: true,
},
"tenancy_id": {
Type: schema.TypeString,
Computed: true,
},
"home_region": {
Type: schema.TypeString,
Computed: true,
},
"organizational_unit_id": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"credentials": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"user": {
Type: schema.TypeString,
Computed: true,
},
"fingerprint": {
Type: schema.TypeString,
Computed: true,
},
"public_key": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"creation_date": {
Type: schema.TypeString,
Computed: true,
},
"organizational_unit_path": {
Type: schema.TypeString,
Computed: true,
},
"organizational_unit_name": {
Type: schema.TypeString,
Computed: true,
},
"vendor": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceOciRead(d *schema.ResourceData, meta interface{}) error {
d9Client := meta.(*Client)

id := d.Get("id").(string)
log.Printf("Getting data for cloud account %s with id %s\n", variable.CloudAccountOciVendor, id)

ociCloudAccount, _, err := d9Client.cloudaccountOci.Get(id)
if err != nil {
return err
}

d.SetId(ociCloudAccount.ID)
_ = d.Set("name", ociCloudAccount.Name)
// Converting the timestamp to string in the format yyyy-MM-dd HH:mm:ss
_ = d.Set("creation_date", ociCloudAccount.CreationDate.Format("2006-01-02 15:04:05"))
_ = d.Set("tenancy_id", ociCloudAccount.TenancyId)
_ = d.Set("home_region", ociCloudAccount.HomeRegion)
_ = d.Set("organizational_unit_id", ociCloudAccount.OrganizationalUnitID)
_ = d.Set("credentials", setOciCredentials(ociCloudAccount.Credentials))
_ = d.Set("organizational_unit_path", ociCloudAccount.OrganizationalUnitPath)
_ = d.Set("organizational_unit_name", ociCloudAccount.OrganizationalUnitName)
_ = d.Set("vendor", ociCloudAccount.Vendor)

return nil
}

func setOciCredentials(credentials oci.CloudAccountCredentialsResponse) map[string]interface{} {
return map[string]interface{}{
"user": credentials.User,
"fingerprint": credentials.Fingerprint,
"publicKey": credentials.PublicKey,
}
}
37 changes: 37 additions & 0 deletions dome9/data_source_dome9_cloudaccount_oci_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package dome9

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/terraform-providers/terraform-provider-dome9/dome9/common/resourcetype"
"github.com/terraform-providers/terraform-provider-dome9/dome9/common/testing/method"
"testing"
)

func TestAccDataSourceCloudAccountOciBasic(t *testing.T) {
resourceTypeAndName, dataSourceTypeAndName, generatedName := method.GenerateRandomSourcesTypeAndName(resourcetype.CloudAccountOCI)

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccCloudAccountOciEnvVarsPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testAccCheckCloudAccountOciDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckCloudAccountOciConfigure(resourceTypeAndName, generatedName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "id", resourceTypeAndName, "id"),
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "name", resourceTypeAndName, "name"),
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "tenancy_id", resourceTypeAndName, "tenancy_id"),
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "home_region", resourceTypeAndName, "home_region"),
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "organizational_unit_id", resourceTypeAndName, "organizational_unit_id"),
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "credentials", resourceTypeAndName, "credentials"),
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "organizational_unit_path", resourceTypeAndName, "organizational_unit_path"),
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "organizational_unit_name", resourceTypeAndName, "organizational_unit_name"),
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "vendor", resourceTypeAndName, "vendor"),
),
},
},
})
}
3 changes: 3 additions & 0 deletions dome9/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func Provider() terraform.ResourceProvider {
resourcetype.IPList: resourceIpList(),
resourcetype.CloudAccountAlibaba: resourceCloudAccountAlibaba(),
resourcetype.CloudAccountAWS: resourceCloudAccountAWS(),
resourcetype.CloudAccountOCI: resourceCloudAccountOCI(),
resourcetype.CloudAccountOCITempData: resourceCloudAccountOciTempData(),
resourcetype.CloudAccountGCP: resourceCloudAccountGCP(),
resourcetype.CloudAccountAzure: resourceCloudAccountAzure(),
resourcetype.CloudAccountKubernetes: resourceCloudAccountKubernetes(),
Expand All @@ -64,6 +66,7 @@ func Provider() terraform.ResourceProvider {
resourcetype.IPList: dataSourceIpList(),
resourcetype.CloudAccountAlibaba: dataSourceCloudAccountAlibaba(),
resourcetype.CloudAccountAWS: dataSourceCloudAccountAWS(),
resourcetype.CloudAccountOCI: dataSourceCloudAccountOCI(),
resourcetype.AwsUnifiedOnboardingUpdateVersionStackConfig: dataSourceAwsUnifiedOnboardingUpdateVersionStackConfig(),
resourcetype.AwsUnifiedOnboarding: dataSourceAwsUnifiedOnboarding(),
resourcetype.CloudAccountGCP: dataSourceCloudAccountGCP(),
Expand Down
Loading

0 comments on commit 03d0745

Please sign in to comment.