Examples

Basic Object Storage Bucket Examples

Info:

— The access_key and secret_key can be retrieved in the DCD, go to Menu > Storage > IONOS Object Storage > Key management.

— For the list of IONOS Object Storage Service endpoints, see Endpoints.

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.50.0"
    }
  }
}

provider "aws" {
  region                      = "de"
  access_key                  = "access_key_here"
  secret_key                  = "secret_key_here"
  # all these checks need to be skipped for an s3 external provider
  skip_credentials_validation = true
  skip_requesting_account_id  = true
  skip_region_validation      = true
  endpoints {
     s3 = "https://s3-eu-central-1.ionoscloud.com"
  }
}

resource "aws_s3_bucket" "tf_bucket_name_here" {
  bucket = "unique_name_here"
  tags = {
    Name        = "my bucket name tag"
    Environment = "dev"
  }
}

Object Storage bucket with Object Lock enabled

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.50.0"
    }
  }
}

provider "aws" {
  region                      = "de"
  access_key                  = "access_key_here"
  secret_key                  = "secret_key_here"
  # all these checks need to be skipped for an s3 external provider
  skip_credentials_validation = true
  skip_requesting_account_id  = true
  skip_region_validation      = true
  endpoints {
     s3 = "https://s3-eu-central-1.ionoscloud.com"
  }
}

resource "aws_s3_bucket" "backup_bucket" {
  bucket = "unique_name_here"
  tags = {
    Name        = "backup bucket"
    Environment = "dev"
  }
 object_lock_configuration {
    object_lock_enabled = "Enabled"
    rule {
        default_retention {
            days  = 10
            mode  = "COMPLIANCE"
          }
      }
  }
}

Object Storage bucket with Versioning enabled

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.50.0"
    }
  }
}

provider "aws" {
  region                      = "de"
  access_key                  = "access_key_here"
  secret_key                  = "secret_key_here"
  # all these checks need to be skipped for an s3 external provider
  skip_credentials_validation = true
  skip_requesting_account_id  = true
  skip_region_validation      = true
  endpoints {
     s3 = "https://s3.eu-central-1.ionoscloud.com"
  }
}
resource "aws_s3_bucket" "example" {
  bucket = "unique_name_here"
}

resource "aws_s3_bucket_versioning" "example" {
  bucket = aws_s3_bucket.example.id

  versioning_configuration {
    status = "Enabled"
  }
}

Last updated