Giter Club home page Giter Club logo

terraform-provider-awscc's Introduction

Terraform logo

Terraform AWS Cloud Control Provider

This provider is currently in technical preview. This means some aspects of its design and implementation are not yet considered stable. We are actively looking for community feedback in order to solidify its form.

The Terraform AWS Cloud Control Provider is a plugin for Terraform that allows for the full lifecycle management of AWS resources using the AWS CloudFormation Cloud Control API. This provider is maintained internally by the HashiCorp AWS Provider team.

AWS Cloud Control API

The AWS Cloud Control API is a lightweight proxy API to discover, provision and manage cloud resources through a simple, uniform and predictable control plane. The AWS Cloud Control API supports Create, Read, Update, Delete and List (CRUDL) operations on any AWS resource that is registered in the AWS CloudFormation registry.

Coverage

At launch a subset of AWS resources which can be managed by CloudFormation are supported, some services use an older CloudFormation schema and cannot be used with Cloud Control. AWS are updating all of the older CloudFormation schemas to conform to the new standard, and are actively pursuing full coverage for CloudFormation. For the latest coverage information please refer to the AWS CloudFormation public roadmap.

To see the list of supported resources within this provider please refer to the registry.

Release Schedule

This provider is generated from the latest CloudFormation schemas, and will release weekly containing all new services and enhancements added to Cloud Control.

Credentials

When performing CRUDL operations the Cloud Control API make calls to downstream AWS services on your behalf. By default, the Cloud Control API will create a temporary session using the AWS credentials of the user making the Cloud Control API call. This session lasts up to a maximum of 24 hours.

All CRUDL operations also accept a RoleArn parameter which represents the AWS CloudFormation service role. In addition to federating access, using a role allows you to extend the allowed time of an operation to 36 hours, as the Cloud Control API can refresh the role credentials by re-assuming the role. The Terraform AWS Cloud Control API Provider has a role_arn argument which enables support for this functionality.

Please note: We take Terraform's security and our users' trust very seriously. If you believe you have found a security issue in the Terraform AWS Cloud Control Provider, please responsibly disclose by contacting us at [email protected].

Quick Starts

Documentation

Full, comprehensive documentation is available on the Terraform Registry

Frequently Asked Questions

Responses to our most frequently asked questions can be found in our FAQ

Contributing

The Terraform Provider for AWS CloudFormation Cloud Control API is the work of a handful of contributors. We appreciate your help!

To contribute, please read the contribution guidelines: Contributing to Terraform - AWS Cloud Control Provider

terraform-provider-awscc's People

Contributors

angie44 avatar bettjoby avatar bflad avatar bondanthony avatar breathingdust avatar catlike avatar dansantf avatar dependabot[bot] avatar emnedre avatar ewbankkit avatar gankidis avatar gdavison avatar glennchia avatar gokendra avatar ishwar-amzn avatar johnsonaj avatar justinretzolk avatar kadrach avatar ksatirli avatar marcosentino avatar naveen-amzn avatar novekm avatar onceupon avatar quixoticmonk avatar rahul-amzn avatar rhhanda avatar tamilver-amzn avatar troyparrett avatar wellsiau-aws avatar zhelding avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-provider-awscc's Issues

Initial Resource Code Generation

Description

Given a source directory of CloudFormation Resource Schema files from #15, an initial code generator should be written that creates corresponding Terraform Resource files. These files can use the output of #7 (or an empty/placeholder map) for schema and write empty/placeholder CRUD handler definitions (which will be more filled in via #8).

Dependent on: #17

Definition of Done

  • Running a generation command (e.g. make gen and/or go generate ./...) (re)creates all Terraform Resource files based on available CloudFormation Resource Schema files.
  • Ensure CI verifies that the code generation is synchronized on pull requests and the main branch

Support Singular Data Sources

Description

Currently we have no support for generating data source schemas.
Eventually we will want to add both singular and plural data sources (as Cloud API supports List operations).

Definition of Done

  • Resources with get by id functionality are supported with a singular datasource

Provider-Level CloudAPI Region Configuration

Description

Practitioners using the CloudAPI-based provider should be able to declare the AWS Region for all resources/operations at the provider level. Currently the AWS Region is hardcoded to us-west-2 for the beta period. This configuration should be required as there will be no default after beta.

Proposed Configuration

provider "awscloudapi" {
  region = "us-west-2"
}

Otherwise if not provided, reads AWS_DEFAULT_REGION environment variable.

Definition of Done

  • Provider schema includes region attribute. If configured, CloudAPI operations are called against that region's endpoint.
  • Supports AWS_DEFAULT_REGION environment variable. If configured, CloudAPI operations are called against that region's endpoint.
  • If both region provider configuration and AWS_DEFAULT_REGION environment variable are provided, configuration takes precedence.

Provider-Level CloudAPI RoleArn Configuration

Description

CloudAPI operations support an optional RoleArn parameter, which is an IAM Role that is used to do the actual provisioning (otherwise it defaults to the principal calling the operation). We should implement support for an optional string argument at the provider level, which can be passed through to all resource-level CloudAPI operations.

Proposed Configuration

provider "awscloudapi" {
  role_arn = "arn:aws:iam::123456789012:role/CloudAPIExecutionRole"
}

Definition of Done

  • Provider schema includes role_arn attribute. If configured, all CloudAPI operations are called with the RoleArn parameter and this configuration value. Should provide IAM Role ARN format validation (e.g. arn.Parse(), service equals iam, etc).

Support Sets

Description

Relates hashicorp/terraform-plugin-framework#53.
As of v0.1.0 terraform-plugin-framework does not support Terraform Sets.
This limits the resource schemas that can be generated.
Once upstream support is added, enhance this provider.

Definition of Done

GitHub repository configuration

Description

Ensure that from day one of alpha the GitHub repository configuration matches HashiCorp standards and as much as possible is entirely managed by Terraform. Where possible these should be consistent with the existing provider assuming that standard makes sense.

Definition of Done

  • labels
  • issue templates

Write-only properties

Description

The CloudFormation resource type schemas write-only. These are properties, such as passwords, that can be specified on resource creation but aren't returned when reading the current state of the resource.

In this provider's generic Read handler, the new Terraform state value is constructed from the returned CloudFormation ResourceModel without regard for any write-only properties.
Write-only properties should be copied from the prior Terraform state value into the new state value.

This will involved capturing the paths to all write-only properties during schema code generation and retaining this information in the generic resource type structure.

Definition of Done

Implement AWS Go v2 SDK-native waiter for polling the `GetResourceRequestStatus` API

Description

We currently use the terraform-plugin-sdk's resource.StateChangeConf structure and associated WaitForState method to poll the CloudAPI GetResourceRequestStatus method waiting for a resource operation to complete.
The AWS Go v2 SDK has a powerful waiter mechanism but as of today the CloudAPI preview SDKs we have received have not had waiters implemented for GetResourceRequestStatus.
It looks like we should be able to implement our own waiter for this operation.
Use for example NewTypeRegistrationCompleteWaiter as a guide.

Definition of Done

  • Implement AWS Go v2 SDK-native waiter

Relates #34.

Use of `terraform-plugin-sdk` acceptance test framework requires top-level `id` attribute

To use the current terraform-plugin-sdk acceptance test framework a top-level attribute named id must be declared in the resource schema. This is required for the state shim, otherwise errors are reported:

TF_ACC=1 go test ./internal/aws/logs -v -count 1 -parallel 20 -run=TestAccLogGroup_ -timeout 180m
=== RUN   TestAccLogGroup_basic
=== PAUSE TestAccLogGroup_basic
=== CONT  TestAccLogGroup_basic
    testing_new_config.go:111: no "id" found in attributes
    testing_new.go:53: no "id" found in attributes
--- FAIL: TestAccLogGroup_basic (3.70s)

The resource code generation should produce an attribute

		"id": {
			Description: `The unique resource ID.`,
			Type:        types.StringType,
			Computed:    true,
		},

and the generic resource handlers should populate this field in state.

Relates: #38.
Relates: hashicorp/terraform-plugin-framework#80.

Enable metrics

Description

This provider implements generic CRUD handlers for all supported resource types.
The single code paths for each operation give us the opportunity to enable metrics consistently.
Consider using https://github.com/armon/go-metrics.

Definition of Done

Internal RFC: Acceptance test generation

Description

In theory we can generate acceptance tests based on the CloudAPI schema definition in order to fully validate the behavior of the generated provider and protect against both local and upstream regression.

The terraform-plugin-framework does not currently provide testing support, however as the existing SDK relies on binary testing it should be possible to use the terraform-plugin-sdk to enable these tests to be run.

However, given the generated nature of the provider, and that the generation code is really the subject under test we may choose to rely mainly on unit tests. The detailed per-attribute, full lifecycle tests that we do for the existing provider, may not be appropriate given the vast range of services on offer from AWS and that the provider code is meant to be generic across services.

Definition of Done

  • We understand whether the terraform-plugin-sdk will allow us to test this provider.
    That we have in Internal RFC (with team alignment) which specifies:
  • Our testing strategy for the generated provider
  • If we choose to pursue generated acceptance tests, an agreed scope for 0.1, 0.2 and 1.0 release.

Release tooling

Description

Validate that we can test the existing release process and that it works for this new provider.

Check with Registry Team and Release team what needs to be done to ensure that the first release works, and how it can be testing without making an artifact public.

Decide what the process is for pre-GA builds vs post.

Some notes from Megan:

Builds should be repeatable, and be one click.

Relates #35

Definition of Done for Testing Release Tooling:

  • Create Release GithubAction
  • Create Post-Release GithubAction (generates new changelog etc.)
  • Ensure repo has access to necessary environment vars per TF-279
  • configure HC-releases with a private (or public) bucket/env for verifying released assets

Additional Tasks before day of release:

  • Raise PR against registry for logo/display-name

Implement Placeholder Create, Read, and Delete Functions in Code Generation

Description

Augment the code generation to include placeholder Create, Read, and Delete functions for all resources. In particular, the Create function should call CreateResource operation with a progress waiter and d.SetId() with the resource type and identifier. The Read function should perform GetResource operation with error checking and trigger resource recreation when receiving the appropriate resource not found error. The Delete function can perform a DeleteResource operation with a progress waiter.

Support operation cancellation

Description

The CloudAPI supports operation cancellation:

You can use the CancelResourceRequest API to request the cancellation of an IN_PROGRESS request, passing the RequestToken from the CreateResource, UpdateResource, or DeleteResource APIs.

Consider supporting this functionality when context.Context signals a user cancellation (^C).

Rework resource schema code generation

The resource schema code generation in internal/provider/generators/resource/main.go need to be reworked to capture attribute paths for write-only properties (#42) and to correctly determine computed and force-new attributes.
Go back to a version of the code sketched out in #7 (comment) to generate the Schema as a single structure.

Standardized Terraform resource diagnostics

Description

To ensure consistency and improve error messaging, standardized warning and error diagnostics can be created.

Proposed Implementation

func ResourceNotFoundAfterCreationDiag(err error) diag.Diagnostic {
	return diag.Diagnostic{
		Severity: diag.Error,
		Summary:  "AWS Resource Not Found After Creation",
		Detail:   fmt.Sprintf("After creating the AWS resource and attempting to read the resource, the API returned a resource not found error. This is typically an error with the Terraform resource implementation. Original Error: %s", err.Error()),
	}
}

func ResourceNotFoundWarningDiag(err error) diag.Diagnostic {
	return diag.Diagnostic{
		Severity: diag.Warning,
		Summary:  "AWS Resource Not Found During Refresh",
		Detail:   fmt.Sprintf("Automatically removing from Terraform State instead of returning the error, which may trigger resource recreation. Original Error: %s", err.Error()),
	}
}

func ServiceOperationEmptyResultDiag(service string, operation string) diag.Diagnostic {
	return diag.Diagnostic{
		Severity: diag.Error,
		Summary:  "AWS SDK Go Service Operation Empty Response",
		Detail:   fmt.Sprintf("Calling %s service %s operation returned missing contents in the response. This is typically an error with the API implementation.", service, operation),
	}
}

func ServiceOperationErrorDiag(service string, operation string, err error) diag.Diagnostic {
	return diag.Diagnostic{
		Severity: diag.Error,
		Summary:  "AWS SDK Go Service Operation Unsuccessful",
		Detail:   fmt.Sprintf("Calling %s service %s operation returned: %s", service, operation, err.Error()),
	}
}

func ServiceOperationWaiterErrorDiag(service string, operation string, err error) diag.Diagnostic {
	return diag.Diagnostic{
		Severity: diag.Error,
		Summary:  "AWS SDK Go Service Operation Incomplete",
		Detail:   fmt.Sprintf("Waiting for %s service %s operation completion returned: %s", service, operation, err.Error()),
	}
}

Can drop Diag in function naming if moved into its own package.

Definition of Done

  • The following known error situations have diagnostic wrappers created:
    • AWS Resource Not Found After Creation (error)
    • AWS Resource Not Found During Refresh (warning)
    • AWS SDK Go Service Operation Empty Response (error)
    • AWS SDK Go Service Operation Incomplete (error)
    • AWS SDK Go Service Operation Unsuccessful (error)
  • Any CRUD handlers are converted

Explicit `identifier` attribute

The Terraform HCL v2 SDK no longer implements (or enforces) an implicit id attribute for every resource.
As the Cloud API has the idea of a unique resource instance identifier, generate an id attribute for every resource type and map it to the Cloud API unique ID.

Related: #28.

The Cloud API (currently) names this as Identifier. For consistency, generated resources will name this attribute identifier.

Decide on resource prefix

Description

To avoid practitioner confusion we don't want the default provider configuration to conflict with the current AWS Provider (aws_ prefix).

Definition of Done

  • Specify a new prefix for this provider.

Obvious suggestions:

  • cloudapi_
  • awscloudapi_

CloudFormation Resource Schema downloads and updates

Description

To generate a provider with all CloudAPI-compatible CloudFormation Resource Types, the schemas of each resource will need to be consistently readable from remote source(s) (e.g. CloudFormation API and/or GitHub repositories) and likely saved within the codebase. Once those schemas are available locally, then the generator can do its part.

There are currently a few unknowns with this setup as:

  • Public CloudFormation Resource Types are not versioned
  • It is unclear how the CloudFormation API itself is updated
  • CloudFormation API does provide source GitHub repository for each CloudFormation Resource Type, which could be used to potentially simplify configuration
  • Source filenames within each of those repositories seems to follow a convention, e.g. “aws-service-thing/aws-service-thing.json”, further investigation would be good

Dependent on: #17

Proposed Functional Requirements

Proposed Configuration

sources = [
  {
    resource_type = "aws_logs_log_group"
    git_source    = "github.com/aws-cloudformation/aws-cloudformation-resource-providers-logs//aws-logs-loggroup/aws-logs-loggroup.json"
    version       = "a0363cb2ff6fd29e2e2312a116470baf4774e219"
  },
]

Definition of Done

  • Given a configuration file, loop through all sources to download all CloudFormation Resource Schemas consistently into a local directory in the repository matching the provided resource_type.
  • CI should be setup to verify out of sync configuration and codebase cache on pull requests and main branch.

AWS Go v2 SDK

Currently this provider is using a custom version of the AWS Go v1 SDK.
This major version of the SDK is on a path towards EOL.
AWS will soon provide us with a custom version of the AWS Go v2 SDK.
Once available, migrate the Cloud API calls.
CloudFormation API client bootstrap and provider configuration will also need to be migrated.
Where possible, share implementation patterns with the similar proposed work in the AWS Provider.
If feasible, use an AWS Go v2 SDK-enabled version of the aws-sdk-go-base package.

Definition Of Done

  • All dependencies on the AWS Go v1 SDK removed
  • No test regressions
  • Provider Configuration and Documentation

Initial Codebase Directory Structure

Definition

This codebase is based off terraform-provider-scaffolding which gets us started, but we will need to determine where provider-specific files such as CloudFormation Resource Schemas, generated Terraform Resource files, and various internal packages/tooling should reside.

Proposed Layout

internal/provider/
|- provider(_test).go
 - resource_{RESOURCE_TYPE}_gen.go # Generated Terraform Resource files
internal/service/cloudformation/
|- cfjsonpatch/  # TEMPORARY: RFC 6902 customizations for CloudFormation
|- cfschema/     # CloudFormation Resource Schema Go SDK
|- schemas/      # CloudFormation Resource Schemas cached from update tooling
|- schemas-sync/ # CloudFormation Resource Schema updater
 - waiter/       # GetRequestStatus polling

Definition of Done

  • README.md or CONTRIBUTING.md updated with details
  • The following issues should have explicit details added:

Package to Convert CloudFormation Resource Schemas into Go Types

All future tasks are dependent on being able to ingest the JSON CloudFormation Resource Provider Schema files. This includes but is not limited to validating the JSON schema against the CloudFormation Resource Provider meta schema, unmarshalling the JSON into Go.

Correctly snake-case attribute names

We are currently using the strcase Go package to convert CloudFormation property names (e.g. Arn or GlobalReplicationGroupDescription) to their Terraform attribute name equivalents (arn and global_replication_group_description) and vice-versa.
However I have noticed that S3Bucket is converted to s_3_bucket, which is not what we want.

Provider configuration options

Currently this provider exposes just the role_arn and region configuration options (and doesn't use role_arn), relying on environment variables to specify authentication arguments via the aws-sdk-go-base package.
Determine and implement the minimal usable set of configuration options, a subset of the AWS Provider's configuration options.
Wherever possible use the same argument names as for the AWS Provider.

Depends on #34.

Definition Of Done

Minimal usable set of provider configuration options

  • Documented
  • Implemented
  • Tested

Temporary local Set implementation

Relates #39.
Until the Plugin Framework has a Set implementation, implement a local, temporary Set type.
This should unblock code generation for all AWS supported resources.

Required attributes not marked as such

I just noticed that properties listed as required in the CloudFormation schema aren't being marked as such in the generated Terraform schema code.
Fix that.

Service package structure

Generate the resource schemas into per-service packages instead of into a single large package.
Try and follow work in the "main" provider on how resource registration and bootstrapping would work.

Related: #17

Terraform Plugin Go to CloudAPI JSON Patch Conversion on Update

CloudAPI requires a customized RFC 6902 JSON Patch input for updates. Terraform Plugin Go implements state updates in the TBD type which can be queried via TBD. This information must be converted to a JSON prior state, converted into a JSON desired state, and those two JSON documents compared into JSON Patch format.

Build tooling

Description

Add a minimal set of build tooling to allow contributors to build, test, lint and format code.
Where possible share workflows with the AWS Provider.

Definition of Done

  • Go Version - M
  • Linting
    • Golangcilint
    • Semgrep
    • impilint
    • Markdownlint
    • link-checker
    • misspell
  • CI (TeamCity Setup) - Requires new testing account for CloudAPI (Make request via Doormat)

CloudFormation Resource Property Behavior Lookup

CloudFormation Resource Provider Schemas encode all information about creation-only (ForceNew), write-only (ForceNew), read-only (wholly Computed), and deprecated properties at the root level using a /path/to/property syntax. The conversion package needs to implement lookup functionality to support those resource behaviors.

Terraform Plugin Go Conversion to CloudAPI JSON on Creation

CloudAPI requires a stringified JSON desired state as input during creation. Terraform Plugin Go represents prior state (configuration) data in a TBD type which is fetched via TBD calls. Implement this conversion (including snake_case to PascalCase) and generate for all resources, which effectively enables very basic resource support.

Versioning Strategy

A CloudFormation resource schema may (in the future) have a version attribute. The CloudAPI may support this field to lock a resource definition to a major version of a resource schema.

Relates: #15.

Spike: Validate current terraform-plugin-docs functionality is compatible with generated schema

Description

Given that the current version of terraform-plugin-docs relies on Terraform CLI output (terraform providers schema -json), the tools should work out of the box with the generated provider. This task captures validating that this process will work, and whether are not there are any shortcoming or modifications required to the tool or to the generated provider.

The scope that the tool needs to satisfy in this case is minimal:

  • Support resource level documentation
  • Support attribute level documentation

Definition of Done

  • Validate that the tool works to satisfy the above scope, and if not, document what needs to be done to satisfy it.
  • This item does not cover any remediation work.

Relates: #9.

Enable Terraform documentation generation

Description

Documentation generation via terraform-plugin-docs can begin when Terraform Resources (and at least their schema) are being created via the code generation. This will allow stakeholders to investigate the current coverage and verbiage for appropriateness in Terraform. The CloudFormation schema providers resource level and property level documentation, but does not provide detailed service level documentation. There is also clear inconsistencies between the level of documentation in each service.

It is expected that the generated documentation will be much more minimal than practitioners are used to seeing in the existing provider.

Definition of Done

  • Setup terraform-plugin-docs to run with other generation command(s).
  • Ensure CI verifies terraform-plugin-docs has been synchronized on pull requests and the main branch.
  • Ensure that the generation steps allow for non-generated documentation files to exist alongside.
  • Import documentation

Kubernetes Alpha Provider - Research

Meet with the Kubernetes Alpha provider team, since that provider must deal with dynamic schemas and validation. They likely have valuable input on design considerations and possible functionality that will influence other tasks.

CloudAPI JSON to Terraform Plugin Go Conversion on Read

CloudAPI returns resource information in a stringified JSON. Terraform Plugin Go represents state data in a TBD type which is updated via TBD calls currently. Implement this conversion (including PascalCase to snake_case) and generate for all resources, which effectively enables drift detection for configured attributes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.