-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aws): new resource: spotinst_data_integration (#301)
- Loading branch information
1 parent
cb5e5bc
commit 8f7d4c4
Showing
12 changed files
with
731 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
## Unreleased | ||
|
||
FEATURES: | ||
**New Resource:** `spotinst_data_integration` | ||
|
||
## 1.72.0 (April 12, 2022) | ||
|
||
BUG FIXES: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
layout: "spotinst" | ||
page_title: "Spotinst: data_integration" | ||
subcategory: "Data Integration" | ||
description: |- | ||
Manages an Data Integration resource. | ||
--- | ||
|
||
# spotinst\_data\_integration | ||
|
||
Provides a Spotinst Data Integration resource. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
resource "spotinst_data_integration" "example" { | ||
name = "foo" | ||
status = "enabled" | ||
s3 { | ||
bucketName = "terraform-test-do-not-delete" | ||
subdir = "terraform-test-data-integration" | ||
} | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name`- (Required) The name of the data integration. | ||
* `status` - (Optional, only when update) Determines if this data integration is on or off. Valid values: `"enabled"`, `"disabled"` | ||
* `s3` - (Required) When vendor value is s3, the following fields are included: | ||
* `bucketName` - (Required) The name of the bucket to use. Your spot IAM Role policy needs to include s3:putObject permissions for this bucket. Can't be null. | ||
* `subdir` - (Optional) The subdirectory in which your files will be stored within the bucket. Adds the prefix subdir/ to new objects' keys. Can't be null or contain '/'. | ||
|
||
|
||
## Attributes Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
* `id` - The Spotinst Data Integration ID. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package commons | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spotinst/spotinst-sdk-go/service/dataintegration/providers/aws" | ||
"github.com/spotinst/spotinst-sdk-go/spotinst" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
var vendorTypes = []string{"s3"} | ||
|
||
const ( | ||
DataIntegrationResourceName ResourceName = "spotinst_data_integration" | ||
) | ||
|
||
var DataIntegrationResource *DataIntegrationResourceTerraformResource | ||
|
||
type DataIntegrationResourceTerraformResource struct { | ||
GenericResource | ||
} | ||
|
||
type DataIntegrationWrapper struct { | ||
DataIntegration *aws.DataIntegration | ||
} | ||
|
||
// NewDataIntegrationResource creates a new DataIntegration resource | ||
func NewDataIntegrationResource(fieldMap map[FieldName]*GenericField) *DataIntegrationResourceTerraformResource { | ||
return &DataIntegrationResourceTerraformResource{ | ||
GenericResource: GenericResource{ | ||
resourceName: DataIntegrationResourceName, | ||
fields: NewGenericFields(fieldMap), | ||
}, | ||
} | ||
} | ||
|
||
// OnCreate is called when creating a new resource block and returns a new DataIntegration resource or an error. | ||
func (res *DataIntegrationResourceTerraformResource) OnCreate( | ||
resourceData *schema.ResourceData, | ||
meta interface{}) (*aws.DataIntegration, error) { | ||
|
||
if res.fields == nil || res.fields.fieldsMap == nil || len(res.fields.fieldsMap) == 0 { | ||
return nil, fmt.Errorf("resource fields are nil or empty, cannot create") | ||
} | ||
|
||
diWrapper := NewDataIntegrationWrapper() | ||
for _, field := range res.fields.fieldsMap { | ||
if field.onCreate == nil { | ||
continue | ||
} | ||
log.Printf(string(ResourceFieldOnCreate), field.resourceAffinity, field.fieldNameStr) | ||
if err := field.onCreate(diWrapper, resourceData, meta); err != nil { | ||
return nil, err | ||
} | ||
} | ||
return diWrapper.GetDataIntegration(), nil | ||
} | ||
|
||
// OnRead is called when reading an existing resource and throws an error if it is unable to do so. | ||
func (res *DataIntegrationResourceTerraformResource) OnRead( | ||
extendedResourceDefinition *aws.DataIntegration, | ||
resourceData *schema.ResourceData, | ||
meta interface{}) error { | ||
|
||
if res.fields == nil || res.fields.fieldsMap == nil || len(res.fields.fieldsMap) == 0 { | ||
return fmt.Errorf("resource fields are nil or empty, cannot read") | ||
} | ||
|
||
diWrapper := NewDataIntegrationWrapper() | ||
diWrapper.SetDataIntegration(extendedResourceDefinition) | ||
|
||
for _, field := range res.fields.fieldsMap { | ||
if field.onRead == nil { | ||
continue | ||
} | ||
log.Printf(string(ResourceFieldOnRead), field.resourceAffinity, field.fieldNameStr) | ||
if err := field.onRead(diWrapper, resourceData, meta); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// OnUpdate is called when updating an existing resource and returns | ||
// an DataIntegration with a bool indicating if had been updated, or an error. | ||
func (res *DataIntegrationResourceTerraformResource) OnUpdate( | ||
resourceData *schema.ResourceData, | ||
meta interface{}) (bool, *aws.DataIntegration, error) { | ||
if res.fields == nil || res.fields.fieldsMap == nil || len(res.fields.fieldsMap) == 0 { | ||
return false, nil, fmt.Errorf("resource fields are nil or empty, cannot update") | ||
} | ||
|
||
diWrapper := NewDataIntegrationWrapper() | ||
hasChanged := false | ||
var vendor = "" | ||
for _, field := range res.fields.fieldsMap { | ||
if contains(vendorTypes, field.fieldNameStr) { | ||
vendor = field.fieldNameStr | ||
} | ||
if field.onUpdate == nil { | ||
continue | ||
} | ||
if field.hasFieldChange(resourceData, meta) { | ||
log.Printf(string(ResourceFieldOnUpdate), field.resourceAffinity, field.fieldNameStr) | ||
if err := field.onUpdate(diWrapper, resourceData, meta); err != nil { | ||
return false, nil, err | ||
} | ||
hasChanged = true | ||
} | ||
} | ||
diWrapper.DataIntegration.SetVendor(spotinst.String(vendor)) | ||
return hasChanged, diWrapper.GetDataIntegration(), nil | ||
} | ||
|
||
// Spotinst DataIntegration must have a wrapper struct. | ||
// the wrapper struct is intended to help reflect the field states into the DataIntegration object properly. | ||
func NewDataIntegrationWrapper() *DataIntegrationWrapper { | ||
return &DataIntegrationWrapper{ | ||
DataIntegration: &aws.DataIntegration{}, | ||
} | ||
} | ||
|
||
// GetDataIntegration returns a wrapped DataIntegration | ||
func (diWrapper *DataIntegrationWrapper) GetDataIntegration() *aws.DataIntegration { | ||
return diWrapper.DataIntegration | ||
} | ||
|
||
// SetDataIntegration applies DataIntegration fields to the DataIntegration wrapper. | ||
func (diWrapper *DataIntegrationWrapper) SetDataIntegration(di *aws.DataIntegration) { | ||
diWrapper.DataIntegration = di | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package dataintegration | ||
|
||
import "github.com/spotinst/terraform-provider-spotinst/spotinst/commons" | ||
|
||
const ( | ||
DataIntegrationName commons.FieldName = "name" | ||
S3 commons.FieldName = "s3" | ||
Status commons.FieldName = "status" | ||
|
||
BucketName commons.FieldName = "bucket_name" | ||
SubDir commons.FieldName = "subdir" | ||
) |
Oops, something went wrong.